OverlayController class

A controller for managing a single overlay's lifecycle, driven by OverlayConfiguration instead of popover-specific parameters.

Replaces PopoverController: show accepts any OverlayConfiguration (popover, menu, tooltip, drawer, sheet, dialog), so a single controller can drive an overlay regardless of its presentation mechanism.

If show is called again with the same configuration type (still a PopoverConfiguration, say, just with a different PopoverConfiguration.alignment), the open overlay is updated in place through OverlayCompleter.config rather than being closed and reopened. A different configuration type, or no overlay currently open, always closes whatever is open and starts fresh.

Field meanings like "alignment" or "margin" aren't interpreted here. Each OverlayCompleter implementation, for example the one PopoverOverlayHandler returns, reads whatever configuration it's assigned through OverlayCompleter.config on its own terms.

Example:

class _MyWidgetState extends State<MyWidget> {
  final OverlayController _controller = OverlayController();

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }

  void _showMenu() async {
    await _controller.show(
      context,
      PopoverConfiguration(
        anchor: LinkedAnchor(#myAnchor),
        alignment: Alignment.bottomStart,
        builder: (context) => MyPopoverContent(),
      ),
    );
  }
}
Inheritance

Constructors

OverlayController()

Properties

config OverlayConfiguration?
The configuration of the currently-open overlay, or null if nothing is open. There's no setter: use show to open or update an overlay, since assigning config directly has no BuildContext to anchor to.
no setter
hashCode int
The hash code for this object.
no setterinherited
hasListeners bool
Whether any listeners are currently registered.
no setterinherited
hasMountedOverlay bool
Whether there's a mounted overlay with an animation in progress.
no setter
hasOpenOverlay bool
Whether there's an open overlay that hasn't completed.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

addListener(VoidCallback listener) → void
Register a closure to be called when the object changes.
inherited
close([bool immediate = false]) → void
Closes the managed overlay, if any.
closeLater() → void
Schedules closure of the managed overlay for the next frame.
dispose() → void
Discards any resources used by the object.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notifyListeners() → void
Call all the registered listeners.
inherited
removeListener(VoidCallback listener) → void
Remove a previously registered closure from the list of closures that are notified when the object changes.
inherited
show<T>(BuildContext context, OverlayConfiguration<T> configuration, {bool adaptive = true}) Future<T?>
Shows an overlay using the given configuration, anchored to context.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited