All language subtitles for 43. Getters & else-if

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 Download
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

So in result here,

let's add a final property, an int, resultScore or whatever you want to name it,

let's add our constructor and now as a positional argument, though of course you could always use a named

argument if you prefer that

but here I will take this as a positional argument,

my score.

So when we use the result widget here, we now have to forward the score and that of course now is our

total score.

So now the total score which we calculate here in the MyAppState class with the help of our total score

property

and the answerQuestion function, that total score is now forwarded to result and in result, we now

receive this here in the constructor and we automatically, thanks to the shortcut here, store it in the

resultScore property.

Now I just want to output different texts here based on my results score. Now first of all, let's assign

some styling here, we did this earlier, I will do this with the help of the TextStyle class here and the

style argument on my text widget and I want to set the font size here, to let's say 36 and also set the

FontWeight, we haven't done that before to FontWeight.bold. Again FontWeight is here a class and

that is a static property,

again FontWeight therefore is basically a utility, a grouper class which groups a couple of predefined

values and that is basically a value that instructs Flutter to turn this text to bold text.

Still we need different texts and we get different ways of now generating this,

I like the way of adding a getter here. A getter here is a special type of property,

it's basically a mixture of property and method.

You create a getter by first of all defining which type of value you want to get,

you want to derive and that would be a string because I want to get some text,

then you add the get keyword and then any name you want, like resultPhrase.

Now unlike in a method, you now don't add parentheses because a getter is like a method that can never

receive any arguments.

You do add a body though and in that body, you now have to return a string,

you always have to return something in a getter, you use it however like a normal property.

So down there instead of you did it,

I will use resultPhrase and I don't use it with parentheses to execute it like a function,

I'm also not using it as the address of a function because this is no function,

this is simply a Dart feature,

it's a normal property but the value is calculated dynamically and here, the value I want to calculate

is calculated based on the result score.

So in here, in my body of that getter, I'll create a new variable, result

text to avoid name clashes here and I'll assign a default of you did it but then I want to add an if

statement and check if my results score is let's say smaller or equal than 8.

If that is true, then here between the curly braces, I'll set result text equal to you are awesome

and innocent.

So I'm overwriting result text with that new value here,

else if and that's now new, I mentioned it earlier,

we haven't used it thus far,

it's an else statement which kicks in if that condition is not satisfied

but unlike the normal else statement, it does now not blindly execute the code between the curly braces

but it checks another condition first

and here I check if results score is smaller or equal than 12.

So if it's not smaller or equal than 8, then maybe it's smaller or equal than 12.

In that case I would set my result text to pretty likable, with an extra e though. If we don't

make it into there, we can check if the result score is smaller or equal than 16 maybe

and remember that in the way I designed this quiz, higher scores mean a more negative personality.

So in that case, I will set result text to

you are strange and then in all other cases, I will set the result text to

you are so bad.

Now of course since I have that overall else case here, we don't really need an initial value here because

we'll never keep that, we'll certainly at least make it into this else block here.

So we could also get rid of that and in that case as you learned, it's a good practice to define the type

that will be stored in result text in the end which is a string.

Now here in the end, I do return that result text and therefore now when we use resultPhrase down there,

that should be based on the result score we're getting and we should be outputting different results

based on the choice the user made. So let's reload this application here and now let's go for a

negative personality,

so I like black,

I like snakes and here everything is right and we see you are so bad.

Now that's good,

let's restart the app with the green button here.

Of course, it would be nice of a button here but for the moment, we don't have that.

So let's wait for that to reload

and now let's go for a good personality,

white and then I like rabbits

and of course I like myself,

you are awesome and innocent. So that's nice,

one thing of course I notice is the text itself is not centered, so we can quickly do that in the

result.dart file, here on the text widget, we can set textAlign to TextAlign.center, something we also

did earlier and now if we save that, it is centered.

So that's pretty sweet and that's working as it should

as it seems like, we're now showing different results based on different choices and now we have

maybe not the most awesome application we ever built but a realistic application that we could

fine tune and already deploy to the app stores if we wished to do that.

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