dispose method Null safety

void dispose()

Discards any resources used by this OverlayEntry.

This method must be called after remove if the OverlayEntry is inserted into an Overlay.

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). However, the listeners registered may not be immediately released until the widget built using this OverlayEntry is unmounted from the widget tree.

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

Implementation

void dispose() {
  assert(!_disposedByOwner);
  assert(_overlay == null, 'An OverlayEntry must first be removed from the Overlay before dispose is called.');
  _disposedByOwner = true;
  if (!mounted) {
    _overlayStateMounted.dispose();
  }
}