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
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Hungarian
Icelandic
Igbo
Indonesian
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
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.