dispose method

  1. @override
void dispose()
override

Discards any resources used by the object.

After this is called, the object is not in a usable state and should be discarded (calls to addListener will throw after the object is disposed).

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

This method does not notify listeners, and clears the listener list once it is called. Consumers of this class must decide on whether to notify listeners or not immediately before disposal.

Implementation

@override
void dispose() {
  if (_disposed) return;
  _disposed = true;
  _scopedWatchdogTimer?.cancel();
  _scopedWatchdogTimer = null;
  _scopedBatchDepth = 0;
  _scopedPendingNotify = false;
  // One last notification, before teardown, so anything tracking this
  // store as a dependency (e.g. ComputedStore) finds out about the
  // disposal right away instead of only on its next unrelated read.
  // notifyListeners() itself now short-circuits on _disposed, so this
  // goes straight to the underlying ChangeNotifier.
  super.notifyListeners();
  _detachLifecycle();
  onDispose();
  for (final timer in _debounceTimers.values) {
    timer.cancel();
  }
  _debounceTimers.clear();
  for (final timer in _throttleTimers.values) {
    timer.cancel();
  }
  _throttleTimers.clear();
  for (final dispose in _watchDisposers) {
    try {
      dispose();
    } catch (_) {}
  }
  _watchDisposers.clear();
  super.dispose();
}