【问题标题】:why TextTheme doesn't change AppBar TextStyle?为什么TextTheme不会改变AppBar TextStyle?
【发布时间】:2020-10-04 07:00:45
【问题描述】:

return MaterialApp(
  theme: ThemeData.dark().copyWith(
    textTheme: GoogleFonts.dancingScriptTextTheme(
        Theme.of(context).textTheme,),
),

如您所见,我在 Flutter 应用程序中使用了 danceScriptTextTheme。但是使用这个 textTheme 只会改变应用程序主体中的 textSytle。如屏幕截图所示,AppBar 中的字体不受影响。如何更改 appBar 的字体?详细解释一下。

【问题讨论】:

  • Appbar有自己的文本主题,试试在copyWith方法中添加appBarTheme: AppBarTheme(textTheme: //你想要的textTheme)

标签: android android-studio flutter visual-studio-code flutter-text


【解决方案1】:

如果你想将它应用到 AppBar,你应该在 AppBar 自己的 textTheme 上定义文本主题,如下所示:

MaterialApp(
    theme: ThemeData.dark().copyWith(
      textTheme: GoogleFonts.dancingScriptTextTheme(
        Theme.of(context).textTheme,
      ),
    ),
    home: Scaffold(
      appBar: AppBar(
        textTheme: GoogleFonts.dancingScriptTextTheme(
          Theme.of(context).textTheme,
        ),
      ),
    ));

【讨论】:

    猜你喜欢
    • 2021-10-19
    • 2019-10-07
    • 2021-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-29
    • 2016-05-27
    • 1970-01-01
    相关资源
    最近更新 更多