翩翩起舞如何改变按钮上的颜色点击

问题描述 投票:0回答:1

我想改变按钮的颜色,当我点击它。你能帮帮我吗,因为我真的做不到。谢谢你的帮助。

 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;

},
flutter colors onpress materialbutton
1个回答
2
投票

尝试像这样

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

splashColors: mySplashColor,
onPressed(){
setState(){
splashColors=Colors.red;
}
}
© www.soinside.com 2019 - 2024. All rights reserved.