setState method

  1. @protected
void setState(
  1. VoidCallback fn

Schedule a call to buildTransitions.

Whenever you need to change internal state for a ModalRoute object, make the change in a function that you pass to setState, as in:

setState(() { _myState = newValue; });

If you just change the state directly without calling setState, then the route will not be scheduled for rebuilding, meaning that its rendering will not be updated.


void setState(VoidCallback fn) {
  if (_scopeKey.currentState != null) {
  } else {
    // The route isn't currently visible, so we don't have to call its setState
    // method, but we do still need to call the fn callback, otherwise the state
    // in the route won't be updated!