lockState method
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
Future<void> lockState(dynamic Function() callback) async {
assert(_debugStateLockLevel >= 0);
assert(() {
_debugStateLockLevel += 1;
return true;
}());
try {
final res = callback() as dynamic;
if (res is Future) {
await res;
}
} finally {
assert(() {
_debugStateLockLevel -= 1;
return true;
}());
}
assert(_debugStateLockLevel >= 0);
}