Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:02,140 --> 00:00:08,950
So we got our first lines of code that lead to this application which obviously is not the kind
2
00:00:08,950 --> 00:00:12,120
of application we would ship to an app store. Yet
3
00:00:12,130 --> 00:00:19,310
before we dive deeper into building a bit more beautiful of an application, let me briefly sum up what
4
00:00:19,310 --> 00:00:25,420
we learned thus far and yes, it's a repetition but it's so important and crucial that you understand
5
00:00:25,690 --> 00:00:28,130
how this works and what we did.
6
00:00:28,150 --> 00:00:34,060
So we have this main.dart file with the main function and this main function is automatically executed
7
00:00:34,270 --> 00:00:36,210
when our app launches,
8
00:00:36,280 --> 00:00:42,610
that is important. In there, we call run app which is a function provided by the Flutter team in the material.dart
9
00:00:42,610 --> 00:00:45,140
package which we are importing up here.
10
00:00:45,220 --> 00:00:51,340
We can import the Flutter package and there, the material file because we have the connection in the
11
00:00:51,340 --> 00:00:57,610
pubspec.yaml file. Later in the course, we will also add other third-party packages to add even more features which
12
00:00:57,610 --> 00:01:00,150
we don't have to build ourselves.
13
00:01:00,160 --> 00:01:06,040
So with that, we call runApp and runApp is a function which does all the heavy lifting behind the scenes
14
00:01:06,040 --> 00:01:13,450
to take a widget we created and draw it onto the screen, to be precise, what it in the end does is it
15
00:01:13,450 --> 00:01:18,890
calls the build method in our widget because and that's an important rule now,
16
00:01:19,060 --> 00:01:26,950
every widget in Flutter needs to extend stateless widget or stateful widget into which I'll dive later,
17
00:01:27,070 --> 00:01:32,620
so it needs to extend one of these two base widget classes and each of these classes will force you to
18
00:01:32,620 --> 00:01:38,980
add a build method because in the end, Flutter will always call that build method for you,
19
00:01:38,980 --> 00:01:44,580
so you don't call it, Flutter calls it when it is prompted to draw something onto the screen.
20
00:01:44,680 --> 00:01:50,290
runApp prompts Flutter or tells Flutter to draw something onto the screen and therefore Flutter will
21
00:01:50,500 --> 00:01:56,460
do a lot of stuff but also call the build method of the widget you pass to runApp.
22
00:01:57,280 --> 00:02:04,000
The build method is always responsible for returning a new widget which should be drawn onto the screen
23
00:02:04,480 --> 00:02:09,610
and therefore at some point of time, you have to end up with returning one of the base widgets
24
00:02:10,090 --> 00:02:16,480
Flutter ships with because these then will have the nitty-gritty details for really controlling the pixels
25
00:02:16,540 --> 00:02:22,320
so to say. Of course they do a bit more than that but in a nutshell, that is how you can think about that.
26
00:02:22,450 --> 00:02:27,150
So widgets need to return widgets and therefore at some point of time, you will end up returning these
27
00:02:27,150 --> 00:02:32,860
base widgets and in the end, you will build your entire user interface with these base widgets because
28
00:02:32,860 --> 00:02:38,800
there are base widgets for everything you could possibly want to build and you will learn how to work
29
00:02:38,800 --> 00:02:45,190
with them and how to find the right widget for which job, you will learn all of that throughout the course.
30
00:02:45,190 --> 00:02:52,600
Now the build method turns this context argument. Now since Flutter called build for you, it's Flutter's
31
00:02:52,600 --> 00:02:58,630
job to provide the value for context, so you don't have to worry about that, you only have to accept
32
00:02:58,630 --> 00:02:59,110
it here
33
00:02:59,110 --> 00:03:05,260
since you are writing that build method in this place here. Context as I mentioned will be an object of
34
00:03:05,260 --> 00:03:11,590
type build context, so using the build context blueprint which is also provided by Flutter, which holds
35
00:03:11,590 --> 00:03:19,390
some metadata about this widget, its position in the widget tree and your overall application so to say.
36
00:03:20,060 --> 00:03:29,410
This is what's happening here. Now in the MyApp widget build method here, we have the MaterialApp
37
00:03:29,440 --> 00:03:34,250
which I'm returning which in turn is a widget but now it's a widget provided by the Flutter team.
38
00:03:34,360 --> 00:03:40,600
This uses a named argument, home and as a value for this named argument, I pass yet another widget, the
39
00:03:40,600 --> 00:03:46,450
text widget which is also provided by the Flutter package and this uses a so-called positional argument.
40
00:03:46,720 --> 00:03:54,280
So both text and hello are arguments, text is an argument to MaterialApp for the home argument and hello
41
00:03:54,550 --> 00:03:56,790
is an argument to the text widget.
42
00:03:56,800 --> 00:04:04,060
Now both these widgets, MaterialApp and text, are in the end Dart classes, every widget is just a Dart
43
00:04:04,060 --> 00:04:06,450
class which in the end has a build method,
44
00:04:06,550 --> 00:04:09,110
that's something you can remember.
45
00:04:09,460 --> 00:04:10,960
This is what's happening here,
46
00:04:10,960 --> 00:04:16,060
it's also worth pointing out that by adding parentheses after your class name, like we're doing it here,
47
00:04:16,270 --> 00:04:22,090
we're instantiating that class so we're creating a concrete object of that class, here of the MyApp
48
00:04:22,090 --> 00:04:28,360
widget, we're creating an object of that and we're passing that to runApp which then passes it on to Flutter
49
00:04:28,480 --> 00:04:33,490
so to say and that is what in the end brings this here onto the screen.
50
00:04:33,490 --> 00:04:39,280
Now with all of that, we only touched on some of the core fundamentals of the Dart language of course,
51
00:04:39,280 --> 00:04:45,520
there is more than named arguments, variables methods and so on but we will learn all of that step-by-step
52
00:04:45,520 --> 00:04:48,640
and not upfront in front of the course,
53
00:04:48,670 --> 00:04:53,460
instead let's rather dive a bit deeper now and make sure that we see something more beautiful on the
54
00:04:53,460 --> 00:04:53,820
screen.
55
00:04:54,120 --> 00:05:00,820
However before we do that, there's one important annotation which I want to add to this build method
56
00:05:01,230 --> 00:05:03,510
and that is @Override.
57
00:05:03,730 --> 00:05:06,130
Now technically, that's not required,
58
00:05:06,130 --> 00:05:08,500
our app worked without that.
59
00:05:08,620 --> 00:05:14,950
This is a so-called decorator and it's a decorator, which you probably guessed it, is also provided
60
00:05:15,250 --> 00:05:21,760
by Dart and Flutter, so override is actually provided by Dart, not by Flutter but there are other decorators
61
00:05:21,760 --> 00:05:26,580
like that @required thing which I showed you earlier which would be provided by Flutter.
62
00:05:26,590 --> 00:05:28,630
Now what does this decorator thing do though,
63
00:05:28,630 --> 00:05:30,170
it worked without it?
64
00:05:30,190 --> 00:05:31,390
Yes, it works without it,
65
00:05:31,420 --> 00:05:38,500
it's just there to make our code a bit clearer and a bit cleaner.
66
00:05:38,530 --> 00:05:44,620
This makes it really clear that we are deliberately overriding the build method which is provided by
67
00:05:44,620 --> 00:05:45,420
stateless widget,
68
00:05:45,430 --> 00:05:51,310
it exists there but we override it with our own implementation and actually stateless widget forces
69
00:05:51,310 --> 00:05:52,530
us to override it,
70
00:05:52,540 --> 00:05:55,710
we don't have the option of not overriding it, nonetheless,
71
00:05:55,990 --> 00:05:59,770
this is basically a common practice and a good practice.
72
00:05:59,770 --> 00:06:06,100
If you provide a method, which also existed in a class you're extending, then you should add @Override
73
00:06:06,100 --> 00:06:12,010
to make it clear that you are not accidentally overwriting this already existing method but deliberately
74
00:06:12,340 --> 00:06:17,900
because when you add your build method here and stateless widget also had one, then the one of stateless
75
00:06:17,900 --> 00:06:22,960
widget will not be considered for my app but your own one will and that is absolutely something
76
00:06:22,960 --> 00:06:23,800
you have to do here.
77
00:06:23,800 --> 00:06:29,110
It's not an error, you want to do that, you just want to be clear that this was done deliberately. So it's
78
00:06:29,110 --> 00:06:33,880
a tiny, stylistic thing, still something which we'll see throughout the course and which I therefore want to
79
00:06:33,880 --> 00:06:36,660
mention here. And there's one other thing you will see,
80
00:06:36,660 --> 00:06:42,940
for example when you create a new Flutter app. Instead of the main function looking like this, you also
81
00:06:43,360 --> 00:06:46,810
can see something that looks like this,
82
00:06:46,810 --> 00:06:52,420
you have void main, then you have your parentheses, so that's the same as we have it up here but then
83
00:06:52,420 --> 00:06:56,100
instead of curly braces, you have an equals sign and a greater sign,
84
00:06:56,260 --> 00:06:58,870
so an arrow kind of
85
00:06:58,990 --> 00:07:01,570
and then you have runApp MyApp.
86
00:07:02,200 --> 00:07:08,800
So what we had between the curly braces now comes after this arrow without curly braces and that is
87
00:07:08,800 --> 00:07:10,750
valid Dart syntax too,
88
00:07:10,840 --> 00:07:18,430
it's a shorthand for functions which only have one and exactly one expression, so only one line of code
89
00:07:18,430 --> 00:07:19,390
in the function,
90
00:07:19,390 --> 00:07:25,450
then you can omit the curly braces and instead add such an arrow here, which tells Dart this is a
91
00:07:25,450 --> 00:07:27,420
function with only one expression
92
00:07:27,460 --> 00:07:29,230
and this here is the expression,
93
00:07:29,230 --> 00:07:30,020
please execute,
94
00:07:30,020 --> 00:07:31,250
there is nothing else
95
00:07:31,330 --> 00:07:37,540
and the result of this expression here will then also automatically be returned.
96
00:07:37,560 --> 00:07:42,640
Now here, runApp doesn't return anything and therefore our overall function does not return anything
97
00:07:42,910 --> 00:07:45,960
but if runApp would return a value,
98
00:07:46,060 --> 00:07:49,750
then this would automatically be returned by our function here as well.
99
00:07:49,840 --> 00:07:54,910
You can use that for any function with one expression where you then want to execute that expression.
100
00:07:55,330 --> 00:08:00,610
So this is just an alternative syntax to that and it's just something I want to get out of the way here
101
00:08:00,760 --> 00:08:03,040
so that it's clear what this does
102
00:08:03,040 --> 00:08:03,910
if you see that.
103
00:08:04,090 --> 00:08:08,440
But with that, let's now make sure we have a bit of a more beautiful app on the screen.
11697
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.