我已从https://github.com/flutter/flutter/issues/28138重定向到此处。
通常我的问题是我不认为FloatingActionButton backgroundColor和FlatButton文本颜色是继承自ThemeData中定义的正确值。
前景和背景均默认为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
答案 0 :(得分:0)
如果您希望浮动按钮的颜色为主要颜色,请添加以下内容。
"Consortiums":&ConfigGroup{...
如果要将对话框中FlatButton的颜色更改为黑色,请添加以下内容。
floatingActionButton: FloatingActionButton(
backgroundColor: Theme.of(context).primaryColor,
最好使用ColorScheme()实例化它,以免影响其他小部件。