gpt4 book ai didi

flutter - 从主题更改 RaisedButton 的颜色不起作用

转载 作者:IT老高 更新时间:2023-10-28 12:43:28 26 4
gpt4 key购买 nike

我尝试从 themeData 更改我所有 RaisedButtons 的颜色,但它拒绝工作。所有其他属性,例如 fontSizefontWeight 已成功更改。仅当 themeData 的亮度属性更改为 Brightness.dark 时,文本的颜色才会从黑色变为白色。

有什么办法可以解决这个问题吗?我可能做错了什么?

这是我的示例代码:

 return new MaterialApp(
title: 'Flutter Demo',
theme: new ThemeData(
primaryColor: Color(0XFF212845),
scaffoldBackgroundColor: Color(0XFF212845),
primarySwatch: Colors.yellow,
buttonColor: Color(0XFFF8D320),
textTheme: TextTheme(
button: TextStyle(
color: Colors.green, // This is not working.
fontSize: 30.0,
fontWeight: FontWeight.bold
)
)
),
home:MenuPage(),
);

最佳答案

对于其他提出这个问题的人来说,按钮可能不会改变颜色的一个原因是它被禁用,当您没有设置 onPressed 方法时会发生这种情况。

RaisedButton(
color: Theme.of(context).accentColor,
onPressed: () {}, // <-- need to add this
child: Text(...),
),

enter image description here

关于flutter - 从主题更改 RaisedButton 的颜色不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53981006/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com