我该如何将我的应用程序中的每个文本更改为使用特定的字体?我可以使用TextStyle()
逐个更改它们,但是如何使我的应用程序默认使用特定的字体?你能向我展示如何做吗?
我该如何将我的应用程序中的每个文本更改为使用特定的字体?我可以使用TextStyle()
逐个更改它们,但是如何使我的应用程序默认使用特定的字体?你能向我展示如何做吗?
如果你想使用这些Google字体,建议使用来自Material团队的官方google_fonts软件包。
dependencies:
google_fonts: ^2.1.0
MaterialApp(
theme: ThemeData(
textTheme: GoogleFonts.latoTextTheme(
Theme.of(context).textTheme,
),
),
);
在 pubspec.yaml 中添加 Google Fonts。
dependencies:
google_fonts: ^2.1.0
MaterialApp(
theme: ThemeData(
fontFamily: GoogleFonts.lato().fontFamily,
),
);
记得导入谷歌字体
import 'package:google_fonts/google_fonts.dart';
对我来说,只要我写两次,所有文本小部件都可以正常工作 -
ThemeData(
fontFamily: 'Varela', // <-- 1
textTheme: Theme.of(context)
.textTheme
.apply(fontFamily: 'Varela'), // <-- 2
),