【问题标题】:How to set textStyle of a Cupertino app in flutter如何在 Flutter 中设置 Cupertino 应用程序的 textStyle
【发布时间】:2020-02-04 21:28:55
【问题描述】:

我有一个 CupertinoApp,我想将自定义 TextStyle 应用于我的应用的所有屏幕/对象。例如,我会撒谎为所有 Text 小部件和 Dialog 小部件设置一个字体系列,并在我的所有应用程序中使用该字体。我希望在CupertinoThemeDataCupertinoTextThemeData 中设置一次,但到目前为止我还没有高兴。

注意:我可以为每个文本设置样式,但我想为所有设置一次

【问题讨论】:

  • 你解决了这个问题吗?

标签: flutter flutter-cupertino textstyle


【解决方案1】:

我刚刚遇到了这个问题。

我要做的只是将文本着色为白色,在整个应用程序中使用一般的黑色背景(不是字体工作)。

以下为我带来了一些成功:

return CupertinoApp(
  theme: new CupertinoThemeData(
    brightness: Brightness.dark,
    primaryColor: CupertinoColors.dark,
    barBackgroundColor: CupertinoColors.black,
    scaffoldBackgroundColor: CupertinoColors.black,
    textTheme: new CupertinoTextThemeData(
      primaryColor: CupertinoColors.white,
      brightness: Brightness.light,
      textStyle: TextStyle(color: CupertinoColors.white),
      // ... here I actually utilised all possible parameters in the constructor
      // as you can see in the link underneath
    ),
  ),
  // ...
)

参考:CupertinoTextThemeData Constructor

我想你也可以扩展我的TextStyle(color: CupertinoColors.white) 来应用字体。我打算将TextStyle...ThemeData 提取到单独的类中,以创建一个单独的位置来编辑它们。

希望这能提升你的地位

【讨论】:

    【解决方案2】:

    在您的 CupertinoApp 中使用此主题示例。

     theme: CupertinoThemeData(
            textTheme: CupertinoTextThemeData(
                textStyle: TextStyle(
                    fontSize: 14,
                    fontStyle: FontStyle.italic,
                    backgroundColor: CupertinoColors.black)),
          ),
    

    提醒:对于颜色,请使用 CupertinoColor 而不是简单的 颜色。
    我的代码是here

    【讨论】:

      猜你喜欢
      • 2019-04-23
      • 2021-02-28
      • 2020-07-23
      • 2021-07-07
      • 2020-10-08
      • 1970-01-01
      • 2019-08-23
      • 1970-01-01
      • 2019-12-07
      相关资源
      最近更新 更多