Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:02,390 --> 00:00:08,440
Now sometimes you have a really hard time finding an error, especially if it's not an error that throws
2
00:00:08,480 --> 00:00:11,990
an error message but if it's some logical error.
3
00:00:11,990 --> 00:00:16,220
Now what would be an example for a logical error?
4
00:00:16,340 --> 00:00:23,930
An example would be that we indeed add 2 here because maybe we mistyped and we'll now never get an error
5
00:00:23,930 --> 00:00:30,440
message because I commented out that line and in our widget tree, we also won't run into a situation
6
00:00:30,440 --> 00:00:34,330
where we select the wrong question because we render the results screen
7
00:00:34,340 --> 00:00:40,820
once we're out of questions or once our index exceeds the questions length, so we'll never get an error
8
00:00:40,820 --> 00:00:44,730
message here and still, we have the wrong behavior.
9
00:00:44,750 --> 00:00:52,190
When we test our app on the device, we see we seem to skip a question and we only got two questions until
10
00:00:52,190 --> 00:00:53,690
we reach the result screen.
11
00:00:53,900 --> 00:00:57,520
So something is wrong but here we got no error message,
12
00:00:57,560 --> 00:01:02,190
so how can you now narrow down the issue and find out what's wrong?
13
00:01:02,210 --> 00:01:03,590
There are two ways of doing that,
14
00:01:03,650 --> 00:01:10,940
the quick and dirty way is that you use print. Here for example, you could print question index to find
15
00:01:10,940 --> 00:01:13,850
out if something's wrong with that index.
16
00:01:13,850 --> 00:01:16,300
So we could do that here
17
00:01:16,570 --> 00:01:24,470
and if I save that and I now click through my question or for my answers again, then we see that
18
00:01:24,470 --> 00:01:30,470
the question index is 2 and 4 and that might already be all we need to know to find out oh something's
19
00:01:30,470 --> 00:01:31,580
wrong with the index,
20
00:01:31,610 --> 00:01:35,200
why is it increasing by 2, it should be increasing by 1.
21
00:01:35,230 --> 00:01:41,690
So this might be one way, using print in your code is a nice way of printing out the current state of
22
00:01:41,690 --> 00:01:46,640
a given value and find out if it has the value you would have expected.
23
00:01:46,640 --> 00:01:53,120
But if you have more complex problems, using this print debugging can be too cumbersome and therefore,
24
00:01:53,210 --> 00:02:00,740
you should use the more powerful built-in debugger. For that, quit the running app and now run the
25
00:02:00,740 --> 00:02:08,300
app in debugging mode, so start debugging, not start without debugging but start debugging or use the
26
00:02:08,300 --> 00:02:09,950
respective shortcut.
27
00:02:09,950 --> 00:02:15,440
Now this will also launch the app but as you can already tell, in a different mode. Here in
28
00:02:15,440 --> 00:02:21,100
Visual Studio Code, it automatically enters the debugging view which you can also activate manually here under
29
00:02:21,100 --> 00:02:22,720
view debug,
30
00:02:22,790 --> 00:02:29,210
you can always go back to the explorer if you want to see your files but in view debug, you now can
31
00:02:29,690 --> 00:02:33,350
do more than just add a couple of print statements,
32
00:02:33,350 --> 00:02:41,240
for example what you can do now is set breakpoints. You do that by moving your mouse cursor to the left
33
00:02:41,240 --> 00:02:48,530
side of the line numbers here in your editor view and then you can add a breakpoint by simply clicking
34
00:02:48,530 --> 00:02:49,130
there.
35
00:02:49,220 --> 00:02:56,330
Now a breakpoint will halt the code execution whenever it reaches this code line and you can then even
36
00:02:56,330 --> 00:03:03,350
look into the values of variables and properties and find out if everything has the value you expected
37
00:03:03,440 --> 00:03:04,940
and so on.
38
00:03:04,940 --> 00:03:11,780
You can also, if you want to, place breakpoints here in your widget tree, simply try a couple of different
39
00:03:11,780 --> 00:03:14,590
spots and see where code execution stops.
40
00:03:15,290 --> 00:03:19,760
So now let's wait for this installation to finish, for the build process to finish and let's see how the
41
00:03:19,760 --> 00:03:21,990
breakpoints work. Here
42
00:03:21,990 --> 00:03:23,530
the app already stopped,
43
00:03:23,560 --> 00:03:29,800
it launched the app and it stopped right away because I placed a breakpoint in my main.js file, in my
44
00:03:29,800 --> 00:03:33,110
MyAppState class, in the main build method
45
00:03:33,110 --> 00:03:38,920
therefore right here when the widget tree gets built. And now you can use the controls here in the top
46
00:03:38,920 --> 00:03:42,690
right on this bar to move through your code.
47
00:03:42,790 --> 00:03:49,300
With this icon here, you move through the next line of code, so to the next instruction to be precise.
48
00:03:50,500 --> 00:03:54,220
With the arrow next to it, you can step into,
49
00:03:54,210 --> 00:03:59,050
for example a function call, so that you don't skip it and just proceed with the result but that you
50
00:03:59,050 --> 00:04:01,610
really can go through each step in the function
51
00:04:01,750 --> 00:04:07,410
and if you are in such a function for example, you can use this arrow here to step out of it.
52
00:04:07,420 --> 00:04:13,240
So here, I'm in the build method of the quiz widget now because I stepped to the next step,
53
00:04:13,240 --> 00:04:20,890
we see that now here build was called and the cool thing is we can now step into this and if you hover
54
00:04:20,890 --> 00:04:26,440
over things like the context here or over questions, you can see what's in there.
55
00:04:26,500 --> 00:04:31,930
You can inspect this, you can find out what values are in there and if that all has the values you
56
00:04:31,930 --> 00:04:32,920
did expect,
57
00:04:32,920 --> 00:04:36,710
for example we can find the current question index value.
58
00:04:36,910 --> 00:04:40,030
You can also add values to the watch list here on the left
59
00:04:40,090 --> 00:04:44,710
so that you can watch how they change as you progress through code.
60
00:04:44,710 --> 00:04:50,890
So here for example, I could add question index and now you see it currently has a value of zero and
61
00:04:50,890 --> 00:04:54,020
we can check whether it stays that way.
62
00:04:54,100 --> 00:04:58,860
Now once you're done for the moment, you can always press the play button here on the left to continue
63
00:04:58,870 --> 00:05:05,170
code execution until the next breakpoint is hit and you see right now, question index is not available because
64
00:05:05,170 --> 00:05:07,910
we're not in that code snippet anymore. Now
65
00:05:08,020 --> 00:05:14,500
however if I press a button, I'm taken back to the editor because I also had a breakpoint in answer question,
66
00:05:14,620 --> 00:05:16,190
I placed that earlier
67
00:05:16,660 --> 00:05:21,480
and here, we can now see what the total score is for example, we can see what the question index is
68
00:05:21,490 --> 00:05:30,920
and here we might then already spot our mistake for example, our logical mistake. Again, we can step through
69
00:05:30,920 --> 00:05:33,170
our code step-by-step if we want to,
70
00:05:33,470 --> 00:05:39,740
so that we progress step-by-step. We always can see which variables we currently have in the method
71
00:05:39,830 --> 00:05:46,640
we're at the moment, so score for example or this which refers to the overall class where we can therefore
72
00:05:46,640 --> 00:05:54,500
inspect all our properties of that class, bunch of internal properties managed by Flutter but then also
73
00:05:54,500 --> 00:06:01,280
for example our _questions or our question index property and with these tools, you should
74
00:06:01,280 --> 00:06:07,130
have everything to deeply analyze your code, what's going on there, what's changing, why it's changing and
75
00:06:07,130 --> 00:06:10,180
hopefully spot logical mistakes.
76
00:06:10,280 --> 00:06:14,450
Now if you're done, you can always press the play button and if you want to get rid of breakpoints, you
77
00:06:14,450 --> 00:06:18,940
simply click on them to clear them and now your code won't stop there anymore.
8654
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.