show method

PopupController show({
  1. required WidgetBuilder builder,
  2. bool barrierDismissible = true,
  3. bool showBarrier = false,
  4. Color barrierColor = Colors.black38,
  5. AnimationSwitchController? animationController,
  6. bool animation = false,
  7. void onHoverInBarrier(
    1. PointerHoverEvent
    )?,
  8. bool dismissCondition(
    1. TapDownDetails
    )?,
  9. void onDismiss()?,
})

Shows Popup widget.

This function returns an PopupController object, on which we can call the remove function to dynamically remove the popup.

Can also get the same PopupController from inside the Popup widget tree, using PopupController.of method, on which one can call remove method.

It is recommended for builder to return Popup, while it can also return a Positioned or a Builder widget which returns Positioned or similar widget.

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

Provide onHoverInBarrier to provide a callback for the onHover method of the Barrier.

Provide dismissCondition to dismiss the popup conditionally.

Implementation

PopupController show({
  required WidgetBuilder builder,
  bool barrierDismissible = true,
  bool showBarrier = false,
  Color barrierColor = Colors.black38,
  AnimationSwitchController? animationController,
  bool animation = false,
  void Function(PointerHoverEvent)? onHoverInBarrier,
  bool Function(TapDownDetails)? dismissCondition,
  void Function()? onDismiss,
}) {
  if (onDismiss != null) this.onDismiss = onDismiss;

  if (mounted) {
    throw PlatformException(
      code: 'POPUP_ALREADY_EXIST',
      message: 'A popup is already being shown, using this controller',
    );
  }

  final Widget child = Stack(
    children: [
      if (showBarrier)
        IgnorePointer(
          ignoring: !barrierDismissible,
          child: Material(
            color: Colors.transparent,
            child: MouseRegion(
              onHover: onHoverInBarrier,
              child: GestureDetector(
                onTapDown: (details) async {
                  if (!((dismissCondition?.call(details) ?? true) &&
                      barrierDismissible)) {
                    return;
                  }
                  await remove();
                },
                child: Container(
                  color: barrierColor,
                ),
              ),
            ),
          ),
        ),
      _PopupInherited(
        controller: this,
        child: Builder(builder: builder),
      ),
    ],
  );

  _mount(child, animation, animationController);
  return this;
}