Change Global Default Font in Flutter App

Change Global Default Font in Flutter App

Here 3 steps to use the default custom font in Flutter apps.

1. Import the font files

Add your fonts to the assets folder.

Flutter supports the following font formats:

  • .ttf
  • .otf

Flutter does not support .woff and .woff2 fonts for all platforms.

2. Declare the font in the pubspec

Add the custom fonts in pubspec.yaml file. Each entry in this list should have a   “family” key with the font family name, and a “fonts” key with a  list giving the asset and other descriptors for the font. For  example:

fonts:
    - family: Jomolhari
      fonts:
        - asset: assets/fonts/Jomolhari.ttf
    - family: DDC_Uchen
      fonts:
        - asset: assets/fonts/DDC_Uchen/DDC_Uchen.ttf

3. Set a font as the default

To use a font as the default, set the fontFamily property as part of the app’s theme. The value provided to fontFamily must match the family a name declared in the pubspec.yaml. Your main method should look something like this:

void main() {
  runApp(
    MaterialApp(
      home: Splash(),
      debugShowCheckedModeBanner: false,
      title: '༼ཁ་ཐུན་གི་རིམ་པ་བཞུགས་སོ༽',
      theme: ThemeData(
        fontFamily: 'DDC_Uchen'
      ),
    ),
  );
}Code language: JavaScript (javascript)

Refer official document for more information.

Leave a Reply

Discover more from BHUTAN IO

Subscribe now to keep reading and get access to the full archive.

Continue reading

Scroll to Top