【发布时间】:2020-05-26 11:06:39
【问题描述】:
我正在使用 Theme 设计一个 Flutter 应用程序。 关于Button,ButtonThemeData.buttonColor和ButtonThemeData.colorScheme.primary有什么区别?
【问题讨论】:
标签: flutter material-design themes styling
我正在使用 Theme 设计一个 Flutter 应用程序。 关于Button,ButtonThemeData.buttonColor和ButtonThemeData.colorScheme.primary有什么区别?
【问题讨论】:
标签: flutter material-design themes styling
在创建ThemeData对象时,如果没有指定buttonTheme,则会从buttonColor等其他属性构建。如果未指定buttonColor,它将是primarySwatch 的阴影。如果未指定primarySwatch,则为Colors.blue。
同理,如果不指定colorScheme,则会从primarySwatch等其他属性构建,此时colorScheme.primary获取primarySwatch的值,默认为Colors.blue。
至于框架如何将它们用于小部件:
buttonColor 实际上并没有在任何地方使用。buttonTheme.buttonColor 用于RaisedButton、FlatButton、OutlineButton
colorScheme.primary 用于滑块、切换开关、小吃栏以及几个 Cupertino 小部件。ThemeData 的其他几个属性本应通过引入 colorScheme 对象而变得多余,但它们并未被弃用,因此相当混乱。
【讨论】: