dispose method Null safety

  1. @override
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 (calls to addListener will throw after the object is disposed).

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


void dispose() {
  // In practice, this will rarely be called. We assume that the listeners
  // will be added and removed in a coherent fashion such that when the object
  // is no longer being used, there's no listener, and so it will get garbage
  // collected.
  if (hasListeners) {