代码之家  ›  专栏  ›  技术社区  ›  biswajit

无法更改RaisedButton颜色

  •  0
  • biswajit  · 技术社区  · 6 年前
    RaisedButton(
              onPressed: null,
              child: Text('Get in'), // change it to sign-in
              color: Colors.blue,
            )
    

    我在children下创建了这个小部件,但是颜色没有改变默认的灰色。我尝试使用十六进制代码值,但仍然没有帮助。

    1 回复  |  直到 6 年前
        1
  •  24
  •   jprogramista    6 年前

    从RaisedButton文档:

    如果[onPressed]回调为空,则该按钮将被禁用,默认情况下类似于[disabledColor]中的平面按钮。如果你是 尝试更改按钮的[颜色]时,如果没有任何效果,请检查是否传递了非空的[onPressed]处理程序。

        2
  •  8
  •   pavel    4 年前

    RaisedButton的颜色取决于它是否可以按下。您应该将onPressed添加到属性中

                               RaisedButton(
                                  onPressed: () => {},
                                  color: Colors.green,
                                  child: Text(
                                    'Login',
                                    style: TextStyle(color: Colors.white),
                                  ),
                                ),
    
        3
  •  7
  •   EngineerDanny    5 年前

    用这个代替,

     RaisedButton(
                  onPressed: null,
                  child: Text('Get in'), // change it to sign-in
                  color: Colors.blue,
                  disabledColor: Colors.blue,//add this to your code
                )
    
        4
  •  1
  •   Younes Belouche    4 年前

    我以前遇到过这个问题,解决方案是将null关键字从onPressed方法中移除到一些实现中,至少是这样:(){}