Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
0
1
00:00:00,510 --> 00:00:08,490
Now in the original mock-up of our design, we wanted to have a nice fancy font for the part where we display
1
2
00:00:08,490 --> 00:00:09,840
our name.
2
3
00:00:09,840 --> 00:00:14,280
Now, how do we add a custom font to our project?
3
4
00:00:14,280 --> 00:00:20,640
Well, the first part is of course, downloading and getting hold of a font. And the easiest way of doing
4
5
00:00:20,640 --> 00:00:24,570
that, is simply heading to fonts.google.com.
5
6
00:00:25,380 --> 00:00:31,440
And the reason why is because all of these fonts here are free for commercial use.
6
7
00:00:31,500 --> 00:00:37,560
So no matter where you're using it, on a website or of course in your Flutter app, you can use it without
7
8
00:00:37,560 --> 00:00:41,640
fear that somebody will come after you because of copyrighting.
8
9
00:00:41,640 --> 00:00:48,900
So now, you get to look through all of these fonts around 900 of them, and decide which one do I like,
9
10
00:00:48,900 --> 00:00:56,190
what looks nice to me. Or if you're more of a designer, and you know exactly what kind of category you're
10
11
00:00:56,190 --> 00:01:03,840
looking, for say a display type of font, then you can uncheck all the other ones and find the one that
11
12
00:01:03,840 --> 00:01:04,810
you want.
12
13
00:01:04,920 --> 00:01:08,990
Now the one that I'm going to use is something called Pacifico.
13
14
00:01:09,150 --> 00:01:16,020
And this is a font that looks a bit like handwriting. And it looks really pretty, especially when it's
14
15
00:01:16,020 --> 00:01:20,490
contrasted with a normal sort of sans serif font.
15
16
00:01:20,520 --> 00:01:22,480
So this is exactly what we're going to do.
16
17
00:01:22,560 --> 00:01:27,770
And in order to download it, we're going to select this font, and we're going to hit the download button.
17
18
00:01:30,020 --> 00:01:30,580
Now,
18
19
00:01:30,600 --> 00:01:38,400
we have a zip file, and once you unzip it, then you can see that here's the font the .ttf file format.
19
20
00:01:38,400 --> 00:01:46,390
And here is the license that allows you to use it for commercial use. In order to add this to our project,
20
21
00:01:46,410 --> 00:01:50,850
we're gonna do a little bit more dragging and dropping. Again inside my project,
21
22
00:01:50,850 --> 00:01:58,200
I'm going to create a new directory called fonts, and here if I have more than one font, I'm going to
22
23
00:01:58,290 --> 00:02:00,250
drop them all in here.
23
24
00:02:00,250 --> 00:02:05,390
So I'm going to drag my Pacifico, and drop it into fonts, and hit OK.
24
25
00:02:05,730 --> 00:02:07,430
And we're going to add the file to git as well.
25
26
00:02:08,040 --> 00:02:11,800
And you can see that in the preview, it shows us what this font looks like.
26
27
00:02:11,810 --> 00:02:19,020
It looks pretty beautiful, and we're gonna use it to reformat our font for our text widget here.
27
28
00:02:19,020 --> 00:02:22,590
So again, we have to go into our pubspec.yaml
28
29
00:02:22,840 --> 00:02:32,340
and in addition to assets, we're also going to have some fonts. Now, previously before we deleted all the
29
30
00:02:32,340 --> 00:02:38,880
comments, you might remember that there was a comment about how to add custom fonts. And they even point
30
31
00:02:38,880 --> 00:02:45,570
you towards a part of the documentation where it talks about how to use custom fonts. So if you head
31
32
00:02:45,570 --> 00:02:50,790
over to this address, then you can see that it takes you to this page that tells you all about how you
32
33
00:02:50,790 --> 00:02:54,050
can use custom fonts in your project.
33
34
00:02:54,210 --> 00:03:00,180
And we've already imported our font files, so now all we have to do, is declare the font in the pubspec
34
35
00:03:00,180 --> 00:03:01,090
.yaml
35
36
00:03:01,500 --> 00:03:06,570
And the reason why I'm taking you over here is because, the yaml file indentation is super important
36
37
00:03:06,690 --> 00:03:08,700
and it's really easy to get it wrong.
37
38
00:03:08,730 --> 00:03:14,220
So instead, what I recommend is just to simply copy all the parts that you need.
38
39
00:03:14,250 --> 00:03:18,630
We've already got the part that says Flutter, because we already have some assets in it. And then we're
39
40
00:03:18,630 --> 00:03:25,180
going to hit a copy, and we're going to go back and we're going to paste it, right underneath here.
40
41
00:03:25,200 --> 00:03:32,460
So now you can see our fonts is indented by two spaces from our Flutter settings, and then inside our
41
42
00:03:32,460 --> 00:03:40,140
fonts, we've got our font family and we've got our fonts, and we've got our font asset. So now all we need
42
43
00:03:40,140 --> 00:03:47,240
to do is to change the family to the name of our font family, which in this case is Pacifico. And then
43
44
00:03:47,240 --> 00:03:52,380
we're going to change the location of our asset which is inside a folder called font,
44
45
00:03:52,520 --> 00:03:55,590
and it's called Pacifico-regular.ttf
45
46
00:03:56,120 --> 00:04:03,920
So I can change this word Pacifico, and that's all we need to do. And this is more of a foolproof way
46
47
00:04:04,280 --> 00:04:09,850
of getting our fonts loaded up into our project. And we run package.get,
47
48
00:04:09,950 --> 00:04:12,690
you should see that everything in here is black and white.
48
49
00:04:12,830 --> 00:04:18,770
But if we had an indentation issue, then when we run this, you might get some errors like this telling
49
50
00:04:18,770 --> 00:04:23,500
you that this part here, where it says fonts, it's not what it expected.
50
51
00:04:23,510 --> 00:04:25,550
So indentation matters a lot,
51
52
00:04:25,550 --> 00:04:30,200
and the easiest way of getting this right is to actually just copy it from the source.
52
53
00:04:30,230 --> 00:04:32,600
This makes it so much less error prone.
53
54
00:04:32,690 --> 00:04:39,440
So now that we've got our Pacifico font loaded into our project, from now on we can refer to it
54
55
00:04:39,560 --> 00:04:41,830
by this name that we specify here.
55
56
00:04:42,050 --> 00:04:45,020
So the Pacifico font family.
56
57
00:04:45,260 --> 00:04:53,180
So let's go back into our main.dart, and for the style property of our text, we're going to also update
57
58
00:04:53,270 --> 00:04:55,910
its font family.
58
59
00:04:55,940 --> 00:05:02,480
And here, we can specify the name that we typed into the pubspec file, which was Pacifico, with a capital
59
60
00:05:02,480 --> 00:05:03,490
P.
60
61
00:05:03,590 --> 00:05:10,540
And now that I've added in our new resource, we actually have to rebuild our project from cold,
61
62
00:05:10,580 --> 00:05:16,910
so I had to hit stop, and then hit play so that it links up all the necessary things that we need.
62
63
00:05:20,120 --> 00:05:24,790
And you can see that our new font gets added in and it looks great.
63
64
00:05:24,800 --> 00:05:29,570
It looks a lot better than the default font that we had to begin with.
64
65
00:05:29,600 --> 00:05:36,680
So now as a challenge, I want you to apply what you just learned, and create the next part of our user
65
66
00:05:36,680 --> 00:05:42,820
interface, which is a piece of text still in our column, that describes your role.
66
67
00:05:42,830 --> 00:05:49,910
So it could be Flutter developer, project manager, product manager, designer, whatever it may be. But you're
67
68
00:05:49,910 --> 00:05:58,730
going to make it all caps, and you're going to change the font to something called Source Sans Pro, and
68
69
00:05:58,730 --> 00:06:01,080
you'll find it on Google fonts.
69
70
00:06:01,340 --> 00:06:07,820
Try and pause the video and apply those changes so that we can update the next part of our business
70
71
00:06:07,820 --> 00:06:10,540
card.
71
72
00:06:10,640 --> 00:06:10,920
All right.
72
73
00:06:10,940 --> 00:06:13,710
So we're just going to do exactly what we did previously.
73
74
00:06:13,710 --> 00:06:19,830
We're going to add our Source Sans Pro to our selection, and then we're going to download it so that
74
75
00:06:19,830 --> 00:06:26,580
we have access to it locally. And then we're going to unzip that file. Once you've extracted it and you
75
76
00:06:26,580 --> 00:06:28,800
can see all the different types.
76
77
00:06:28,800 --> 00:06:34,650
We're actually just going to drag in the source sans pro regular, and we're going to drop it into our fonts
77
78
00:06:34,650 --> 00:06:40,140
folder. And then we're going to click OK to move it, and we'll be able to see an excerpt of what it
78
79
00:06:40,140 --> 00:06:41,350
looks like.
79
80
00:06:41,370 --> 00:06:48,930
So now we can go into our pubspec.yaml, and we can copy what we did for the Pacifico font family,
80
81
00:06:49,470 --> 00:06:51,930
and we can paste it right below,
81
82
00:06:52,380 --> 00:06:59,380
but at the same indentation level where the family is. So now, essentially what we're saying is that the
82
83
00:06:59,390 --> 00:07:04,560
custom fonts that we want to use in our Flutter app, there are two families.
83
84
00:07:04,560 --> 00:07:05,870
One is Pacifico,
84
85
00:07:06,060 --> 00:07:09,480
and the other is going to be Source Sans Pro.
85
86
00:07:10,260 --> 00:07:17,610
And we can change the asset location to SourceSansPro-regular and just check to make sure it's
86
87
00:07:17,610 --> 00:07:19,420
the same spelling.
87
88
00:07:19,500 --> 00:07:26,340
And now if we go ahead and click on packages.get, we'll be able to pull in those files to use in
88
89
00:07:26,400 --> 00:07:30,790
our main.dart. Right below our previous text widget,
89
90
00:07:30,790 --> 00:07:37,750
we're going to add our next text widget, and this one is simply going to say your job title.
90
91
00:07:37,780 --> 00:07:44,890
So it could be, I don't know, Flutter developer, or it could be designer, whatever it may be.
91
92
00:07:45,280 --> 00:07:53,470
And then we're going to set the style to a text style that uses the font family that we named just now,
92
93
00:07:53,500 --> 00:08:01,600
which was called Source Sans Pro. And it's really important that this part has to match exactly what
93
94
00:08:01,600 --> 00:08:02,680
you wrote here,
94
95
00:08:02,710 --> 00:08:06,700
so including all the spaces and the upper and lower casing.
95
96
00:08:07,360 --> 00:08:15,220
So you're essentially referring to something inside the fonts with a family name of Source Sans Pro.
96
97
00:08:15,220 --> 00:08:20,920
And by linking it up previously, we already told it that this is where that font resides and where
97
98
00:08:20,920 --> 00:08:22,590
it should look to.
98
99
00:08:22,720 --> 00:08:29,180
Now that we've added in our font family, the rest of it is really up to you how you want to style it.
99
100
00:08:29,230 --> 00:08:36,610
Personally for me, I'm going to change the color to a light teal. So I'm going to go into colors, and
100
101
00:08:36,610 --> 00:08:42,280
then I'm going to go into teal, and then I'm going to specify maybe the 100 shade.
101
102
00:08:42,310 --> 00:08:46,090
Now you might have noticed that there's lots of ways that you can do this.
102
103
00:08:46,090 --> 00:08:54,070
So when I write teal, and my little doc popsup, you can see that there's teal from 50 all the way down
103
104
00:08:54,070 --> 00:09:00,930
to all the way down to 900. And that's kind of the dark or deepness of the shade.
104
105
00:09:01,390 --> 00:09:07,860
But instead of adding in the square brackets, I can also just write a dot, and specify my shade. As in,
105
106
00:09:07,860 --> 00:09:13,020
if I want shade 100, then I can just simply do that.
106
107
00:09:13,180 --> 00:09:18,390
So this is what we've got so far, and the font a little bit too small for my eyes.
107
108
00:09:18,400 --> 00:09:21,510
I think I'm getting a bit old. I can't actually see it that well.
108
109
00:09:21,670 --> 00:09:26,740
So I'm going to increase the font size to maybe a 20 point size.
109
110
00:09:27,010 --> 00:09:30,940
And I'm also going to change something called letter spacing.
110
111
00:09:31,030 --> 00:09:36,100
So this property will determine how much space there is between each of the letters in the word.
111
112
00:09:36,100 --> 00:09:38,460
And I'm going to say maybe 2.5.
112
113
00:09:38,560 --> 00:09:44,440
So a lot of these things you can have a play around with it and see how it looks to you.
113
114
00:09:44,440 --> 00:09:49,750
I think one last thing that I would do to this is I would probably make the font weight bold.
114
115
00:09:52,690 --> 00:09:58,350
And that will probably make it look just how I would like it.
115
116
00:09:58,450 --> 00:10:00,370
The styling is of course up to you.
116
117
00:10:00,500 --> 00:10:06,580
But this lesson is all about making sure that you've understood how to incorporate custom fonts into
117
118
00:10:06,610 --> 00:10:14,830
your Flutter app, and how we can use the pubspec to specify what are font is called, and where it is
118
119
00:10:14,830 --> 00:10:19,640
located inside our project. And then using packages.get to grab it.
119
120
00:10:19,640 --> 00:10:26,620
Now if you had any problem with indentation, be sure to take a look at this file over here and just notice
120
121
00:10:26,620 --> 00:10:33,370
that every single indent is actually two spaces, and it's two spaces from the left, and it's two spaces
121
122
00:10:33,370 --> 00:10:35,050
for every child.
122
123
00:10:35,080 --> 00:10:36,610
Now this is really important.
123
124
00:10:36,670 --> 00:10:40,940
So if you have any errors when you run it, this is the first thing to check.
124
125
00:10:41,260 --> 00:10:47,470
I'll include this file as a download for this lesson, just in case you mess up all the indentations and
125
126
00:10:47,470 --> 00:10:50,660
you just want a quick way of fixing it. In the next lesson,
126
127
00:10:50,660 --> 00:10:56,530
we're going to be looking at how we can add icons that are already made and ready to go, into our app.
127
128
00:10:56,530 --> 00:10:59,320
So for all of that and more, I see on the next lesson.
14850
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.