All language subtitles for 20. Anonymous Functions

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
fr French
fy Frisian
gaa Ga
gl Galician
ka Georgian
de German
el Greek
gn Guarani
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

Now this way of hooking up a button to a function is one of two possible ways.

We have our function here, our named function inside of stateless widget

and then we connect here to onPressed.

Now another way of solving this would be to use an anonymous function,

this here is a named function because it has a name.

Now if you have a function which you really only need here in this one place and you're never calling

it from anywhere else in the application which is already not the case here because we have three buttons

that use the function

but let's say you only had one button, then instead of using a named function which you can always do

but instead of doing that, you can add a function right here. Now without a name but you simply add parentheses

to get any possible arguments, in this case you don't get any though,

so it's an empty pair of parentheses and then either that one line expressions syntax with an arrow function

and then the code you want to execute,

so here answer 2 chosen for example or if I do the same on answer 3,

you can also add curly braces for a possibly longer function body.

So here, you could now do some stuff and then in the end, print answer 3 chosen, like this

and here I had one parentheses too much.

Now if I save that, you will see that if I click answer 1, 2, 3 here, we see answer chosen,

that's from the answer 1 button which executed our name,

answerQuestion function, then we had answer 2 chosen which is coming from my anonymous function here

and answer 3 chosen which is coming from the function here

and it's called anonymous because it has no name here,

it just has the argument list and then the function body.

Now an anonymous function always is a good idea if you never need to call it from anywhere else in the

code because you can't call it from anywhere else, it has no name

but you don't need to define it up here

if you only need it in one place.

So these are two function syntaxes which you will also see throughout the course, please note that this

also is not executed immediately,

this is just the function definition,

I didn't add parentheses after that which would execute it immediately,

instead I just defined my function here with the arguments in the function body and I pass that definition

of the function to onPressed, which therefore ensures that the RaisedButton can execute the function when

the user really pressed the button. So that's a lot of fun with buttons and functions and it's a crucial

building block of Flutter applications because in your typical application of course, you do interact

with the user and you want to give the user some chance of interacting with the application

and that requires exactly what we learned here.

Nonetheless right now, we're really just doing some behind the scenes stuff right,

we're really just printing something here and that's nice for debugging so that we see that the buttons

really are pressed but it would be nicer to change something on the screen before we then also later

work on the general layout and the look of this and that is exactly what we'll do next.

Let's make sure that something changes on the screen when we press one of these buttons.

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