【问题标题】:Does Flutter support cascading styles?Flutter 是否支持级联样式?
【发布时间】:2020-07-03 12:52:30
【问题描述】:

我希望能够设置一个可以在我的应用程序中使用的默认文本样式,然后在特定情况下覆盖该样式的一部分。 React Native 支持这个,请问 Flutter 也支持吗?或者如果没有,我怎样才能实现这样的目标?

我希望这会如何工作的示例:

style.dart:

ThemeData appTheme() {
   return ThemeData(
      ...
      textTheme: TextTheme(
         headline1: TextStyle(fontSize: 26.0, fontWeight: FontWeight.bold),
         ...
      )
   )
}

body.dart:

Text('My text here', style: [TextStyle(color: myColorVariable), themeData.textTheme.headline1])

非常感谢!

【问题讨论】:

    标签: flutter dart


    【解决方案1】:

    你可以使用

    Theme.of(context).textTheme.copyWith()

    甚至

    Theme.of(context).textTheme.subtitle1.copyWith()

    更改特定文本小部件的默认值。

    【讨论】:

      猜你喜欢
      • 2018-04-26
      • 1970-01-01
      • 1970-01-01
      • 2020-08-06
      • 2013-01-13
      • 1970-01-01
      • 2018-09-21
      • 2021-08-06
      • 1970-01-01
      相关资源
      最近更新 更多