如何在flutter应用程序中使用GoogleFonts作为默认字体?

Ama*_*wat 11 dart flutter

我在我的 flutter 应用程序中使用 GoogleFonts api,但现在我将每个文本的 fontStyle 手动设置为 GoogleFonts.roberto,但我想在 main.dart 的 ThemeData 中将其设置为默认值。但是 fontFamily: GoogleFonts.roberto 抛出一个错误,指出需要一个字符串值,那么我该如何实现呢?

Aki*_*kif 18

您可以像这样使用它来制作或修改整个文本主题以使用其官方文档中提到的“Roboto”字体:

  MaterialApp(
     theme:ThemeData(
       textTheme: GoogleFonts.robotoTextTheme(
           Theme.of(context).textTheme,
      ),
  );
Run Code Online (Sandbox Code Playgroud)