show static method

void show({
  1. required BuildContext context,
  2. required String dialogId,
  3. required Widget dialog,
  4. bool barrierDismissible = true,
  5. Color barrierColor = Colors.black54,
  6. bool rootOverlay = true,
  7. bool enableHide = false,
})

Implementation

static void show({
  required BuildContext context,
  required String dialogId,
  required Widget dialog,
  bool barrierDismissible = true,
  Color barrierColor = Colors.black54,
  bool rootOverlay = true,
  bool enableHide = false,
}) {
  dismiss(dialogId);

  final overlay = Overlay.of(context, rootOverlay: rootOverlay);
  late OverlayEntry overlayEntry;
  final WidgetBuilder widgetBuilder = (builderContext) {
    return Stack(
      children: [
        Positioned.fill(
          child: GestureDetector(
            behavior: HitTestBehavior.opaque,
            onTap: barrierDismissible ? () => dismiss(dialogId) : null,
            child: Container(
              color: barrierColor,
            ),
          ),
        ),
        Center(
          child: Material(
            color: Colors.transparent,
            child: dialog,
          ),
        ),
      ],
    );
  };
  ValueNotifier<bool> isVisable = ValueNotifier(true);
  if (enableHide) {
    overlayEntry = OverlayEntry(
      builder: (context) {
        return ValueListenableBuilder<bool>(
          valueListenable: isVisable,
          builder: (_, visible, __) {
            return Offstage(
              offstage: !visible,
              child: widgetBuilder.call(context),
            );
          },
        );
      },
    );
  } else {
    overlayEntry = OverlayEntry(
      builder: (context) => widgetBuilder.call(context),
    );
  }

  overlay.insert(overlayEntry);
  _overlays[dialogId] = OverlayEntryWrapper(overlayEntry: overlayEntry, isVisable: isVisable);
}