我试图切换凸起按钮的颜色.最初按钮应为蓝色,按下时按钮变为灰色.现在我有一个名为pressAttention的bool值,它被设置为false.我用这个来初步设置这个假.按下按钮时,它会切换pressAttention bool,但似乎小部件永远不会再次更新.
new RaisedButton(
child: new Text("Attention"),
textColor: Colors.white,
shape: new RoundedRectangleBorder(borderRadius: new BorderRadius.circular(30.0)),
color: pressAttention?Colors.grey:Colors.blue,
onPressed: () => doSomething("Attention"),
)
void doSomething(String buttonName){
if(buttonName == "Attention"){
if(pressAttention = false){
pressAttention = true;
} else {
pressAttention = false;
}
}
Run Code Online (Sandbox Code Playgroud)
}