Hussein Al-Mosawi
Hussein Al-Mosawi

Reputation: 1674

How to change the default font family in Flutter

How can I change every text of my app to use a specific font? I can change them individually by using the TextStyle() but how can I make my app default to a specific font? Can you show me how?

Upvotes: 81

Views: 162292

Answers (4)

ינון רחמים
ינון רחמים

Reputation: 706

For me it worked with all text widgets just when I wrote it twice -

ThemeData(
   fontFamily: 'Varela',             // <-- 1
   textTheme: Theme.of(context)
      .textTheme
      .apply(fontFamily: 'Varela'),  // <-- 2
),

Upvotes: 6

Rohan Arora
Rohan Arora

Reputation: 531

add google fonts to pubspec.yaml

dependencies:
  google_fonts: ^2.1.0 

use fontFamily function

MaterialApp(
  theme: ThemeData(
    fontFamily: GoogleFonts.lato().fontFamily,
  ),
);

remember to import google fonts

import 'package:google_fonts/google_fonts.dart';

Upvotes: 15

Mahesh Jamdade
Mahesh Jamdade

Reputation: 20221

If you want to use one of these Google fonts then use the official google_fonts package from the material team.

  • add to pubspec.yaml
dependencies:
  google_fonts: ^2.1.0 
  • Override the default font like this
MaterialApp(
  theme: ThemeData(
    textTheme: GoogleFonts.latoTextTheme(
      Theme.of(context).textTheme,
    ),
  ),
);

Upvotes: 57

OMi Shah
OMi Shah

Reputation: 6186

You can change the default font family of your Flutter app by following the below steps:

1. Add your font files into your project folder. Say Project Folder > assets > fonts > hind.

2. Declare the font family with font files with style in your project's pubspec.yaml file as (An example):

enter image description here

  1. In the MaterialApp widget of your main class file, define the default font family as:

enter image description here

Upvotes: 120

Related Questions