lockState method

void lockState(
  1. VoidCallback callback
)

Establishes a scope in which calls to State.setState are forbidden, and calls the given callback.

This mechanism is used to ensure that, for instance, State.dispose does not call State.setState.

Implementation

void lockState(VoidCallback callback) {
  assert(_debugStateLockLevel >= 0);
  assert(() {
    _debugStateLockLevel += 1;
    return true;
  }());
  try {
    callback();
  } finally {
    assert(() {
      _debugStateLockLevel -= 1;
      return true;
    }());
  }
  assert(_debugStateLockLevel >= 0);
}