颤抖如何更改单击按钮的颜色

时间:2020-05-26 23:23:06

标签: flutter colors onpress materialbutton

单击按钮时,我试图更改按钮的颜色。您能帮我吗,因为我真的做不到。谢谢。

 Container(

        child: new Row(
          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
            children: <Widget>[
              new MaterialButton(
                  child: new Text("1"),
                  color: Colors.greenAccent,
                splashColor: Colors.red,
                  onPressed:  (){
                    test=0;
                    test=1;



},




 ),
              new MaterialButton(
                child: new Text("2"),
                  color: Colors.greenAccent,
                    onPressed: (){
                    test=0;
                    test=2;

},

1 个答案:

答案 0 :(得分:2)

尝试这样

Color mySplashColor=Colors.blue; //define in build function or state class

splashColors: mySplashColor,
onPressed(){
setState(){
splashColors=Colors.red;
}
}