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 All right. 1
So how did you get on with that challenge? 2
This should be quite simple because we've already done it once for the left dice. But it's important 3
that you understand how it all links together, which is why I wanted you to complete the challenge. 4
The first thing that we need to do is we've got a variable that's tracking the value for our leftDice 5
Number. And it's updating it when the button is pressed. So that it can display a new image in that image 6
widget. 7
Now in order to do the same for the right dice, we're going to need to create a new variable. And we'll 8
just call this rightDice 9
Number, because not feeling too imaginative today. 10
Now once we've got our variable, then we can go about changing it to a random number, when the flap button 11
is pressed. Inside our onPressed, 12
the first thing we're gonna do is we're going to say that our rightDiceNumber is going to equal to 13
a number that's generated from a random number generator. 14
And the specific type of number we want to generate is an integer, 15
so a whole number. And we're going to set the max to six. 16
So we generate random numbers between 0 and 5. And then we'll just add 1 to any of those numbers to bring 17
it up to 1 - 6, which matches with the dice numbers that we have in our images. 18
The next thing we're going to do is we're going to update the place where we use that rightDiceNumber. 19
Instead of pulling up the images/dice1.png, which is pretty much hardcoded, it's always going 20
to be the first image shown. We're going to delete that one, and instead we're going to use a string interpolation 21
to insert the rightDiceNumber inside there. And it's going to be inserted using that little dollar 22
sign there that we saw previously. 23
Now all we have to do is to say that when the rightDiceNumber changes, we should update all the places 24
where it's used. 25
So in order to do that, we have to call that method called set state. 26
And this simply says that this change in the rightDiceNumber's value is going to need to trigger a 27
rebuild of our stateful widget, so that the part where it's used can update on the screen. 28
Let's hit save and for those changes to go through to our app, and let's test it by... we already know the 29
left side works. 30
And now if we click on the right side, it also works. And it gives us all the numbers that we could possibly 31
want. 32
And we now have two separate dice that we can roll on our dice app. 33
Now what if we wanted both dice to change when one of the buttons is pressed? 34
So what if I wanted both of these buttons to update when I click on any one of those buttons? 35
Here is your challenge. 36
Try and get this behavior in your app. So pause the video and try to complete this challenge. 37
And I'll share with you the solution in the next lesson.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.