【问题标题】:How to use textTheme in ElevatedButton?如何在 ElevatedButton 中使用 textTheme?
【发布时间】:2021-06-03 23:55:55
【问题描述】:

我正在从 RaisedButton 迁移到 ElevatedButton,但在我的 themeData 中有一些东西我不知道该怎么做:

buttonTheme: ButtonThemeData(
              buttonColor: PRIMARY_COLOR,
              textTheme: ButtonTextTheme.primary,
            )

textTheme 是我喜欢的东西,因为它使用黑色或白色取决于背景颜色,它是救生员。如何在 ElevatedButton 上做到这一点?没有文本主题

【问题讨论】:

    标签: flutter


    【解决方案1】:

    昨天遇到了这个,我认为这对你有用。

    elevatedButtonTheme: ElevatedButtonThemeData(
      style: ButtonStyle(
        textStyle: MaterialStateProperty.resolveWith(
          (states) => TextStyle(
            // add your styles here
          ),
        ),
      ),
    ),
    

    现在是这样的

    【讨论】:

    • 但是这样我需要为每个按钮指定每种文本颜色,对吗?我正在寻找像 RaisedButton textTheme 一样自动使用它的东西: ButtonTextTheme.primary 例如,如果我在两个按钮上都设置了白色背景色,则 raisebutton 将使用黑色文本颜色本身,而 ElevatedButton 将始终变为白色,而我不会想自己指定颜色
    猜你喜欢
    • 2021-12-16
    • 2021-08-21
    • 2021-06-08
    • 2021-08-16
    • 2022-08-19
    • 2022-10-18
    • 2021-03-07
    • 2021-06-21
    • 2020-05-26
    相关资源
    最近更新 更多