How to use GoogleFonts as default fonts in flutter app?

Viewed 6384

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?

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,
      ),
  );
Related