dispose method Null safety

  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.

Implementation

@override
void dispose() {
  assert(ChangeNotifier.debugAssertNotDisposed(this)); // FYI, This uses ChangeNotifier's _debugDisposed, not _disposed.
  _owner?._unregister(this);
  super.dispose();
  _disposed = true;
}