Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Hungarian
Icelandic
Igbo
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranรฎ)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
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.