When a widget icon button is pressed, I want to change the button's icon, have setState rebuild the widget so the changed button icon is visible, then run a function:
bool _showPauseIcon = false;
void doSomething() {
print("doSomething()");
}
.
.
.
IconButton(
icon: _showPauseIcon ? Icon(Icons.pause) : Icon(Icons.play),
onPressed: () {
_showPauseIcon = true;
setState (() { });
doSomething();
},
)
doSomething() appears to be called before setState rebuilds the widget, so the modified icon only appears after doSomething() has been called - I need it to happen before doSomething() is called. I looking for the simplest possible solution.