All language subtitles for 040 Hot Reload and Hot Restart - Flutter Power Tools.en_US

af Afrikaans
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bn Bengali
bs Bosnian
bg Bulgarian
ca Catalan
ceb Cebuano
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
tl Filipino
fi Finnish
fr French Download
fy Frisian
gl Galician
ka Georgian
de German
el Greek
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
km Khmer
ko Korean
ku Kurdish (Kurmanji)
ky Kyrgyz
lo Lao
la Latin
lv Latvian
lt Lithuanian
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mn Mongolian
my Myanmar (Burmese)
ne Nepali
no Norwegian
ps Pashto
fa Persian
pl Polish
pt Portuguese
pa Punjabi
ro Romanian
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
st Sesotho
sn Shona
sd Sindhi
si Sinhala
sk Slovak
sl Slovenian
so Somali
es Spanish
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
te Telugu
th Thai
tr Turkish
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu
or Odia (Oriya)
rw Kinyarwanda
tk Turkmen
tt Tatar
ug Uyghur
Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated: 1 00:00:00,690 --> 00:00:05,580 Now in the last module, we built our 'I Am Rich' and 'I Am Poor' project. 2 00:00:05,880 --> 00:00:12,660 If you remember, we created our app inside our main function, which we know gets triggered, when our code 3 00:00:12,720 --> 00:00:16,450 is run. Inside these curly braces, is the starting point. 4 00:00:17,100 --> 00:00:24,090 And inside here, we've told the phone to run an app which is a Material app. And then we gave it various 5 00:00:24,090 --> 00:00:26,040 widgets to be displayed. 6 00:00:26,070 --> 00:00:32,550 So in this case, we've got a scaffold, that has a background color and simply just an empty container, 7 00:00:32,880 --> 00:00:34,230 as the body. 8 00:00:34,230 --> 00:00:39,740 Now if you remember, at the beginning when I told you about why Flutter is awesome, 9 00:00:39,810 --> 00:00:46,620 one of the things I talked about, was this thing called hot reload, which allows you to almost instantaneously 10 00:00:46,650 --> 00:00:51,660 see your changes in the simulator or on your device that you're testing it on. 11 00:00:51,660 --> 00:00:57,810 That means, if I was to go and change our color, instead of having a background of teal, and I wanted to 12 00:00:57,810 --> 00:01:04,500 have a background of a red color. Then I should be able to go and click on this button which is hot reload, 13 00:01:05,010 --> 00:01:07,470 and it should change instantly, right? 14 00:01:07,950 --> 00:01:13,170 And you can see down here that it's initializing hot reload, and it seems to have successfully reloaded 15 00:01:13,170 --> 00:01:13,980 everything. 16 00:01:14,070 --> 00:01:16,800 But, why is our background not red? 17 00:01:16,800 --> 00:01:18,830 Why hasn't it changed? 18 00:01:18,840 --> 00:01:26,130 Well, the reason is because for hot reload to work, we have to have the things that we've changed inside 19 00:01:26,400 --> 00:01:27,120 a Flutter 20 00:01:27,120 --> 00:01:30,270 stateless, or stateful widget. 21 00:01:30,270 --> 00:01:34,800 So let me show you what that looks like. In order to create a stateless widget, 22 00:01:34,830 --> 00:01:42,210 there's a really quick shortcut that Flutter gives us, which is if you type S-T-L-E-S-S, so state 23 00:01:42,300 --> 00:01:48,780 less, I guess for short. It will automatically create you a new Stateless widget. 24 00:01:48,810 --> 00:01:53,910 So if we go ahead and hit ENTER, you can see, it writes a whole bunch of code for us. 25 00:01:53,910 --> 00:01:57,590 And this is the boilerplate code for building a stateless widget. 26 00:01:57,870 --> 00:02:01,440 And then we get to give it a name, so let's call this stateless widget, 27 00:02:01,440 --> 00:02:09,270 I don't know, 'MyApp' and instead of building our Material app inside our runApp project in the main function, 28 00:02:09,630 --> 00:02:11,520 we're gonna go ahead and take it out. 29 00:02:11,520 --> 00:02:14,920 So we're gonna go highlight it up until we've got the comment 30 00:02:14,930 --> 00:02:22,080 where it says 'MaterialApp', and I'm gonna hit COMMAND + X to cut, and then I'm going to paste it here where 31 00:02:22,080 --> 00:02:23,230 it says return. 32 00:02:23,250 --> 00:02:28,710 So instead of returning a simple container, I'm gonna return an entire Material app. 33 00:02:28,710 --> 00:02:31,300 And of course, we can't have a comma and a semicolon, 34 00:02:31,320 --> 00:02:37,080 I'm going to delete the comma. And instead of running that Material app including all of those things 35 00:02:37,080 --> 00:02:44,040 there, I'm simply going to say, runApp, and the app that we're going to run, is MyApp. So you can see that 36 00:02:44,040 --> 00:02:46,830 this hasn't really changed our app, at all. 37 00:02:46,830 --> 00:02:54,300 All it's done, is we've separated out the part where we build our Material app, into a separate widget. 38 00:02:54,750 --> 00:02:57,240 And this is a stateless widget. 39 00:02:57,240 --> 00:03:05,280 Now what a stateless widget comes with, is this method called build. And this method gets called whenever 40 00:03:05,370 --> 00:03:08,700 we create a new version of this widget. 41 00:03:08,880 --> 00:03:16,860 That means that, if I go ahead and change this color from, what was it teal to red, and I click on the 42 00:03:16,860 --> 00:03:24,420 hot reload button, then it will go and check to see what was the code that was changed most recently, 43 00:03:24,870 --> 00:03:27,160 namely teal became red. 44 00:03:27,260 --> 00:03:36,040 It will look to see where the closest build function is, and it will re-run it. Now that we've done this, 45 00:03:36,060 --> 00:03:40,770 let's go ahead and stop our app, and run it again. 46 00:03:40,770 --> 00:03:43,130 So we're restarting it from fresh. 47 00:03:43,350 --> 00:03:51,360 And this means that our app is going to be created again using this stateless widget instead of simply 48 00:03:51,390 --> 00:03:57,190 just returning a MaterialApp. You can see right now, our background has been changed to red, 49 00:03:57,220 --> 00:03:58,660 but this is not very interesting. 50 00:03:58,660 --> 00:04:04,640 We always knew that we could stop our app and run our app, and wait a million seconds for that to happen. 51 00:04:04,690 --> 00:04:11,530 But here's the cool thing. Now that we've got our MaterialApp inside a Stateless widget, which has a 52 00:04:11,530 --> 00:04:17,920 build method, which can be called every time we make a change to one of the widgets inside this build 53 00:04:17,920 --> 00:04:18,800 method. 54 00:04:18,850 --> 00:04:22,340 So let's change that color from red to blue. 55 00:04:22,360 --> 00:04:28,440 This is the part of the code that will get marked as changed, and as soon as I click on this button for 56 00:04:28,450 --> 00:04:36,040 Flutter hot reload, you'll see that the changes move over almost instantaneously. And it's because that 57 00:04:36,220 --> 00:04:43,000 all the app is doing, is instead of compiling all of the code, linking everything together, figuring out 58 00:04:43,000 --> 00:04:50,980 where the app icons are, which platform it's being run on. Instead of all of that, it just calls this method 59 00:04:50,980 --> 00:04:58,570 again. And it rebuilds our MaterialApp with the scaffold with the changes. 60 00:04:58,570 --> 00:05:06,840 This is why it can be so fast. And remember that you don't actually have to click on this button. By default, 61 00:05:06,930 --> 00:05:12,240 Flutter's hot reload is hardwired to happen when you save your project. 62 00:05:12,270 --> 00:05:13,890 So let's change the color again. 63 00:05:13,890 --> 00:05:21,060 Let's change it to white, and as soon as I hit COMMAND + S on Mac, or CONTROLS + S on Windows, and I save my 64 00:05:21,060 --> 00:05:29,100 project, it automatically runs hot reload, and we get all the content refreshed almost immediately. Which, 65 00:05:29,370 --> 00:05:36,060 for anybody who's done any sort of mobile development with iOS, Android, Xamarin, whatever it may be, this 66 00:05:36,060 --> 00:05:38,250 is almost magical. 67 00:05:38,520 --> 00:05:45,230 And the idea really, is that hot reload is meant to happen so fast and it really is like a reload. 68 00:05:45,330 --> 00:05:48,150 Like when you refresh your website as you're creating it. 69 00:05:48,900 --> 00:05:55,620 And what this will allow developers to do is to almost paint their user interface into life. 70 00:05:55,620 --> 00:05:55,900 Right? 71 00:05:55,900 --> 00:06:02,370 Say if you were creating a drawing or creating a painting, you see the changes immediately as soon as 72 00:06:02,370 --> 00:06:03,520 your pen hits paper. 73 00:06:03,930 --> 00:06:10,560 And even though hot reload is not instantaneous, like when you put a brush on paper, but it reduces that 74 00:06:10,560 --> 00:06:17,520 lag to fractions of a second, which means that developers are more inclined to use hot reload to see 75 00:06:17,520 --> 00:06:21,300 the changes that happen after every change they make. 76 00:06:21,300 --> 00:06:26,430 And this means that you get less errors, because you haven't waited for a whole day before you rerun 77 00:06:26,430 --> 00:06:29,790 your app. And you realize that there's 10 things that have broken. 78 00:06:29,880 --> 00:06:35,670 So we're going to be using the power of hot reload to massively reduce the amount of time for each development 79 00:06:35,670 --> 00:06:36,350 cycle. 80 00:06:36,360 --> 00:06:43,770 So let's imagine a development cycle being, we write code, and then we test code, we run it, we see what 81 00:06:43,770 --> 00:06:49,680 happens. And then we look at the difference between what we expected to happen, and what actually happens 82 00:06:49,830 --> 00:06:54,170 on screen. And then we go back, and we change our code, we write more code. 83 00:06:54,420 --> 00:07:02,220 And this goes on until infinity, or until your app is done. And what Flutter allows us to do, is to massively 84 00:07:02,220 --> 00:07:08,310 shorten the time that's taken to create that cycle, for each of those cycles. 85 00:07:09,000 --> 00:07:14,670 And previously when you saw me creating this FloatingActionButton, I created the button, I hit save, 86 00:07:14,730 --> 00:07:21,750 it updates. I changed the background color, I hit save, it updates. I add an icon to the button, and I hit 87 00:07:21,750 --> 00:07:23,750 save, and it updates as well. 88 00:07:23,760 --> 00:07:30,510 So for every single line of code, when I'm creating the user interface, I'm just painting it on to my 89 00:07:30,510 --> 00:07:35,180 app and seeing the result, in fractions of seconds. So almost live. 90 00:07:35,190 --> 00:07:39,690 This means that you can really experiment with how you want the screen to look. 91 00:07:39,780 --> 00:07:46,680 Let's see, if you know for example, let's move this thing to the left a bit. See how that looks or change 92 00:07:46,710 --> 00:07:53,010 the color of that thing, through you know, all the rainbows of colors and see how that looks and see whether 93 00:07:53,010 --> 00:07:59,430 if you like it. If not, change it and then it updates in a fraction of second. When we're developing apps 94 00:07:59,520 --> 00:08:01,980 natively for iOS or Android, 95 00:08:01,980 --> 00:08:07,500 the only real option that we have is running the app from cold. 96 00:08:07,500 --> 00:08:15,270 Now I want to show you, even on a fast iOS simulator, running on one of the latest MacBook Pros. 97 00:08:15,270 --> 00:08:17,350 So it has a lot of processing power. 98 00:08:17,360 --> 00:08:19,180 I want to show you just how long this takes, right. 99 00:08:19,350 --> 00:08:26,190 So I'm stopping. I'm starting. And we're just watching that timer go. And you can see in the console, that 100 00:08:26,190 --> 00:08:27,740 things are happening. 101 00:08:27,750 --> 00:08:29,740 It's launching the code. 102 00:08:29,850 --> 00:08:31,620 It's starting the build. 103 00:08:31,620 --> 00:08:38,220 It's compiling our code turning the human readable code that we've written, into ones and zeros that 104 00:08:38,310 --> 00:08:44,230 the machine can actually understand. And then launching our app onto the simulator. 105 00:08:44,220 --> 00:08:52,070 And in total I counted that that took about 30 seconds to actually show up on the screen. 106 00:08:52,110 --> 00:08:54,400 It really took a long time. 107 00:08:54,630 --> 00:09:01,290 And imagine that if you had changed just the color of the FloatingActionButton on the bottom right, 108 00:09:01,710 --> 00:09:06,730 you probably are not inclined to spend 30 seconds waiting to see how it's changed. 109 00:09:06,780 --> 00:09:14,730 Right? Now let's consider, if instead we were creating a Flutter app, and we now have access to our hot 110 00:09:14,730 --> 00:09:15,870 reload. 111 00:09:15,870 --> 00:09:17,070 Now the same thing, 112 00:09:17,070 --> 00:09:20,590 changing a color. Instead of hitting run, 113 00:09:20,610 --> 00:09:25,990 I'm going to hit hot reload, and it's a matter of seconds. 114 00:09:26,010 --> 00:09:32,830 It took five seconds for that app bar background to change. And the beauty of this is that it doesn't 115 00:09:32,920 --> 00:09:34,740 even lose the state of the app. 116 00:09:34,750 --> 00:09:40,840 So all of the things that you've done for testing, say if I've changed the number of donuts eaten in 117 00:09:40,840 --> 00:09:47,140 the app, it's reading as ten. But I decide to change the background color of the app bar to red, and I 118 00:09:47,140 --> 00:09:50,170 hit hot reload, almost instantaneously, 119 00:09:50,230 --> 00:09:57,250 my background color changes, but the rest of the data that I inputed hasn't reset itself. Which means 120 00:09:57,250 --> 00:10:02,200 that if you're testing something like a form, or you're testing something where you don't want to lose 121 00:10:02,200 --> 00:10:08,380 the data that you've used to test the app, but you wanted to make some sort of UI change, then hot reload 122 00:10:08,710 --> 00:10:10,950 won't lose that data for you. 123 00:10:11,380 --> 00:10:17,020 And we're gonna see this come into action, a little bit later on, as we get to develop more and more complex 124 00:10:17,080 --> 00:10:19,000 apps. 125 00:10:19,000 --> 00:10:23,460 Now what is this button that's next to the hot reload button? 126 00:10:23,500 --> 00:10:25,030 This little green one. 127 00:10:25,070 --> 00:10:27,540 Well this is something that comes with Flutter as well, 128 00:10:27,610 --> 00:10:30,700 and it's called a hot restart. 129 00:10:30,700 --> 00:10:37,120 What this does, is that it does in fact, reset the state of your app. 130 00:10:37,120 --> 00:10:40,630 So if you needed to test your app from the start, 131 00:10:40,630 --> 00:10:47,490 So when number of donuts gets reset back down to zero, then this is the button that you would use instead. 132 00:10:47,500 --> 00:10:53,020 So I'm changing the background color, and then I'm pressing hot restart, instead a hot reload. 133 00:10:53,020 --> 00:10:56,590 And you can see that in the console, it's doing exactly that. 134 00:10:56,590 --> 00:11:02,920 Now it still doesn't take as long as actually starting the app from cold, when you stop it and run it 135 00:11:02,920 --> 00:11:03,650 again. 136 00:11:03,820 --> 00:11:09,340 But it does in fact, reset the state of our app and you can see that not only is this background gets 137 00:11:09,340 --> 00:11:15,100 changed to blue, but also the number of doughnuts eaten get reset back down to zero. 138 00:11:15,100 --> 00:11:18,500 And it only took eight seconds for this to happen. 139 00:11:18,760 --> 00:11:24,430 So you might be wondering. Well, OK, that's fair enough on a very simple app right. 140 00:11:24,430 --> 00:11:27,550 Like you know something that just counts the number of doughnuts that you've eaten. 141 00:11:27,760 --> 00:11:33,340 But what if I had a big app with thousands of lines of code, then surely you know hot reload and hot 142 00:11:33,340 --> 00:11:35,590 restart won't really be very useful for me. 143 00:11:36,250 --> 00:11:43,510 Well actually, it still is. Because of the way that hot reload and hot restart work, what they do is they 144 00:11:43,510 --> 00:11:51,550 will only look at the changes that were made, and they will push those changes onto your testing device, 145 00:11:51,580 --> 00:11:53,710 your simulator or your iPhone. 146 00:11:53,710 --> 00:11:58,550 It's almost kind of like, if you're somebody like me who travels a lot, 147 00:11:58,630 --> 00:12:03,850 I actually have a suitcase that's pre-packed with pretty much all the things I always need when I go 148 00:12:03,850 --> 00:12:09,940 travelling, like toothbrush, toothpaste, my you know, a couple of pair of socks and those kind of things. 149 00:12:10,480 --> 00:12:16,150 And depending on where I go, I might add a few things or move a few things. Say if I'm going somewhere 150 00:12:16,150 --> 00:12:19,420 that's quite warm, I might add a pair of sunglasses. 151 00:12:19,510 --> 00:12:26,650 So it's only the changes that I'm making to my suitcase that gets put into the suitcase. And this means 152 00:12:26,680 --> 00:12:31,490 I save myself a lot of time. Instead of packing my suitcase from scratch, 153 00:12:31,630 --> 00:12:36,970 I'm only adding the changes that I need for a particular destination. 154 00:12:37,150 --> 00:12:39,610 And this is how hot reload and hot restart works. 155 00:12:40,600 --> 00:12:49,420 So in this case, size doesn't actually matter. It doesn't matter if you are packing for a small suitcase 156 00:12:49,510 --> 00:12:56,470 or a giant suitcase. As long as you already have the suitcase packed, and you're only adding to it one 157 00:12:56,470 --> 00:13:02,980 thing or two things, depending on which destination you're going to, then it doesn't actually take any 158 00:13:02,980 --> 00:13:07,270 longer to pack a larger suitcase or a smaller suitcase. 159 00:13:07,270 --> 00:13:14,440 And this is the same for our Flutter code, even if we're hot reloading for changes that we've made to 160 00:13:14,470 --> 00:13:18,430 a really complex large project. 161 00:13:18,430 --> 00:13:26,590 It will still be just as fast as doing it for a tiny project like this one here. And in the coming lessons, 162 00:13:26,710 --> 00:13:33,520 we're gonna be using hot reload and hot restart to almost instantly, see the changes that we're making 163 00:13:33,640 --> 00:13:37,720 with our code in our simulator. In the next lesson, 164 00:13:37,720 --> 00:13:42,760 that's exactly what we're going to be building. We're gonna be building out our container, and seeing 165 00:13:42,970 --> 00:13:48,460 all of the cool things that you can use it to do. So for all of that and more, I'll see you in the next 166 00:13:48,460 --> 00:13:48,820 lesson. 17985

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.