A. pubspec.yaml syntax error due to missing indentation
B. Font file is missing from assets folder
C. Font family name in TextStyle does not match pubspec.yaml
D. Text widget cannot use custom fonts
Solution
Step 1: Check fontFamily spelling in Dart code
The Dart code uses 'FancyFontt' but pubspec.yaml declares 'FancyFont' (extra 't').
Step 2: Font family names must match exactly
Font family names are case-sensitive and must match exactly between pubspec.yaml and Dart code.
Final Answer:
Font family name in TextStyle does not match pubspec.yaml -> Option C
Quick Check:
Font family names must match exactly [OK]
Hint: Check spelling of fontFamily matches pubspec.yaml exactly [OK]
Common Mistakes:
Typos in font family names
Forgetting to run flutter pub get after changes
Incorrect indentation in pubspec.yaml
5. You want to use two different custom fonts in your Flutter app: 'Lobster' for titles and 'OpenSans' for body text. How should you organize your pubspec.yaml and Dart code to achieve this?
hard
A. Add both font files but use only one family name in pubspec.yaml
B. Declare both fonts under fonts in pubspec.yaml with different family names, then use fontFamily: 'Lobster' or 'OpenSans' in TextStyle accordingly
C. Declare only one font in pubspec.yaml and switch fontFamily names in Dart code
D. Use system fonts for titles and custom font for body text without declaring both
Solution
Step 1: Declare each font family separately in pubspec.yaml
You must list each font family with its own name and font files under the fonts section.
Step 2: Use fontFamily property in Dart code for each Text widget
Apply fontFamily: 'Lobster' for titles and fontFamily: 'OpenSans' for body text in TextStyle.
Final Answer:
Declare both fonts under fonts in pubspec.yaml with different family names, then use fontFamily: 'Lobster' or 'OpenSans' in TextStyle accordingly -> Option B
Quick Check:
Multiple fonts need separate declarations and usage [OK]
Hint: Declare each font family separately and use fontFamily accordingly [OK]
Common Mistakes:
Declaring only one font family for multiple fonts
Using wrong fontFamily names in Dart code
Not adding all font files to assets
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.