从主题更改RaisedButton的颜色不起作用 [英] Change color of RaisedButton from theme not working

查看:826
本文介绍了从主题更改RaisedButton的颜色不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I tried changing the color of all my RaisedButtons from the themeData but it refused to work. All other properties, such as fontSize and fontWeight changed successfully. The color of the text only changes from black to white when the brightness property of themeData is changed to Brightness.dark.

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

Is there a way I can solve this issue? What could I be doing wrong?

这是我的示例代码:

 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方法集.

For other people coming to this question, one reason that a button may not change colors is that it is disabled, which happens when you don't have the onPressed method set.

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

这篇关于从主题更改RaisedButton的颜色不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆