All language subtitles for 7. [Dart] Variables

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
en English
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
ru Russian
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
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
wo Wolof
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu

Original subtitles

0 In the last lesson, we saw that we could create a variable to hold a value and insert that value inside 1

here by using that dollar sign. 2

This is called string interpolation. But if you're new to programming and you don't know what variables 3

are, what strings are, and how these things work together to produce this effect, then I want to quickly 4

spend this lesson talking about variables in Dart. 5

So if you're an experienced programmer and you know all about variables, then feel free to skip the next 6

two lessons where I talk about variables and data types and head straight to the next lesson 7

when we continue building out our dice app. But for everybody else who's with me, 8

let's head over to our slides, and let's talk more about variables in Dart. Now, 9

variables at the end of the day, it's just a container. 10

It's just a fancy way of saying a data container. 11

So we've known each other for a little while now and it might be time for me to introduce myself. My 12

name is Angela. 13

Now that's a piece of information that you might hear as a human 14

very frequently. My name is this or my name is that. Or I might tell you that I live in London and my 15

life ambition is to eat my own body weight in Sushi. 16

But if you a computer, all of this information would be best stored as a variable. So you would have a 17

variable that's called name, and you would store the value Angela in that variable. So the full line of 18

code would look something like this. Var is a keyword that says I'm creating a variable, then I give that 19

variable a name. 20

So in this case it's called myName. And I set what that variable's equal to. So in this case, it's Angela. 21

And all the rest of it such as the semicolons and the equals sign, 22

they're all just syntax. And syntax is just computer grammar. Just as we would have commas or full stops 23

or call ons in the English language, 24

Computers also have their own grammar. And this grammar differs from programming language to programming 25

language. But in Dart, this is what it looks like when you create a new variable. 26

Now what's actually happening here? 27

Well, essentially when I write the keyword var, the computer builds a box. And then it looks to see what 28

name it should give that box. 29

So this one's called myName. And then it looks at the right hand side of the equal sign to see what 30

it should put into the box. 31

In this case it's the word Angela. And the semicolon just says, 'well this is the end of my line of code. 32

So you can close the box now.' 33

So now I have this shelf and as you create more and more variables, you build up shelves full of these 34

boxes. And whenever you need one, you can go ahead and pull it off the shelf and open it to see what's 35

inside. 36

So for example, if I wanted to print the value of the variable i just created, myName, 37

this is how I would write it. 38

I would use the print function and inside the parentheses,I would tell it where I want to print. 39

And in this case, it's not actually the words 'myName' that will be printed. 40

It's the value of that variable. 41

So by running this line of code, the computer is going to pick up that box that's labeled myName from 42

the shelf. 43

It's going to open it up, see what's inside. 44

And it's going to put that into the console. 45

And in reality, what you'll see is the output from Flutter, saying the words 46

Angela. In order for you to try this out yourself and not just take my word for it, head over to dart 47

pad.dartlang.org and I'll include a link to this in the course resources as well. 48

And I want you to delete everything inside the DART file here 49

other than the void main. 50

So from our functions lesson, you know that this is a function. 51

And this is the function that acts as the entrance point to all of our DART programs. 52

And at the moment, I'm telling it to do nothing when it starts. 53

And so when I hit run, nothing happens. But if inside here, I told it to maybe create a new variable that's 54

called a variable my name. 55

And that said it equaled the string, that's Angela. 56

So strings have these single quotes around them in Dart. 57

If you come from other programming languages, you might see double quotes. 58

But this is the convention that we work with when we're writing Dart code. And then I'm going to tell 59

the computer that I'm done with my line of code by closing it off with a semicolon. 60

So now that I've created my variable, I can use it and I can use it by referring to its name which is 61

this part right here. 62

Let's go ahead and write a print statement. And inside the print statement, let's get it to print myName 63

and close off that line of code as well. 64

And now let's click Run, and you will see the word Angela which is the value of my name printed in our 65

console. 66

So now if I'm late today, I decided that I didn't really want to have the same name anymore or if I wanted 67

to change the value that's stored in my variable, I can simply reassign it. So I can say now, my name is 68

equal to Jane. 69

And what will happen is that will fetch that box that's labeled myName, it'll will take out Angela from inside 70

it and we'll put the new value inside. 71

So now myName is equal to Jane. 72

So now if we head back to our dartpad, and I change the variable my name to equal the new value right? 73

Let's say I'm now called Jack Bauer. And I go ahead and move my print from that line to this line. 74

What do you think will be printed now? 75

Will it be Angela or will it be Jack Bauer? 76

All right. 77

So hurray for those guys who got it right. Now in Dart, when you're inside a function, 78

so inside a set of curly braces, the code runs from top to bottom. 79

So at this stage if I had a print statement, then it would print out Angela because my name is still 80

equal to Angela. 81

But at this point I modify my name to make it equal to Jack Bauer. 82

So when I print it here, it's now equal to Jack Bauer. 83

And when I click run, you'll see first my name is Angela 84

will get printed, 85

and then Jack Bauer will get printed after it's been changed. 86

Now, what if I decided to change this variable to something a little bit different? 87

What if I try to make it equal a number say 123? 88

Well now you can see already, the Dart compiler's warning us that the value of type 'int' cannot be assigned 89

to a variable of type 'String'. 90

And if I click run, then everything crashes and I've got some errors inside my console telling me pretty 91

much the same thing. 92

So what is an int and why can't it be assigned to a string? 93

Well if you're interested in finding out about that, head over to the next lesson where we discuss about 94

Dart data types. 95

So hopefully I'll see you there.

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