0
0
Fluttermobile~20 mins

Custom fonts in Flutter - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Custom Fonts Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ui_behavior
intermediate
2:00remaining
What is the output of this Flutter code snippet using a custom font?

Given the following Flutter widget, what font family will the displayed text use?

Flutter
Text('Hello Flutter', style: TextStyle(fontFamily: 'MyCustomFont'))
AThe text uses the system default font.
BThe text will not display because 'MyCustomFont' is not a valid font family name.
CThe text uses the 'MyCustomFont' font family if properly registered.
DThe text uses a random font from the device.
Attempts:
2 left
💡 Hint

Custom fonts must be registered in the pubspec.yaml file before use.

📝 Syntax
intermediate
2:00remaining
Which pubspec.yaml snippet correctly registers a custom font named 'MyCustomFont'?

Choose the correct way to declare a custom font in pubspec.yaml.

A
flutter:
  fonts:
    - family: MyCustomFont
      fonts:
        - asset: fonts/MyCustomFont.ttf
B
flutter:
  assets:
    - fonts/MyCustomFont.ttf
C
fonts:
  - family: MyCustomFont
    asset: fonts/MyCustomFont.ttf
D
flutter:
  fonts:
    - family: MyCustomFont
      asset: fonts/MyCustomFont.ttf
Attempts:
2 left
💡 Hint

Look for the correct indentation and keys under flutter.

lifecycle
advanced
2:00remaining
What happens if you add a new font asset but forget to run 'flutter pub get' before running the app?

Consider you added a new font file and updated pubspec.yaml but did not run 'flutter pub get'. What will happen when you run the app?

AThe app will display the new font correctly without any issues.
BThe app will use the default font instead of the new custom font.
CThe app will crash immediately on startup.
DThe app will show a compile-time error.
Attempts:
2 left
💡 Hint

Think about how Flutter updates dependencies and assets.

🔧 Debug
advanced
2:00remaining
Why does this Flutter app fail to apply the custom font?

Given this pubspec.yaml snippet and Flutter code, why does the custom font not appear?

flutter:
  fonts:
    - family: MyFont
      fonts:
        - asset: fonts/MyFont-Regular.ttf

Text('Sample', style: TextStyle(fontFamily: 'MyCustomFont'))
AThe Text widget does not support custom fonts.
BThe font asset path is incorrect in pubspec.yaml.
CThe font file is missing from the fonts folder.
DThe font family name in TextStyle does not match the one declared in pubspec.yaml.
Attempts:
2 left
💡 Hint

Check the font family names carefully.

🧠 Conceptual
expert
3:00remaining
How does Flutter handle font weight variations in custom fonts?

You have multiple font files for different weights (e.g., Regular, Bold) under the same family. How should you declare them in pubspec.yaml to enable Flutter to use them automatically?

ADeclare each font file under the same family with the 'weight' property specifying the font weight.
BDeclare only the Regular font file; Flutter will simulate other weights automatically.
CFlutter does not support multiple weights for custom fonts.
DDeclare each font file under different family names for each weight.
Attempts:
2 left
💡 Hint

Look for how pubspec.yaml supports font weight declarations.