All language subtitles for 5. [Dart] Functions - Part 1

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
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 Now in the last lesson, we covered flat buttons and the void callback that they expect. 1

We also used the print function and gave it an input, or rather an argument. 2

So in this lesson, I wants to quickly cover Dart functions. 3

So if you already know what an argument is, what return does and what a function does, then feel free to 4

skip this lesson and head over to the next one where we continue building out our Flutter app. 5

But for those guys who are staying with me, functions as you can guess from the name, are there to give 6

your app or you give your program some functionality, right? Now, 7

in this lesson, I want to talk about functions in the most fundamental sense and when we using functions 8

as programmers, 9

fundamentally, we're trying to package bits of code together into a block and to call that block of code 10

repeatedly, saving ourselves from typing the same code again and again and again. 11

So for example, if you had a little housekeeping robot, this guy. His name is Bit Bob. And he does a number 12

of things right? 13

For example he'll go and get you milk every day. But you have to tell him how to do it. 14

You have to tell him to leave the house, move right to blocks, move up four blocks, then move right to blocks, 15

get the milk, come back. And you have to specify all these instructions to him because he's a robot and 16

he doesn't understand contextual information like go to the store and get me some milk. Now if you had 17

to do this day after day after day every single time you wanted milk, your fingers would start hurting, 18

and you wouldn't want to keep typing out the same instructions. 19

Right? 20

So what can you do? 21

Well we're programmers. 22

We're born to be lazy. 23

So what we can do instead, is we can take all these instructions that the robot understands, and we can 24

package it into a block of code. 25

Now a block of code, in many many programming languages, is represented by code that inside a set of curly 26

braces. 27

Once we've got all our instructions inside our curly braces, we can give that block of code a name. 28

And in this case we've called it getMilk. 29

Now every time I need some milk, I can tell the robot get milk and it'll know what to do because it 30

will find this function called getMilk, and look inside it to see what it should do. 31

It's almost like I'm creating a recipe, right? 32

It's like, I want to eat cookies, but I don't want to bake cookies. 33

So let me write down a recipe and give it to my housekeeping robot, so that they can make it for me. 34

And that recipe or the name of the recipe is basically the name of our function. In Dart, the way that 35

you would create the function looks like this. 36

We've got the name of the function which is called getMilk, and then we've got the curly braces which 37

enclose all of the things that should happen when this function gets called. 38

And then later on when we actually need to use it, we will call the function or tell the computer to 39

execute all of this by writing something like this, giving the name of the function. 40

Now this is called a named function. 41

Well it makes sense because it's got a name. 42

Right? 43

We can identify it by what it's called. 44

Now if we dropped everything other than just the core parts, namely the parentheses and the curly braces 45

and all the instructions, then this would become an anonymous function, because it doesn't have a name. 46

Right? 47

And these anonymous functions are legion. 48

No just kidding. 49

These are anonymous functions are actually very useful. 50

They allow us to tell the computer to do something without explicitly having to create this entire function 51

and give it a name and call its name. When we were coding up our onPressed which expected a void callback, 52

it essentially wanted an anonymous function. 53

We passed in the two empty parentheses, and we gave it the block of code that we want to be executed 54

when the button got pressed. This is all you need to know about functions so far to be able to understand 55

what's happening in our flat 56

button. A little bit later on when we level up and we talk about functions in more detail, we'll talk 57

more about what goes in these parentheses namely some inputs into the function. And also we'll talk about 58

the return statement when we want our function to output something. 59

But for now, just know that this is anonymous function. 60

It has a set of parentheses and a set of curly braces. In the curly braces 61

we say what should happen. So now that we're all caught up, in the next lesson we're gonna get back to 62

coding up our dice app. And we're going to get our button to change our dice images to actually make the 63

app work. 64

So for all of that and more, I'll see on the next lesson.

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