of static method

PopupController of(
  1. BuildContext context, {
  2. String? id,
  3. bool forceOverlay = false,
  4. void onDismiss()?,
})

Return a PopupController object. This also determines, whether the popup will show using an Overlay over whole screen, or inside a PopupScope.

PopupController returned, will be of the nearest PopupScope parent, which if not exists, then it will be for Overlay.

If called inside a Popup will return the PopupController of that Popup only, i.e cannot use it to show more Popup, but instead can use to remove the Popup dynamically, using PopupController.remove method.

If forceOverlay is true, then pop up will be displayed as an OverlayEntry, i.e like there is no PopupScope above in the widget tree, regardless of it actually exists or not.

Use id to specify own specific id, of the popup.

Provide onDismiss function to perform any callback action on dismissing the popup.

Implementation

static PopupController of(
  BuildContext context, {
  String? id,
  bool forceOverlay = false,
  void Function()? onDismiss,
}) {
  final popupInherited =
      context.dependOnInheritedWidgetOfExactType<_PopupInherited>();
  if (popupInherited != null) return popupInherited.controller;

  id ??= _uniqueId;
  final scope = forceOverlay ? null : PopupScope.of(context);
  return PopupController._(
    context: context,
    id: id,
    key: scope?.key,
    onDismiss: onDismiss,
  );
}