我是Flutter的新手。
我安装了这个库以便使用Google字体。
现在我需要在主题数据定义中使用它,并尝试像这样做,但不被允许。
ThemeData appTheme() {
return ThemeData(
...
fontFamily: GoogleFonts.openSans(),
);
}
我该怎么做?非常感谢。
我是Flutter的新手。
我安装了这个库以便使用Google字体。
现在我需要在主题数据定义中使用它,并尝试像这样做,但不被允许。
ThemeData appTheme() {
return ThemeData(
...
fontFamily: GoogleFonts.openSans(),
);
}
我该怎么做?非常感谢。
我重新发表我的评论:fontFamily
需要一个String
类型的参数。使用GoogleFonts.openSans().fontFamily
。
final TextTheme textTheme = TextTheme(
headline1: GoogleFonts.roboto(
fontSize: 97, fontWeight: FontWeight.w300, letterSpacing: -1.5),
headline2: GoogleFonts.roboto(
fontSize: 61, fontWeight: FontWeight.w300, letterSpacing: -0.5),
headline3: GoogleFonts.roboto(fontSize: 48, fontWeight: FontWeight.w400),
headline4: GoogleFonts.roboto(
fontSize: 34, fontWeight: FontWeight.w400, letterSpacing: 0.25),
headline5: GoogleFonts.roboto(fontSize: 24, fontWeight: FontWeight.w400),
headline6: GoogleFonts.roboto(
fontSize: 20, fontWeight: FontWeight.w500, letterSpacing: 0.15),
subtitle1: GoogleFonts.roboto(
fontSize: 16, fontWeight: FontWeight.w400, letterSpacing: 0.15),
subtitle2: GoogleFonts.roboto(
fontSize: 14, fontWeight: FontWeight.w500, letterSpacing: 0.1),
bodyText1: GoogleFonts.roboto(
fontSize: 16, fontWeight: FontWeight.w400, letterSpacing: 0.5),
bodyText2: GoogleFonts.roboto(
fontSize: 14, fontWeight: FontWeight.w400, letterSpacing: 0.25),
button: GoogleFonts.roboto(
fontSize: 14, fontWeight: FontWeight.w500, letterSpacing: 1.25),
caption: GoogleFonts.roboto(
fontSize: 12, fontWeight: FontWeight.w400, letterSpacing: 0.4),
overline: GoogleFonts.roboto(
fontSize: 10, fontWeight: FontWeight.w400, letterSpacing: 1.5),
);
这个视频很好地解释了如何在Flutter中使用主题和字体https://youtu.be/stoJpMeS5aY?t=640
return MaterialApp( theme:ThemeData(textTheme: GoogleFonts.robotoTextTheme()));
fontFamily 期望一个字符串。使用 GoogleFonts.openSans().fontFamily
fontFamily
需要一个字符串。使用GoogleFonts.openSans().fontFamily
。 - Riwen