dispose method

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.');
  if (kFlutterMemoryAllocationsEnabled) {
    FlutterMemoryAllocations.instance.dispatchObjectDisposed(object: this);
  }
  _disposedByOwner = true;
  if (!mounted) {
    // If we're still mounted when disposed, then this will be disposed in
    // _didUnmount, to allow notifications to occur until the entry is
    // unmounted.
    _overlayEntryStateNotifier?.dispose();
    _overlayEntryStateNotifier = null;
  }
}