【问题标题】:Flutter Button Theme颤振按钮主题
【发布时间】:2020-05-26 11:06:39
【问题描述】:

我正在使用 Theme 设计一个 Flutter 应用程序。 关于Button,ButtonThemeData.buttonColor和ButtonThemeData.colorScheme.primary有什么区别?

【问题讨论】:

    标签: flutter material-design themes styling


    【解决方案1】:

    在创建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 对象而变得多余,但它们并未被弃用,因此相当混乱。

    【讨论】:

      猜你喜欢
      • 2021-08-02
      • 1970-01-01
      • 2020-04-23
      • 1970-01-01
      • 2021-11-24
      • 2018-11-23
      • 2020-11-22
      • 2019-07-06
      • 2020-10-13
      相关资源
      最近更新 更多