flutter font code example

Example 1: flutter fonts

flutter:
  fonts:
    - family: Raleway
      fonts:
        - asset: fonts/Raleway-Regular.ttf
        - asset: fonts/Raleway-Italic.ttf
          style: italic
    - family: RobotoMono
      fonts:
        - asset: fonts/RobotoMono-Regular.ttf
        - asset: fonts/RobotoMono-Bold.ttf
          weight: 700

Example 2: how to set font family in flutter

MaterialApp(
  title: 'Custom Fonts',
  // Set Raleway as the default app font.
  theme: ThemeData(fontFamily: 'Raleway'),
  home: MyHomePage(),
);

Example 3: add font in flutter

MaterialApp(
  title: 'Fonts',
  theme: ThemeData(fontFamily: 'Mukta'),
  home: HomePage(),
);
 
 In pubspec.yaml
 fonts:
    - family: Mukta
      fonts:
        - asset: assets/fonts/Mukta/Mukta-Regular.ttf
          weight: 400

Example 4: flutter font family

final String? fontFamily;

Tags:

Dart Example