All language subtitles for 4. Displaying the Questions

af Afrikaans
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bn Bengali
bs Bosnian
bg Bulgarian
ca Catalan
ceb Cebuano
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
tl Filipino
fi Finnish
fr French Download
fy Frisian
gl Galician
ka Georgian
de German
el Greek
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
km Khmer
ko Korean
ku Kurdish (Kurmanji)
ky Kyrgyz
lo Lao
la Latin
lv Latvian
lt Lithuanian
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mn Mongolian
my Myanmar (Burmese)
ne Nepali
no Norwegian
ps Pashto
fa Persian
pl Polish
pt Portuguese
pa Punjabi
ro Romanian
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
st Sesotho
sn Shona
sd Sindhi
si Sinhala
sk Slovak
sl Slovenian
so Somali
es Spanish
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
te Telugu
th Thai
tr Turkish
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu
or Odia (Oriya)
rw Kinyarwanda
tk Turkmen
tt Tatar
ug Uyghur
Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated: 0 1 00:00:00,800 --> 00:00:07,880 So now that we've learned all about Dart lists, you'll start seeing them all over the place. And to start 1 2 00:00:07,880 --> 00:00:08,180 with, 2 3 00:00:08,180 --> 00:00:12,440 we already said that the columns, when we're trying to set its children property, 3 4 00:00:12,530 --> 00:00:19,070 it always expects a list of widgets. And that's why we create them inside these square brackets, 4 5 00:00:19,070 --> 00:00:21,040 and also so do these rows. 5 6 00:00:21,050 --> 00:00:25,370 They also want to have children that contains a number of widgets. 6 7 00:00:25,880 --> 00:00:32,240 So now that we've seen our list in action and we've set up our scorekeeper, we want to actually go ahead 7 8 00:00:32,330 --> 00:00:37,660 and remove all of these icons and start off with a empty list. 8 9 00:00:37,700 --> 00:00:44,210 And as the user scores points, we'll add checkmarks or cross marks to our scorekeeper so that we actually 9 10 00:00:44,210 --> 00:00:45,950 keep track of their score. 10 11 00:00:45,950 --> 00:00:51,140 Now we can either go through our code and find all the places where we need to remove some of these 11 12 00:00:51,140 --> 00:00:58,540 things such as for example when we added it to here on the onPressed of our true button, or when we added 12 13 00:00:58,540 --> 00:01:01,480 our icons into our scorekeeper list. 13 14 00:01:01,760 --> 00:01:04,830 But there's another way that you can do this with Android Studio. 14 15 00:01:04,970 --> 00:01:11,090 So very helpfully, Andrid Studio is actually tracking everything that you're doing behind the scenes. 15 16 00:01:11,090 --> 00:01:14,750 Now it sounds a bit creepy, but it's actually super helpful. 16 17 00:01:14,750 --> 00:01:22,190 So first they go into the VCS menu up here, and this stands for version control system. 17 18 00:01:22,190 --> 00:01:25,400 So a part of that has on local history. 18 19 00:01:25,550 --> 00:01:31,010 If we go in there and we click on show history, then you'll see all of the code changes that we made. 19 20 00:01:31,250 --> 00:01:40,690 For example 30 minutes ago, I added my check icon, that's green, to my scorekeeper. And even further along, 20 21 00:01:40,730 --> 00:01:47,930 maybe 34 minutes ago, I added this scorekeeper list to my Quiz page state. So you can see that 21 22 00:01:48,230 --> 00:01:53,440 this is current and this is 42 minutes ago, what it used to look like. 22 23 00:01:53,480 --> 00:02:00,290 So what you can do is you can simply, if you wanted to rewind the clock and go back in time, then you 23 24 00:02:00,290 --> 00:02:07,010 can see that these are the additions that you made and these are the things that you deleted. 24 25 00:02:07,040 --> 00:02:14,630 So if you wanted to revert back to this date 35 minutes ago, you can simply select it and click 25 26 00:02:14,630 --> 00:02:19,220 on this button which will revert to the previous changes. 26 27 00:02:19,250 --> 00:02:28,640 So now if we go back, you can see it's like we time traveled back to 45 minutes ago. And now our icons 27 28 00:02:28,730 --> 00:02:33,340 are inside our row and we don't actually have our list. 28 29 00:02:33,530 --> 00:02:38,160 Now what if you want to go forwards in time and you want to go to the future? 29 30 00:02:38,210 --> 00:02:39,950 Well you can also do that. 30 31 00:02:40,040 --> 00:02:48,350 You can go to the 32 minutes ago version for example and let's click on this, and now we have our scorekeeper 31 32 00:02:48,620 --> 00:02:49,690 list again. 32 33 00:02:49,760 --> 00:02:52,470 Now it gets a little bit confusing if you time travel a lot. 33 34 00:02:52,490 --> 00:02:59,170 And as with all good time traveling movies they always tell you that you can't do it too much. This is 34 35 00:02:59,170 --> 00:03:07,140 quite helpful when you've made some grave error and just using COMMAND + Z to go back wasn't enough. 35 36 00:03:07,240 --> 00:03:14,580 Then using that history browser to go back and forwards will be really really helpful. Now just check 36 37 00:03:14,580 --> 00:03:20,730 to make sure that in your onPressed for your true button, there's nothing in there other than the comment 37 38 00:03:20,730 --> 00:03:24,850 that says well this is what should get triggered when they use it picked true. 38 39 00:03:24,990 --> 00:03:31,980 And we're also going to delete all of our icons from our list so that we end up with a empty list to 39 40 00:03:31,980 --> 00:03:34,400 start with for our scorekeeper. 40 41 00:03:34,410 --> 00:03:39,420 Now if you scroll all the way to the top, you might see you have this green squiggly line underneath 41 42 00:03:39,420 --> 00:03:40,560 the word Quizzler. 42 43 00:03:40,830 --> 00:03:45,750 And this is because Android Studio thinks that Quizzler is a typo. 43 44 00:03:45,750 --> 00:03:51,890 Now we know better. We know that Quizzler is actually a super awesome name for a app, 44 45 00:03:51,900 --> 00:03:53,760 so this is definitely not a typo. 45 46 00:03:53,790 --> 00:03:59,790 And if you want to get rid of it, simply right click and go to spelling and click save this word Quizzler 46 47 00:04:00,090 --> 00:04:02,130 to the project level dictionary. 47 48 00:04:02,160 --> 00:04:09,270 So now inside this project, it won't tell you that this is a typo anymore which is perfect. 48 49 00:04:09,270 --> 00:04:15,180 So now let's focus on displaying some questions to the user because at the moment, our app just says 49 50 00:04:15,240 --> 00:04:19,540 this is where the question text will go and it doesn't actually show anything. 50 51 00:04:19,560 --> 00:04:27,180 So we have to update this part. Now we want to create a list of questions and every time we press the 51 52 00:04:27,180 --> 00:04:33,760 true or the false button for it to check our answers and then to go to the next question in the list. 52 53 00:04:34,170 --> 00:04:38,480 So in order to do this, we've included three questions to start you off. 53 54 00:04:38,910 --> 00:04:45,360 And they each have their correct answers. So you can lead a cow downstairs but not upstairs, is in fact 54 55 00:04:45,430 --> 00:04:46,120 false. 55 56 00:04:46,170 --> 00:04:51,990 You can apparently lead a cow up and downstairs because they're super awesome animals. 56 57 00:04:51,990 --> 00:04:57,930 So we're going to start off with the first question. And then when you click the true button or the false 57 58 00:04:57,930 --> 00:05:03,900 button, it should go to the next question until the end of course. If you want to follow along with me, 58 59 00:05:03,960 --> 00:05:07,560 then we're going to get started tackling this bit by bit. 59 60 00:05:07,560 --> 00:05:07,830 All right. 60 61 00:05:07,830 --> 00:05:11,800 So first things first, let's review these three questions. 61 62 00:05:11,940 --> 00:05:17,480 Now one thing that might be a little bit unusual here is this little backslash here. 62 63 00:05:17,520 --> 00:05:22,200 Why is it saying a slug backslash's blood is green? 63 64 00:05:22,230 --> 00:05:30,180 Well I actually want to say a slug's blood is green. But because in Dart, we use these single quotes as 64 65 00:05:30,180 --> 00:05:33,930 a way of telling the computer that this is a String, 65 66 00:05:33,930 --> 00:05:35,090 this is a piece of text. 66 67 00:05:35,490 --> 00:05:40,800 Then if we have any extra single quotes in there, it gets confused whether if the string should end here 67 68 00:05:41,160 --> 00:05:47,430 or whether if the string should end there. And that's why we have this backslash. It helps to show the 68 69 00:05:47,430 --> 00:05:52,980 computer that the thing that comes after it is actually something that is a part of the English language 69 70 00:05:53,060 --> 00:05:54,880 and not the coding language. 70 71 00:05:54,900 --> 00:05:57,130 So let me show you this in more detail. 71 72 00:05:57,690 --> 00:06:02,560 So if we're going to display these questions, we're going to use a list. 72 73 00:06:02,640 --> 00:06:05,700 So up here below where we have our scorekeeper, 73 74 00:06:05,850 --> 00:06:12,870 we're going to create a list of strings. And we're going to call it questions, and it's going to contain a 74 75 00:06:12,870 --> 00:06:15,770 list of all three questions. 75 76 00:06:15,810 --> 00:06:23,970 So if we go ahead and copy our questions one by one including the single quotes, so that they go in as 76 77 00:06:23,970 --> 00:06:33,800 a string, then we can build up our list of questions and have three in our list. 77 78 00:06:33,900 --> 00:06:37,860 So here's the second one and here's the final one 78 79 00:06:41,500 --> 00:06:47,190 now that we've got all three strings in our list, we can close off our list of questions. 79 80 00:06:47,260 --> 00:06:50,560 And now you see that backslash in action. 80 81 00:06:50,710 --> 00:06:53,020 Check out what happens when I delete it. 81 82 00:06:53,020 --> 00:06:56,610 When I delete the backslash it thinks that this is the beginning of the string, 82 83 00:06:56,770 --> 00:06:58,480 and this is the end of the string. 83 84 00:06:58,540 --> 00:07:05,500 And it interprets the rest of the text as code, which it obviously isn't. 84 85 00:07:05,500 --> 00:07:12,580 So what we do is right in front of the single quote inside our string, we're going to add a backslash. 85 86 00:07:13,090 --> 00:07:22,650 And now it knows to ignore this single quote and to use the next one as the end of that string. 86 87 00:07:22,890 --> 00:07:26,430 Now that we've created our list of questions, 87 88 00:07:26,430 --> 00:07:34,590 the next thing to do is we need to update the question text that gets displayed in here to the first 88 89 00:07:34,740 --> 00:07:36,170 item in our list. 89 90 00:07:36,180 --> 00:07:40,950 So we want this to say you can lead a crowd downstairs but not upstairs. 90 91 00:07:41,190 --> 00:07:43,590 And I'm going to leave this to you as a challenge. 91 92 00:07:43,590 --> 00:07:51,360 So identify the right place in your widget tree to update and try to use this list called questions 92 93 00:07:51,660 --> 00:07:54,360 to get it to show up inside this area 93 94 00:07:54,360 --> 00:08:00,040 here. Pause the video and try to complete this challenge. All right. 94 95 00:08:00,070 --> 00:08:02,890 So let's first identify where this comes from. 95 96 00:08:02,890 --> 00:08:10,720 Now we can either do it in a fancy way by clicking on this locate button, and then we can click on here 96 97 00:08:10,840 --> 00:08:17,080 and it'll locate to us the widget that's responsible for displaying this, which happens to be a text 97 98 00:08:17,170 --> 00:08:17,870 widget. 98 99 00:08:18,070 --> 00:08:20,520 And this is where that text comes from. 99 100 00:08:20,590 --> 00:08:24,650 And this is the original sort of hardcoded text that gets displayed. 100 101 00:08:24,850 --> 00:08:29,280 Now instead of that, we're going to use our question list. 101 102 00:08:29,290 --> 00:08:36,850 So in order to get the first item in the list, we have to write questions, to tap in to that list, and 102 103 00:08:36,850 --> 00:08:42,050 then we can either specify the index where the index is 0. 103 104 00:08:42,130 --> 00:08:50,410 And this refers to the first item in this list of questions which is of course this one. Or we can use 104 105 00:08:50,410 --> 00:08:53,880 that trick that we saw earlier on which is questions.first 105 106 00:08:54,160 --> 00:09:03,480 Both work exactly the same way. But in this case I'm actually going to stick to using a number and this 106 107 00:09:03,480 --> 00:09:06,210 will become clear very very quickly. 107 108 00:09:06,210 --> 00:09:13,590 So now that we've managed to get our first text to show up inside our text widget, the next thing is 108 109 00:09:13,650 --> 00:09:19,680 we need to create some sort of tracker to track where we are in this list of questions. 109 110 00:09:19,710 --> 00:09:25,530 At the moment we're on zero. But the next thing that we want to happen is when we click on the true or 110 111 00:09:25,530 --> 00:09:29,040 the false button, we want to progress to the next question. 111 112 00:09:29,100 --> 00:09:36,030 So in order to track which question we're on, we want to create a new variable called questionNumber, 112 113 00:09:36,510 --> 00:09:44,630 and it's going to keep track of what is the current question that we have displayed in our text widget. 113 114 00:09:44,670 --> 00:09:50,730 Try to complete this as a challenge and create your variable right here. So pause a video and complete 114 115 00:09:50,730 --> 00:10:00,390 the challenge. So we're going to create a new variable called questionNumber. And because it's going 115 116 00:10:00,390 --> 00:10:04,210 to keep track of where we are in our list of questions, 116 117 00:10:04,260 --> 00:10:10,890 it's pretty much going to be an integer. And it's going to start off with the value 0 to correspond to 117 118 00:10:10,950 --> 00:10:13,830 the first item in our question list. 118 119 00:10:13,830 --> 00:10:16,460 Remember lists start numbering from 0. 119 120 00:10:16,640 --> 00:10:18,210 And let's give it a day to type. 120 121 00:10:18,210 --> 00:10:19,560 It's going to be an integer. 121 122 00:10:19,560 --> 00:10:28,620 It's always gonna be a whole number because it's simply going to go from 0 to 1 and to 2. Starting with 122 123 00:10:28,650 --> 00:10:39,090 question number 0 we can now replace this part where we get questions at index 0 to questions at index 123 124 00:10:39,360 --> 00:10:40,620 questionNumber. 124 125 00:10:40,620 --> 00:10:42,360 And if you hit save, 125 126 00:10:42,450 --> 00:10:47,520 nothing will change because questionNumber starts off being equal to 0. 126 127 00:10:47,700 --> 00:10:54,260 So 0 goes in here and we tap into our questions list looking for the zeroth item, 127 128 00:10:54,300 --> 00:11:03,480 so no changes there. But the next thing to do is we want to increase this questionNumber by 1 whenever 128 129 00:11:03,480 --> 00:11:08,500 the user clicks on the true button or the false button. 129 130 00:11:08,550 --> 00:11:15,990 Keep in mind what we learn in Dicee and Magic April about updating the state of the user interface. And 130 131 00:11:15,990 --> 00:11:17,380 using that hint, 131 132 00:11:17,460 --> 00:11:24,330 I want you to pause the video and see if you can figure out how to increase our questionNumber when 132 133 00:11:24,360 --> 00:11:28,440 we click on the true or false button and update our text widget. 133 134 00:11:31,860 --> 00:11:32,200 All right. 134 135 00:11:32,230 --> 00:11:37,090 So the place where we want to do this is of course in our onPressed. 135 136 00:11:37,550 --> 00:11:40,270 So in this case this is where they use it picked true. 136 137 00:11:40,370 --> 00:11:44,020 And we also want to do the same thing when the user picks false. 137 138 00:11:44,060 --> 00:11:48,740 We're going to go to the next question no matter which choice they picked. 138 139 00:11:48,920 --> 00:11:54,130 Right here below the comment, I'm going to try and increase the questionNumber by one. 139 140 00:11:54,170 --> 00:12:02,130 Now you can either say questionNumber now equals the previous value of questionNumber + 1. 140 141 00:12:02,180 --> 00:12:09,770 So if it was 0, it becomes one etc. or a slightly shorter way of doing this that you'll find in many 141 142 00:12:09,770 --> 00:12:13,970 programming languages is to simply write questionNumber++. 142 143 00:12:14,240 --> 00:12:18,290 And this is where the programming language C++ comes from. 143 144 00:12:18,380 --> 00:12:22,690 It's the C programming language increased by 1. 144 145 00:12:22,700 --> 00:12:27,260 So it's kind of like the sequel to the C programming language. 145 146 00:12:27,260 --> 00:12:34,010 This now will increase our questionNumber by 1 and we're going to do the same down here when the 146 147 00:12:34,010 --> 00:12:35,540 user presses false. 147 148 00:12:35,690 --> 00:12:43,640 But right now if you hit save, even though we can print our questionNumber and we can assure ourselves 148 149 00:12:43,670 --> 00:12:47,750 that it's actually in fact going up by 1. 149 150 00:12:47,870 --> 00:12:52,560 And let me just put that down here as well in both places and hit save. 150 151 00:12:52,610 --> 00:13:00,950 Let's pull up our run and now, if I click on either the true button or the false button, you can see my 151 152 00:13:00,950 --> 00:13:06,140 questionNumber is going up. But my text widget isn't changing. 152 153 00:13:06,140 --> 00:13:07,220 Why is that? 153 154 00:13:07,220 --> 00:13:17,580 Well remember my hint about state because our text widget up here depends on this question number. 154 155 00:13:17,600 --> 00:13:26,450 So when our questionNumber updates from 0 to 1, we should now be pulling in the first item from our 155 156 00:13:26,450 --> 00:13:31,390 questions list which is this question right here. 156 157 00:13:31,430 --> 00:13:41,420 So in order for it to update, we have to get this widget tree rebuilt. And in order to mark the places 157 158 00:13:41,570 --> 00:13:48,050 where we've changed something, we have to use that set state method. 158 159 00:13:48,050 --> 00:13:54,980 So we had the right set state and inside the curly braces is where we need to increase our question 159 160 00:13:54,980 --> 00:13:55,850 Number. 160 161 00:13:55,880 --> 00:14:00,920 So I'm going to copy that down into the false button as well. 161 162 00:14:00,920 --> 00:14:10,880 And now what will happen is when the button is pressed, it's going to mark anything that uses the question 162 163 00:14:10,880 --> 00:14:12,940 Number as dirty. 163 164 00:14:13,190 --> 00:14:20,510 And the thing that uses the questionNumber is of course on text widget and it's going to trigger a 164 165 00:14:20,600 --> 00:14:23,000 rebuild of our widget tree. 165 166 00:14:23,210 --> 00:14:31,070 And it's going to refresh this text widget with the latest question from our list of questions. 166 167 00:14:31,070 --> 00:14:33,420 So let's check this out. Now, 167 168 00:14:33,500 --> 00:14:41,540 it's important that you keep an eye on the run area because at the moment, if I click on true, you can 168 169 00:14:41,540 --> 00:14:43,970 see that my app crashes. 169 170 00:14:43,970 --> 00:14:51,860 And the reason is because right now, it's printing out a question number of 3 and we get an error 170 171 00:14:51,890 --> 00:14:59,660 in here. It says range error not in range 0..2. 171 172 00:15:00,380 --> 00:15:03,170 So what's going on here? 172 173 00:15:03,170 --> 00:15:10,670 Well notice that our question number is currently 3. But if we go into our list of questions and 173 174 00:15:10,670 --> 00:15:19,240 we count from the beginning 0, 1, 2, well there is no 3. There is no fourth question. 174 175 00:15:19,260 --> 00:15:20,870 right? 175 176 00:15:20,910 --> 00:15:27,220 So this is why it's telling you that it's outside of the range of this list of questions. 176 177 00:15:27,540 --> 00:15:29,040 So what's the cause of this? 177 178 00:15:29,040 --> 00:15:30,780 We just started our app. 178 179 00:15:30,840 --> 00:15:38,190 Well it's because you might remember when we talked about hot reload and hot refresh. Hot reload actually 179 180 00:15:38,190 --> 00:15:40,810 keeps the state of your app. 180 181 00:15:40,830 --> 00:15:41,970 What does that mean? 181 182 00:15:41,970 --> 00:15:48,060 Well it means that when we have these variables such as questionNumber, and we know that every time 182 183 00:15:48,060 --> 00:15:50,630 we click on a button it grows by 1, 183 184 00:15:50,700 --> 00:15:56,390 that doesn't change. If we wanted to reset it back to zero 184 185 00:15:56,400 --> 00:16:00,630 then we have to click on hot restart instead. 185 186 00:16:00,750 --> 00:16:02,310 So let's click on hot restart. 186 187 00:16:03,360 --> 00:16:08,660 And now notice that the first question is displaying in the text widget. 187 188 00:16:08,660 --> 00:16:13,130 And when we click on the true button, it will increase our question number by one. 188 189 00:16:13,170 --> 00:16:15,410 So it will take it up to 1 189 190 00:16:15,540 --> 00:16:19,760 and the question at index 1 is of course this one. 190 191 00:16:19,920 --> 00:16:27,480 And now if we click on one of the buttons again, it will go to 2, which is a slug's blood is green. 191 192 00:16:27,480 --> 00:16:31,980 Now we keep pressing then it's going to crash because we don't have any more questions. 192 193 00:16:32,010 --> 00:16:33,270 That's all that we've got. 193 194 00:16:33,630 --> 00:16:43,180 So our code now works until we run out of questions. If some parts of this was confusing such as how 194 195 00:16:43,180 --> 00:16:49,950 a set state works or what is the difference between hot reload and hot refresh, then be sure to revisit 195 196 00:16:49,980 --> 00:16:53,520 those modules where we covered those topics in more detail. 196 197 00:16:53,640 --> 00:16:58,050 But once you've reviewed the code and once you're happy with it, then we're going ahead of it to the 197 198 00:16:58,050 --> 00:17:02,610 next lesson and we're going to set up the answers for the questions. 22360

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