Let's update the previous recipe's code with some new fonts:
-
Open the pubspec.yaml file in the root folder of your project.
-
In the pubspec.yaml file, add the google_fonts package in the dependencies section, but be careful. YAML is one of the few languages where white space matters, so be sure to put the google_fonts dependency precisely under flutter, as shown here:
dependencies:
flutter:
sdk: flutter
google_fonts: ^2.0.0
-
After this is done, run flutter packages get to rebuild your asset bundle.
-
We can now add any Google font to the text widgets in text_layout.dart. Add the google_fonts import at the top of the file:
import 'package:google_fonts/google_fonts.dart';
- Update the first Text widget to reference the leckerliOne font:
Text(
'Hello, World!',
style: GoogleFonts.leckerliOne(fontSize: 40),
),
The leckerliOne font will now be rendered on the screen:
- Now you will...