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?
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.
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,
),
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With