invalidateSelf method

  1. @override
void invalidateSelf()
override

Invalidates the state of the provider, causing it to refresh.

The refresh is not immediate and is instead delayed to the next read or next frame.

Calling invalidateSelf multiple times will refresh the provider only once.

Calling invalidateSelf will cause the provider to be disposed immediately.

Implementation

@override
void invalidateSelf() {
  if (_mustRecomputeState) return;

  _mustRecomputeState = true;
  runOnDispose();
  mayNeedDispose();
  _container.scheduler.scheduleProviderRefresh(this);

  // We don't call this._markDependencyMayHaveChanged here because we voluntarily
  // do not want to set the _dependencyMayHaveChanged flag to true.
  // Since the dependency is known to have changed, there is no reason to try
  // and "flush" it, as it will already get rebuilt.
  visitChildren(
    elementVisitor: (element) => element._markDependencyMayHaveChanged(),
    notifierVisitor: (notifier) => notifier.notifyDependencyMayHaveChanged(),
  );
}