showAlertWidget static method

AlertHandler showAlertWidget({
  1. required WidgetBuilder builder,
  2. required BuildContext context,
  3. Color? barrierColor,
  4. bool showContent = true,
  5. bool useRootNavigator = false,
})

Implementation

static AlertHandler showAlertWidget({
  required WidgetBuilder builder,
  required BuildContext context,
  Color? barrierColor,
  bool showContent = true,
  bool useRootNavigator = false,
}) {
  final handler = AlertHandler();
  handler._visible.value = showContent;
  final barrierColor0 = barrierColor ?? Colors.black54;
  final route = _showDialog(
    context: context,
    barrierDismissible: false,
    barrierColor: Colors.transparent,
    useRootNavigator: useRootNavigator,
    builder: (builderContext) {
      return ValueListenableBuilder<bool>(
        valueListenable: handler._visible,
        builder: (_, visible, __) {
          return Offstage(
            offstage: !visible,
            child: Stack(children: [
              ModalBarrier(
                color: barrierColor0,
                dismissible: false,
              ),
              builder.call(builderContext),
            ]),
          );
        },
      );
    },
  );
  final navigator = Navigator.of(context, rootNavigator: useRootNavigator);
  handler._navigatorState = navigator;
  handler._route = route;
  return handler;
}