FloatingActionButton backgroundColor 默认为重音颜色

Eri*_*ica 3 material-design flutter

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

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

  1. 创建一个应用程序,您将在其中使用主要红色(应用程序栏、按钮 bg、卡片),黄色用于强调(图标、应用程序栏标题),黑色用于一般文本,白色/浅灰色用于脚手架主体等背景。
  2. 使用主题 (primaryColor) 将 AppBar BG 颜色设置为红色
  3. 使用主题 (accentColor) 将 AppBar 标题颜色设置为黄色
  4. 将图标的颜色设置为与重音颜色相同的颜色,因为如果使用原色,它们将在 AppBar 中不可见
  5. 创建一个带有图标的浮动操作按钮。
  6. floatActionButton 中的图标不可见,因为小部件的 backgroundColor 使用黄色的 ThemeData.accentColor 而不是 ThemeData.primaryColor

前景和背景都默认为重音颜色。

 /// The color to use when filling the button.
 ///
 /// Defaults to **[ThemeData.accentColor**] for the current theme.
 final Color backgroundColor;
Run Code Online (Sandbox Code Playgroud)

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

flat_button.dart:127

 /// The color to use when filling the button.
 ///
 /// Defaults to **[ThemeData.accentColor**] for the current theme.
 final Color backgroundColor;
Run Code Online (Sandbox Code Playgroud)

我的主题:

 textStyle: theme.textTheme.button.copyWith(color: buttonTheme.getTextColor(this)),
Run Code Online (Sandbox Code Playgroud)

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

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

ko2*_*2ic 5

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

  floatingActionButton: FloatingActionButton(
    backgroundColor: Theme.of(context).primaryColor,
Run Code Online (Sandbox Code Playgroud)

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

  theme: ThemeData(
    colorScheme: ColorScheme.light(
      primary: primary,
      secondary: Colors.black,
    ),
Run Code Online (Sandbox Code Playgroud)

最好用 ColorScheme() 实例化它,这样它就不会影响其他小部件。