showPopupDialog<T> function

Future<T?> showPopupDialog<T>(
  1. BuildContext context,
  2. WidgetBuilder builder, {
  3. bool useRootNavigator = false,
  4. bool barrierDismissible = true,
  5. Color? barrierColor,
  6. String? barrierLabel,
  7. bool asDropDown = false,
  8. bool useTargetWidth = false,
  9. double? dialogWidth,
})

Implementation

Future<T?> showPopupDialog<T>(
  BuildContext context,
  WidgetBuilder builder, {
  bool useRootNavigator = false,
  bool barrierDismissible = true,
  Color? barrierColor,
  String? barrierLabel,
  bool asDropDown = false,
  bool useTargetWidth = false,
  double? dialogWidth,
}) {
  final navigator = Navigator.of(context, rootNavigator: useRootNavigator);
  final renderBox = context.findRenderObject()! as RenderBox;
  final overlayRenderBox =
      navigator.overlay!.context.findRenderObject()! as RenderBox;

  final position = RelativeRect.fromRect(
    Rect.fromPoints(
      renderBox.localToGlobal(renderBox.size.topLeft(Offset.zero),
          ancestor: overlayRenderBox),
      renderBox.localToGlobal(renderBox.size.bottomRight(Offset.zero),
          ancestor: overlayRenderBox),
    ),
    Offset.zero & overlayRenderBox.size,
  );

  return navigator.push(_PopupDialogRoute<T>(
    asDropDown: asDropDown,
    position: position,
    capturedThemes:
        InheritedTheme.capture(from: context, to: navigator.context),
    dialogWidth: useTargetWidth ? renderBox.size.width : dialogWidth,
    barrierDismissible: barrierDismissible,
    barrierColor: barrierColor,
    barrierLabel: barrierLabel,
    child: builder(context),
  ));
}