【问题标题】:How to use an Elevated Button Theme from a themes file?如何使用主题文件中的高架按钮主题?
【发布时间】:2021-04-11 20:05:15
【问题描述】:

由于不推荐使用凸起按钮以支持 ElevatedButtons,因此我无法从另一个文件中找到有关使用 ElevatedButtonTheme 的任何明确示例。

提升按钮接受样式属性,特别是按钮样式,但此样式属性不接受提升按钮主题对象,这是常识所说的应该起作用的对象。按钮样式需要 MaterialState 属性,没有提到提升的ButtonTheme :(.

有人可以为此提供一个例子吗?文档没有说清楚,这里没有例子:https://api.flutter.dev/flutter/material/ElevatedButtonTheme-class.html

【问题讨论】:

    标签: flutter dart


    【解决方案1】:

    看起来 Flutter 的默认行为是它会自动默认为提升的ButtonTheme,无需指定。我只需要在我的主题文件中指定正确的颜色,它就开始工作了。无需指定样式属性。

    提升按钮的默认样式由 defaultStyleOf 定义。这个提升按钮的样式可以被它的样式参数覆盖。子树中所有提升按钮的样式可以用 ElevatedButtonTheme 覆盖,应用程序中所有提升按钮的样式可以用 Theme 的 ThemeData.elevatedButtonTheme 属性覆盖。

    来自-https://api.flutter.dev/flutter/material/ElevatedButton-class.html

    【讨论】:

      猜你喜欢
      • 2021-02-01
      • 2019-04-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-26
      • 1970-01-01
      相关资源
      最近更新 更多