Everything I have read about this suggests you can do this work with SetState. This is what I have been using and it will just not redraw.
class ServerSelectionState extends State<ServerSelection> {
bool server1Selected, server2Selected, server3Selected = false;
@override
void initState() {
setState(() {
server1Selected= false;
server2Selected= false;
server3Selected= false;
});
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
//Basically have an onTap method from a ListTile that opens a dialog, like this:
onTap: () {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
backgroundColor: greyTheme,
content: Form(
child: Container(
children: <Widget>[
ButtonTheme(
child: RaisedButton(
onPressed: (){
if (!mounted) return;
setState(() {
server1Selected = true;
server2Selected = false;
server3Selected = false;
});
},
color: server1Selected == true ? Colors.pink : Colors.blue,
child: Text(
'Server 1',
style: TextStyle(
color: Colors.red,
),
),
),
),
],
),
),
),
}
);
}
This will update the button colour just fine on a hot reload, but until then it doesn't seem like it is happy doing a redraw. The if (!mounted) section prevents an error that I was seeing about dispose being called before redraw, or similar, and print outputs this is working, it is changing the state of the booleans correctly, it just doesn't actually update the colour until you force the widget to redraw.