作者热门文章
- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我已经从 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;
我在对话框中发现 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
最佳答案
如果您希望 float 按钮的颜色是主要的,请添加以下内容。
floatingActionButton: FloatingActionButton(
backgroundColor: Theme.of(context).primaryColor,
如果想把对话框中FlatButton的颜色改成黑色,添加如下内容。
theme: ThemeData(
colorScheme: ColorScheme.light(
primary: primary,
secondary: Colors.black,
),
最好用 ColorScheme() 实例化它,这样它就不会影响其他小部件。
关于flutter - FloatingActionButton backgroundColor 默认为 accentColor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54767363/
我是一名优秀的程序员,十分优秀!