Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use GoogleFonts as default fonts in flutter app?

Tags:

flutter

dart

I'm using GoogleFonts api in my flutter app but right now I am setting the fontStyle for every text manually to GoogleFonts.roberto but I want to set that as default in ThemeData in main.dart. But the fontFamily: GoogleFonts.roberto throws an error saying expected an string value so how can I achive that?

like image 415
Aman Rawat Avatar asked Oct 21 '20 20:10

Aman Rawat


People also ask

How do you add a TTF font to Flutter?

Importing font files in a project After downloading, we need to add the font files to our Flutter project. Create a folder named fonts in the root of the Flutter project. Next, move the Montserrat font files or . ttf files into the fonts folder that you just created.


1 Answers

You can use it like this to make or modify an entire text theme to use the "Roboto" font as mentioned in their official document:

  MaterialApp(
     theme:ThemeData(
       textTheme: GoogleFonts.robotoTextTheme(
           Theme.of(context).textTheme,
      ),
  );
like image 63
Akif Avatar answered Nov 08 '22 00:11

Akif