FloatingActionButton backgroundColor默认为accentColor

时间:2019-02-19 13:24:14

标签: flutter material-design

我已从https://github.com/flutter/flutter/issues/28138重定向到此处。

通常我的问题是我不认为FloatingActionButton backgroundColor和FlatButton文本颜色是继承自ThemeData中定义的正确值。

  1. 创建一个应用,在其中您将使用主红色(应用栏,按钮bg,卡片),黄色作为重音(图标,应用栏标题),黑色作为常规文本,白色/浅灰色作为背景(如脚手架主体)。
  2. 使用主题(primaryColor)将AppBar BG颜色设置为红色
  3. 使用主题(accentColor)将AppBar标题颜色设置为黄色
  4. 将图标的颜色设置为与accentColor相同的颜色,因为如果使用原色,则它们在AppBar中将不可见
  5. 使用图标创建一个floatActionButton。
  6. floatActionAction中的图标不可见,因为小部件的backgroundColor使用黄色的ThemeData.accentColor代替ThemeData.primaryColor

前景和背景均默认为accentColor。

 /// The color to use when filling the button.
 ///
 /// Defaults to **[ThemeData.accentColor**] for the current theme.
 final Color backgroundColor;

我在Dialog中发现了FlatButton的类似问题,默认情况下,文本的颜色是加重颜色,即黄色(在白色背景上),如果我将其覆盖为主要颜色,则为红色,但是我不想红色,因为旁边的删除按钮是红色。所以我需要将其设置为正常,所以它是黑色的,这是正确的,但是:

flat_button.dart:127

 textStyle: theme.textTheme.button.copyWith(color: buttonTheme.getTextColor(this)),

我的主题:

buttonTheme: ButtonThemeData(
            textTheme: ButtonTextTheme.normal,
            buttonColor: primary, // Red
          ),

textTheme: TextTheme(
           ...
            button: TextStyle(color: black), // Black
          ),

new FlatButton(
              //textTheme: ButtonTextTheme.normal,
              child: new Text("Ponechať"),
              onPressed: () {
                Navigator.of(context).pop();
                onKeep();
              },
            )

理论上,我在弹出对话框中的FlatButton应该为黑色和/或红色。但是它的颜色是黄色。

要重现,请尝试以下示例: https://gist.github.com/erikkubica/45fc8acdce1f8a25cd5258e8b3a0e1f3

1 个答案:

答案 0 :(得分:0)

如果您希望浮动按钮的颜色为主要颜色,请添加以下内容。

"Consortiums":&ConfigGroup{...

如果要将对话框中FlatButton的颜色更改为黑色,请添加以下内容。

  floatingActionButton: FloatingActionButton(
    backgroundColor: Theme.of(context).primaryColor,

最好使用ColorScheme()实例化它,以免影响其他小部件。