showPopover<T extends Object?> function

Future<T?> showPopover<T extends Object?>({
  1. required BuildContext context,
  2. required WidgetBuilder bodyBuilder,
  3. PopoverDirection direction = PopoverDirection.bottom,
  4. Color backgroundColor = const Color(0x8FFFFFFFF),
  5. Color barrierColor = const Color(0x80000000),
  6. Duration transitionDuration = const Duration(milliseconds: 200),
  7. double radius = 8,
  8. List<BoxShadow> shadow = const [BoxShadow(color: Color(0x1F000000), blurRadius: 5)],
  9. double arrowWidth = 24,
  10. double arrowHeight = 12,
  11. double arrowDxOffset = 0,
  12. double arrowDyOffset = 0,
  13. double contentDyOffset = 0,
  14. bool barrierDismissible = true,
  15. double? width,
  16. double? height,
  17. VoidCallback? onPop,
  18. bool isParentAlive()?,
  19. BoxConstraints? constraints,
  20. RouteSettings? routeSettings,
  21. String? barrierLabel,
  22. Key? key,
})

A popover is a transient view that appears above other content onscreen when you tap a control or in an area.

This function allows for customization of aspects of the dialog popup.

bodyBuilder argument is builder which builds body/content of popover.

The direction is desired Popover's direction behaviour. This argument defaults to PopoverDirection.bottom.

The backgroundColor is background Color of popover. This argument defaults to Color(0x8FFFFFFFF).

The barrierColor is barrier Color of screen when popover is presented. This argument defaults to Color(0x80000000).

The transitionDuration argument is used to determine how long it takes for the route to arrive on or leave off the screen. This argument defaults to 200 milliseconds.

The radius of popover's body. This argument defaults to 8.

The shadow is BoxShadow of popover body. This argument defaults to [BoxShadow(color: Color(0x1F000000), blurRadius: 5)].

The arrowWidth is width of arrow. This argument defaults to 24.

The arrowHeight is height of arrow. This argument defaults to 12.

The arrowDxOffset offsets arrow position on X axis. It can be positive or negative number. This argument defaults to 0.

The arrowDyOffset offsets arrow position on Y axis. It can be positive or negative number. This argument defaults to 0.

ThecontentDyOffset offsets Popovers contetnt position on Y axis. It can be positive or negative number. This argument defaults to 0.

The barrierDismissible argument is used to determine whether this route can be dismissed by tapping the modal barrier. This argument defaults to true.

The width is popover's body/content widget width.

The height is popover's body/content widget height.

The onPop called to veto attempts by the user to dismiss the popover.

Pass mounted property from parent widget to the isParentAlive function to prevent red screen of death. isParentAlive : () => mounted

The constraints is popover's constraints.

The routeSettings is data that might be useful in constructing a Route.

The barrierLabel is semantic label used for a dismissible barrier.

Implementation

Future<T?> showPopover<T extends Object?>({
  required BuildContext context,
  required WidgetBuilder bodyBuilder,
  PopoverDirection direction = PopoverDirection.bottom,
  Color backgroundColor = const Color(0x8FFFFFFFF),
  Color barrierColor = const Color(0x80000000),
  Duration transitionDuration = const Duration(milliseconds: 200),
  double radius = 8,
  List<BoxShadow> shadow = const [
    BoxShadow(color: Color(0x1F000000), blurRadius: 5)
  ],
  double arrowWidth = 24,
  double arrowHeight = 12,
  double arrowDxOffset = 0,
  double arrowDyOffset = 0,
  double contentDyOffset = 0,
  bool barrierDismissible = true,
  double? width,
  double? height,
  VoidCallback? onPop,
  bool Function()? isParentAlive,
  BoxConstraints? constraints,
  RouteSettings? routeSettings,
  String? barrierLabel,
  Key? key,
}) {
  constraints = (width != null || height != null)
      ? constraints?.tighten(width: width, height: height) ??
          BoxConstraints.tightFor(width: width, height: height)
      : constraints;

  return Navigator.of(context, rootNavigator: true).push<T>(
    RawDialogRoute<T>(
      pageBuilder: (_, __, ___) {
        return Builder(builder: (_) => const SizedBox.shrink());
      },
      barrierDismissible: barrierDismissible,
      barrierLabel: barrierLabel ??=
          MaterialLocalizations.of(context).modalBarrierDismissLabel,
      barrierColor: barrierColor,
      transitionDuration: transitionDuration,
      settings: routeSettings,
      transitionBuilder: (builderContext, animation, _, child) {
        return WillPopScope(
          onWillPop: () {
            if (onPop != null) {
              onPop();
              return Future.value(true);
            } else {
              return Future.value(true);
            }
          },
          child: FadeTransition(
            opacity: CurvedAnimation(parent: animation, curve: Curves.easeOut),
            child: PopoverItem(
              child: bodyBuilder(builderContext),
              context: context,
              backgroundColor: backgroundColor,
              direction: direction,
              radius: radius,
              boxShadow: shadow,
              animation: animation,
              arrowWidth: arrowWidth,
              arrowHeight: arrowHeight,
              constraints: constraints,
              arrowDxOffset: arrowDxOffset,
              arrowDyOffset: arrowDyOffset,
              contentDyOffset: contentDyOffset,
              isParentAlive: isParentAlive,
              key: key,
            ),
          ),
        );
      },
    ),
  );
}