Fonts
Sprout's designer picked a friendly rounded typeface and sent two files: a regular and a bold. Dropping them into the project is not enough. Flutter needs to know that both files belong to one family, and which one is the bold.
The rule
One family, one file per weight, one name in the theme.
flutter:
fonts:
- family: Nunito
fonts:
- asset: fonts/Nunito-Regular.ttf
- asset: fonts/Nunito-Bold.ttf
weight: 700
- asset: fonts/Nunito-Italic.ttf
style: italicfamilyis the name your code will use. It does not have to match the file names.- Each file is one variation.
weightis a number from 100 to 900 in steps of 100 (400 is regular, 700 is bold).style: italicmarks an italic file. - A file with no
weightcounts as regular (400).
Apply it to one piece of text:
Text('Sprout', style: TextStyle(fontFamily: 'Nunito', fontWeight: FontWeight.bold))or, far more often, to the whole app:
MaterialApp(theme: ThemeData(fontFamily: 'Nunito'), home: const SproutHome())When a Text asks for FontWeight.bold, Flutter looks in the Nunito family for the file declared with weight 700. If there is none, it uses the closest weight it has, and bold may look faked or not bold at all.
An alternative is the google_fonts package, which fetches fonts by name at run time or bundles them. Declaring files yourself keeps everything offline and under your control.