dispose method

  1. @mustCallSuper
void dispose()

Discards any resources used by the object. After this is called, the object is not in a usable state and should be discarded.

Calling dispose from inside a listener is supported: the in-flight notifyListeners iteration sees _isDisposed flip to true and breaks out of its loop, so listeners scheduled later in the same dispatch do not fire.

This method should only be called by the object's owner.

Implementation

@mustCallSuper
void dispose() {
  assert(!_isDisposed, 'This $runtimeType has already been disposed.');
  _isDisposed = true;
  _listeners = _emptyListeners;
  _count = 0;
  _pinnedListeners?.clear();
  _pinnedListeners = null;
  _detachAllFinalizers();
}