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

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bem Bemba
bn Bengali
bh Bihari
bs Bosnian
br Breton
bg Bulgarian
km Cambodian
ca Catalan
ceb Cebuano
chr Cherokee
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
eo Esperanto
et Estonian
ee Ewe
fo Faroese
tl Filipino
fi Finnish
fy Frisian
gaa Ga
gl Galician
ka Georgian
de German
el Greek
gn Guarani
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ia Interlingua
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
rw Kinyarwanda
rn Kirundi
kg Kongo
ko Korean
kri Krio (Sierra Leone)
ku Kurdish
ckb Kurdish (Soranรฎ)
ky Kyrgyz
lo Laothian
la Latin
lv Latvian
ln Lingala
lt Lithuanian
loz Lozi
lg Luganda
ach Luo
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mfe Mauritian Creole
mo Moldavian
mn Mongolian
my Myanmar (Burmese)
sr-ME Montenegrin
ne Nepali
pcm Nigerian Pidgin
nso Northern Sotho
no Norwegian
nn Norwegian (Nynorsk)
oc Occitan
or Oriya
om Oromo
ps Pashto
fa Persian
pl Polish
pt-BR Portuguese (Brazil)
pt Portuguese (Portugal)
pa Punjabi
qu Quechua
ro Romanian
rm Romansh
nyn Runyakitara
sm Samoan
gd Scots Gaelic
sr Serbian
sh Serbo-Croatian
st Sesotho
tn Setswana
crs Seychellois Creole
sn Shona
sd Sindhi
si Sinhalese
sk Slovak
sl Slovenian
so Somali
es Spanish
es-419 Spanish (Latin American)
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
tt Tatar
te Telugu
th Thai
ti Tigrinya
to Tonga
lua Tshiluba
tum Tumbuka
tr Turkish
tk Turkmen
tw Twi
ug Uighur
uk Ukrainian
uz Uzbek
vi Vietnamese
cy Welsh
wo Wolof
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu

Original subtitles

0 Now in the last module, we built our 'I Am Rich' and 'I Am Poor' project. 1

If you remember, we created our app inside our main function, which we know gets triggered, when our code 2

is run. Inside these curly braces, is the starting point. 3

And inside here, we've told the phone to run an app which is a Material app. And then we gave it various 4

widgets to be displayed. 5

So in this case, we've got a scaffold, that has a background color and simply just an empty container, 6

as the body. 7

Now if you remember, at the beginning when I told you about why Flutter is awesome, 8

one of the things I talked about, was this thing called hot reload, which allows you to almost instantaneously 9

see your changes in the simulator or on your device that you're testing it on. 10

That means, if I was to go and change our color, instead of having a background of teal, and I wanted to 11

have a background of a red color. Then I should be able to go and click on this button which is hot reload, 12

and it should change instantly, right? 13

And you can see down here that it's initializing hot reload, and it seems to have successfully reloaded 14

everything. 15

But, why is our background not red? 16

Why hasn't it changed? 17

Well, the reason is because for hot reload to work, we have to have the things that we've changed inside 18

a Flutter 19

stateless, or stateful widget. 20

So let me show you what that looks like. In order to create a stateless widget, 21

there's a really quick shortcut that Flutter gives us, which is if you type S-T-L-E-S-S, so state 22

less, I guess for short. It will automatically create you a new Stateless widget. 23

So if we go ahead and hit ENTER, you can see, it writes a whole bunch of code for us. 24

And this is the boilerplate code for building a stateless widget. 25

And then we get to give it a name, so let's call this stateless widget, 26

I don't know, 'MyApp' and instead of building our Material app inside our runApp project in the main function, 27

we're gonna go ahead and take it out. 28

So we're gonna go highlight it up until we've got the comment 29

where it says 'MaterialApp', and I'm gonna hit COMMAND + X to cut, and then I'm going to paste it here where 30

it says return. 31

So instead of returning a simple container, I'm gonna return an entire Material app. 32

And of course, we can't have a comma and a semicolon, 33

I'm going to delete the comma. And instead of running that Material app including all of those things 34

there, I'm simply going to say, runApp, and the app that we're going to run, is MyApp. So you can see that 35

this hasn't really changed our app, at all. 36

All it's done, is we've separated out the part where we build our Material app, into a separate widget. 37

And this is a stateless widget. 38

Now what a stateless widget comes with, is this method called build. And this method gets called whenever 39

we create a new version of this widget. 40

That means that, if I go ahead and change this color from, what was it teal to red, and I click on the 41

hot reload button, then it will go and check to see what was the code that was changed most recently, 42

namely teal became red. 43

It will look to see where the closest build function is, and it will re-run it. Now that we've done this, 44

let's go ahead and stop our app, and run it again. 45

So we're restarting it from fresh. 46

And this means that our app is going to be created again using this stateless widget instead of simply 47

just returning a MaterialApp. You can see right now, our background has been changed to red, 48

but this is not very interesting. 49

We always knew that we could stop our app and run our app, and wait a million seconds for that to happen. 50

But here's the cool thing. Now that we've got our MaterialApp inside a Stateless widget, which has a 51

build method, which can be called every time we make a change to one of the widgets inside this build 52

method. 53

So let's change that color from red to blue. 54

This is the part of the code that will get marked as changed, and as soon as I click on this button for 55

Flutter hot reload, you'll see that the changes move over almost instantaneously. And it's because that 56

all the app is doing, is instead of compiling all of the code, linking everything together, figuring out 57

where the app icons are, which platform it's being run on. Instead of all of that, it just calls this method 58

again. And it rebuilds our MaterialApp with the scaffold with the changes. 59

This is why it can be so fast. And remember that you don't actually have to click on this button. By default, 60

Flutter's hot reload is hardwired to happen when you save your project. 61

So let's change the color again. 62

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 63

project, it automatically runs hot reload, and we get all the content refreshed almost immediately. Which, 64

for anybody who's done any sort of mobile development with iOS, Android, Xamarin, whatever it may be, this 65

is almost magical. 66

And the idea really, is that hot reload is meant to happen so fast and it really is like a reload. 67

Like when you refresh your website as you're creating it. 68

And what this will allow developers to do is to almost paint their user interface into life. 69

Right? 70

Say if you were creating a drawing or creating a painting, you see the changes immediately as soon as 71

your pen hits paper. 72

And even though hot reload is not instantaneous, like when you put a brush on paper, but it reduces that 73

lag to fractions of a second, which means that developers are more inclined to use hot reload to see 74

the changes that happen after every change they make. 75

And this means that you get less errors, because you haven't waited for a whole day before you rerun 76

your app. And you realize that there's 10 things that have broken. 77

So we're going to be using the power of hot reload to massively reduce the amount of time for each development 78

cycle. 79

So let's imagine a development cycle being, we write code, and then we test code, we run it, we see what 80

happens. And then we look at the difference between what we expected to happen, and what actually happens 81

on screen. And then we go back, and we change our code, we write more code. 82

And this goes on until infinity, or until your app is done. And what Flutter allows us to do, is to massively 83

shorten the time that's taken to create that cycle, for each of those cycles. 84

And previously when you saw me creating this FloatingActionButton, I created the button, I hit save, 85

it updates. I changed the background color, I hit save, it updates. I add an icon to the button, and I hit 86

save, and it updates as well. 87

So for every single line of code, when I'm creating the user interface, I'm just painting it on to my 88

app and seeing the result, in fractions of seconds. So almost live. 89

This means that you can really experiment with how you want the screen to look. 90

Let's see, if you know for example, let's move this thing to the left a bit. See how that looks or change 91

the color of that thing, through you know, all the rainbows of colors and see how that looks and see whether 92

if you like it. If not, change it and then it updates in a fraction of second. When we're developing apps 93

natively for iOS or Android, 94

the only real option that we have is running the app from cold. 95

Now I want to show you, even on a fast iOS simulator, running on one of the latest MacBook Pros. 96

So it has a lot of processing power. 97

I want to show you just how long this takes, right. 98

So I'm stopping. I'm starting. And we're just watching that timer go. And you can see in the console, that 99

things are happening. 100

It's launching the code. 101

It's starting the build. 102

It's compiling our code turning the human readable code that we've written, into ones and zeros that 103

the machine can actually understand. And then launching our app onto the simulator. 104

And in total I counted that that took about 30 seconds to actually show up on the screen. 105

It really took a long time. 106

And imagine that if you had changed just the color of the FloatingActionButton on the bottom right, 107

you probably are not inclined to spend 30 seconds waiting to see how it's changed. 108

Right? Now let's consider, if instead we were creating a Flutter app, and we now have access to our hot 109

reload. 110

Now the same thing, 111

changing a color. Instead of hitting run, 112

I'm going to hit hot reload, and it's a matter of seconds. 113

It took five seconds for that app bar background to change. And the beauty of this is that it doesn't 114

even lose the state of the app. 115

So all of the things that you've done for testing, say if I've changed the number of donuts eaten in 116

the app, it's reading as ten. But I decide to change the background color of the app bar to red, and I 117

hit hot reload, almost instantaneously, 118

my background color changes, but the rest of the data that I inputed hasn't reset itself. Which means 119

that if you're testing something like a form, or you're testing something where you don't want to lose 120

the data that you've used to test the app, but you wanted to make some sort of UI change, then hot reload 121

won't lose that data for you. 122

And we're gonna see this come into action, a little bit later on, as we get to develop more and more complex 123

apps. 124

Now what is this button that's next to the hot reload button? 125

This little green one. 126

Well this is something that comes with Flutter as well, 127

and it's called a hot restart. 128

What this does, is that it does in fact, reset the state of your app. 129

So if you needed to test your app from the start, 130

So when number of donuts gets reset back down to zero, then this is the button that you would use instead. 131

So I'm changing the background color, and then I'm pressing hot restart, instead a hot reload. 132

And you can see that in the console, it's doing exactly that. 133

Now it still doesn't take as long as actually starting the app from cold, when you stop it and run it 134

again. 135

But it does in fact, reset the state of our app and you can see that not only is this background gets 136

changed to blue, but also the number of doughnuts eaten get reset back down to zero. 137

And it only took eight seconds for this to happen. 138

So you might be wondering. Well, OK, that's fair enough on a very simple app right. 139

Like you know something that just counts the number of doughnuts that you've eaten. 140

But what if I had a big app with thousands of lines of code, then surely you know hot reload and hot 141

restart won't really be very useful for me. 142

Well actually, it still is. Because of the way that hot reload and hot restart work, what they do is they 143

will only look at the changes that were made, and they will push those changes onto your testing device, 144

your simulator or your iPhone. 145

It's almost kind of like, if you're somebody like me who travels a lot, 146

I actually have a suitcase that's pre-packed with pretty much all the things I always need when I go 147

travelling, like toothbrush, toothpaste, my you know, a couple of pair of socks and those kind of things. 148

And depending on where I go, I might add a few things or move a few things. Say if I'm going somewhere 149

that's quite warm, I might add a pair of sunglasses. 150

So it's only the changes that I'm making to my suitcase that gets put into the suitcase. And this means 151

I save myself a lot of time. Instead of packing my suitcase from scratch, 152

I'm only adding the changes that I need for a particular destination. 153

And this is how hot reload and hot restart works. 154

So in this case, size doesn't actually matter. It doesn't matter if you are packing for a small suitcase 155

or a giant suitcase. As long as you already have the suitcase packed, and you're only adding to it one 156

thing or two things, depending on which destination you're going to, then it doesn't actually take any 157

longer to pack a larger suitcase or a smaller suitcase. 158

And this is the same for our Flutter code, even if we're hot reloading for changes that we've made to 159

a really complex large project. 160

It will still be just as fast as doing it for a tiny project like this one here. And in the coming lessons, 161

we're gonna be using hot reload and hot restart to almost instantly, see the changes that we're making 162

with our code in our simulator. In the next lesson, 163

that's exactly what we're going to be building. We're gonna be building out our container, and seeing 164

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 165

lesson.

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