Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,790 --> 00:00:05,290
In the last section, we started talking about how we can reference a widget that has been created by
2
00:00:05,290 --> 00:00:10,250
creating a global key and kind of pointing that global key at the widget that we are making.
3
00:00:10,720 --> 00:00:14,780
So this global key thing is how we kind of maintain a reference to widget that's been created.
4
00:00:15,430 --> 00:00:19,570
So I think that part we kind of understand I've repeated that phrase like four times now in the last
5
00:00:19,570 --> 00:00:19,960
two minutes.
6
00:00:19,960 --> 00:00:21,190
So we get that idea.
7
00:00:21,580 --> 00:00:26,110
So now we're going to pivot just a little bit and we're going to talk about why using a global key with
8
00:00:26,110 --> 00:00:30,070
specifically a form is going to be just a little bit complicated.
9
00:00:30,730 --> 00:00:33,460
So we're going to pivot and we're going to talk about the form for just a minute.
10
00:00:33,730 --> 00:00:36,130
And we're going to bring back in this idea of the global key.
11
00:00:36,580 --> 00:00:36,990
All right.
12
00:00:37,000 --> 00:00:37,480
So here we go.
13
00:00:37,870 --> 00:00:39,770
So now we're talking about the form itself.
14
00:00:40,600 --> 00:00:47,380
So whenever a user sees this form on the screen and specifically like our form widget and the text field
15
00:00:47,380 --> 00:00:52,390
widgets that are displayed inside of it, we get this kind of flow of interaction that's displayed here
16
00:00:52,390 --> 00:00:53,150
on the right hand side.
17
00:00:53,770 --> 00:00:55,720
So a user focuses this input.
18
00:00:56,200 --> 00:01:00,160
They then type some data in and then this series of action occurs.
19
00:01:00,340 --> 00:01:06,960
So first off, the user types in some data that clearly is changing some data inside of our application,
20
00:01:07,360 --> 00:01:11,260
it is changing the value that is associated with this input right here.
21
00:01:12,070 --> 00:01:15,490
And it appears that any time that data changes.
22
00:01:16,740 --> 00:01:23,160
Our form widget, or perhaps would be better to say the text form field is clearly rendering itself
23
00:01:23,160 --> 00:01:28,330
on the screen with that new data, the new net, new data being the text that the user typed in here.
24
00:01:28,860 --> 00:01:32,070
In other words, when I select this input right here.
25
00:01:33,320 --> 00:01:38,420
And I start typing stuff in I see that data up here within that widget right there.
26
00:01:39,140 --> 00:01:44,990
So clearly whenever I change the data of this little widget, it is re rendering this widget on the
27
00:01:44,990 --> 00:01:45,920
screen of my device.
28
00:01:46,340 --> 00:01:47,660
So now here's my question to you.
29
00:01:48,230 --> 00:01:51,740
Does that process remind you of anything that we've spoken about so far?
30
00:01:52,460 --> 00:01:56,960
So we're clearly saying here that if we change data, it renders our widget on the screen of our device.
31
00:01:56,990 --> 00:01:59,730
So, again, does that remind you of anything that we've been discussing?
32
00:02:00,470 --> 00:02:04,400
Well, it might remind you of how a stateful widget behaves.
33
00:02:04,820 --> 00:02:10,039
Remember, we use a stateful widget when we want to have some data that's going to change over time.
34
00:02:10,370 --> 00:02:14,450
And each time that data changes, we want to render the widget on the screen of the device.
35
00:02:15,140 --> 00:02:16,640
So here is why.
36
00:02:18,060 --> 00:02:24,240
Our global key stuff right here is going to be a little bit complicated with our form widget, it's
37
00:02:24,240 --> 00:02:29,830
complicated because our form widget right here is actually a stateful widget.
38
00:02:30,540 --> 00:02:32,810
The format here, it's actually a stateful widget.
39
00:02:32,820 --> 00:02:34,800
It's not statelets, it's stateful.
40
00:02:35,340 --> 00:02:38,680
And so our widget hierarchy actually looks like this.
41
00:02:39,270 --> 00:02:41,490
This is what's actually going on behind the scenes.
42
00:02:42,550 --> 00:02:50,290
Whenever we create an instance of form, not only are we getting the kind of core form widget that renders
43
00:02:50,290 --> 00:02:55,930
something on the screen to the device, but it's also behind the scenes creating a form St. Instance,
44
00:02:56,530 --> 00:03:02,620
the same kind of class that is created by our login screen state right here, and some kind of mirroring
45
00:03:02,620 --> 00:03:03,430
that in the diagram.
46
00:03:03,640 --> 00:03:08,710
Remember, when we create a stateful widget, we get the kind of widget that represents our widget on
47
00:03:08,710 --> 00:03:12,820
the screen, the device or the class instance that represents our stuff on screen of the device.
48
00:03:13,330 --> 00:03:14,290
This widget right here.
49
00:03:14,320 --> 00:03:18,220
This class gets created and thrown away every time our application is rendered.
50
00:03:18,640 --> 00:03:23,920
But our login screen state over here is persisted to hold all the values that we've assigned to it and
51
00:03:23,920 --> 00:03:24,790
changed over time.
52
00:03:25,300 --> 00:03:27,790
And so the same thing is occurring with our form.
53
00:03:28,860 --> 00:03:35,490
That we've created we've got the core form, which over here that is responsible for showing information
54
00:03:35,490 --> 00:03:36,790
on the screen of the device.
55
00:03:37,290 --> 00:03:41,810
This form gets created and thrown away every time our application renders.
56
00:03:42,300 --> 00:03:49,500
But the actual values that are stored within our form are persisted with in this form state object.
57
00:03:50,430 --> 00:03:54,880
So that's why our situation is a little bit more complicated when it comes to that global key.
58
00:03:55,320 --> 00:04:00,750
We don't want to associate the global key with the form, the information that you and I care about,
59
00:04:00,930 --> 00:04:07,290
like the status of all those input fields and whether or not they are valid is actually stored with
60
00:04:07,290 --> 00:04:09,750
the form state, not the form.
61
00:04:10,680 --> 00:04:17,190
So in summary, what you and I really want to do here, we want to create a global key and we want to
62
00:04:17,190 --> 00:04:22,500
associate that global key with the form state, not the original form.
63
00:04:24,350 --> 00:04:28,910
Now, in practice, when we create this global key and pass it off to the form, we're going to write
64
00:04:28,910 --> 00:04:33,200
code that very clearly passes off that global key to the form.
65
00:04:33,380 --> 00:04:34,400
Like that's what we're going to write.
66
00:04:34,400 --> 00:04:39,440
We're going to create the global key and we're going to pass it off to this form instance right here.
67
00:04:39,800 --> 00:04:44,090
But I'm just telling you all this to let you know what is really going on behind the scenes when we
68
00:04:44,090 --> 00:04:49,910
create that global key and we pass it off to the form in in the end, the global key is actually going
69
00:04:49,910 --> 00:04:53,180
to reference this form state that is created for us.
70
00:04:54,290 --> 00:04:58,130
Now, that might not seem like a super relevant right now, but as soon as we create the global key
71
00:04:58,130 --> 00:05:00,980
and associate with the form, you'll see why it's relevant right away.
72
00:05:01,460 --> 00:05:04,880
OK, so all this stuff I know this is pretty heavy duty stuff.
73
00:05:04,880 --> 00:05:06,110
It's not the easy stuff in the world.
74
00:05:06,110 --> 00:05:07,630
But let's take a pause right here.
75
00:05:07,670 --> 00:05:08,900
We're going to come back the next section.
76
00:05:09,200 --> 00:05:13,220
We're going to make that global key and we're going to associate it with our form and then we'll be
77
00:05:13,220 --> 00:05:16,210
able to reference the form and call different methods that are on it.
78
00:05:16,490 --> 00:05:18,370
So quick break and I'll see you in just a minute.
8109
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.