markNeedsBuild method

  1. @mustCallSuper
void markNeedsBuild()

Marks the element as dirty and schedules a rebuild.

Implementation

@mustCallSuper
void markNeedsBuild() {
  assert(_lifecycleState != _ElementLifecycle.defunct);
  if (_lifecycleState != _ElementLifecycle.active) return;
  assert(_parentRenderObjectElement != null);
  assert(_lifecycleState == _ElementLifecycle.active);
  assert(() {
    if (owner._debugBuilding) {
      assert(owner._debugCurrentBuildTarget != null);
      if (_debugIsInScope(owner._debugCurrentBuildTarget!)) {
        return true;
      }
      if (!_debugAllowIgnoredCallsToMarkNeedsBuild) {
        throw 'setState() or markNeedsBuild() called during build.';
      }
      // can only get here if we're not in scope, but ignored calls are allowed, and our call would somehow be ignored (since we're already dirty)
      assert(dirty);
    } else if (owner._debugStateLocked) {
      assert(!_debugAllowIgnoredCallsToMarkNeedsBuild);
      throw 'setState() or markNeedsBuild() called when widget tree was locked.';
    }
    return true;
  }());

  if (_dirty) return;
  _dirty = true;
  owner.scheduleBuildFor(this);
}