debugUpdate method

void debugUpdate()

A test utility to test the behavior of your initState/update method.

The first time debugUpdate is called, this will call initState + update. Further calls will only call update.

While inside update, read will be disabled as it would be in production.

Implementation

void debugUpdate() {
  assert(() {
    if (!_debugDidInitState) {
      _debugDidInitState = true;
      initState();
    }

    final locator = read;
    read = <T>() => throw StateError('Cannot use `read` inside `update`');
    try {
      update(locator);
    } finally {
      read = locator;
    }
    return true;
  }(), '');
}