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
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
0 So notice that all that we did, is we created a list of questions where we copied over the questions 1
from down here and we've only got three of them. 2
And then we created a variable to track where we are in the list of questions, 3
and it starts from zero. And then down here where we have our text widget, the text that we chose to display 4
in it comes from our list of questions pulling in the item at this particular index. And then down 5
here, in our onPressed for our true and false buttons, we use set state to update our question number 6
and update the screen when the user presses the true or the false buttons. 7
Now we can use the hot restart, 8
then we reset our question number back down to zero. And we can cycle through our questions until we 9
run out of questions at which point we get a range error because we don't have any more questions to 10
display. 11
So now that we've done that, the next part is to create a list of matching answers. 12
So right below our questions here, we're going to create a list of booleans, because these are going to 13
be our answers. 14
And this is also going to be a list, and it's going to correspond to the questions. So we can see that 15
the first question's correct answer is false, 16
and the second question is true and then the third is true. 17
So in our list of answers, we're going to listed in that order. 18
So again we say false, true, true. 19
So now, at the same index, our answers match our questions. At index 0 20
is this question and it's correct answer is false. 21
So now we can check to see if the user got the right answer. Inside our onPressed, 22
we're going to figure out if the user got the answer right or if they got it wrong. In order to do this, 23
we're first going to figure out what the correct answer was. 24
So let's create a new variable and it's going to hold data type of boolean. 25
And this is going to be called correct answer. 26
Now the correct answer of course comes from our list of answers, and we're going to pull out the answer 27
at the current question number. 28
So we're gonna say answer, and inside a set of square brackets, we're going to provide the question number. 29
So that means that when the user is seeing 'You can lead a cow downstairs but not upstairs', then 30
question number has to be equal to 0, because it starts off being 0. 31
And so when we look inside the answers list and we try to get the one at index 0, then that's the correct 32
answer for that question. 33
So now that we've got the correct answer, all we have to do is to check to see if what the user picked, 34
which in this case is true, is equal to the correct answer. 35
So we can use something called an if-statement, and inside these parentheses, we're going to check to 36
see if the user-picked answer, which in this case is true, is equal to the correct answer. 37
So we can say correctAnswer == true. Then that means the user got it right. 38
So we can print into the console, we can write user got it right. 39
But if they didn't get it right, then we're going to print user got it wrong. 40
If the correct answer is equal to the button that they picked, which is true, then we're going to print 41
they got it right, 42
otherwise we gonna print 43
they got it wrong. 44
And then down here at the other button, and this is the false button, 45
if they clicked on this button then we want to check if the correct answer is equal to false. Then that 46
means they got it right, 47
otherwise it means they got it wrong. 48
Now you have to make sure that this set of code goes before we increase the question number and we go 49
to the next question. Because we want to check the correct answer for the current question and make sure 50
that those two match. 51
Now if we go ahead and click hot restart to take our question number back down to zero and start on question 52
1, 53
then you can see that this is the question. And if I click on true, that's my selection, then it tells 54
me that I got it wrong because the actual correct answer for the first question is false. 55
Now let's go onto the next one. 56
Let's try and get this one right. 57
Let's check out the answer. 58
So this one, the correct answer is true. 59
So if I click on the true button, it tells me that I got it right. 60
And the final one is also a true. 61
So if I click on the false button, it tells me that I got it wrong, but then it crashes because it tries 62
to go to the next question, and we don't have another question. 63
So although this works, if we had more data for each question, say if we had instead of just true and 64
false, we had you know a multiple choice question or for each question we even had a picture that's associated 65
with it, then we would end up creating many many lists and try to make sure that we're always matching 66
the right item in these different lists. 67
And that's quite error prone. 68
So we're going to upgrade our questions and answers a little bit later on. 69
But first for those you guys who have never seen this syntax these if and else, or what we call conditionals 70
in programming, then the next lesson is all about that and we discuss how to use if and else statements in 71
Dart, and how to build up an elseif leader using Dart as well. 72
So if this is unfamiliar to you, then you might find the next lesson really helpful to get a better understanding 73
of this. 74
But if you're already familiar with how if and else works, then feel free to skip to the next lesson where 75
we're going to build a class for our questions.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.