showBox function

Future<bool> showBox({
  1. required BuildContext context,
  2. String? text,
  3. Option? button01,
  4. Option? button02,
  5. VoidCallback? press01,
  6. VoidCallback? press02,
  7. Widget? title,
  8. EdgeInsetsGeometry? titlePadding,
  9. TextStyle? titleTextStyle,
  10. Widget? content,
  11. EdgeInsetsGeometry? contentPadding,
  12. TextStyle? contentTextStyle,
  13. List<Widget>? actions,
  14. EdgeInsetsGeometry? actionsPadding,
  15. VerticalDirection? actionsOverflowDirection,
  16. double? actionsOverflowButtonSpacing,
  17. EdgeInsetsGeometry? buttonPadding,
  18. Color? backgroundColor,
  19. double? elevation,
  20. String? semanticLabel,
  21. EdgeInsets? insetPadding,
  22. Clip? clipBehavior,
  23. ShapeBorder? shape,
  24. bool? scrollable,
  25. bool? barrierDismissible,
  26. Color? barrierColor,
  27. String? barrierLabel,
  28. bool? useSafeArea,
  29. bool? useRootNavigator,
  30. RouteSettings? routeSettings,
})

A high-level function Displays a String passing specific one to two button options and their corresponding fucntion calls. Displays a particular dialogue box depending on platform.

Implementation

Future<bool> showBox({
  required BuildContext context,
  String? text,
  Option? button01,
  Option? button02,
  VoidCallback? press01,
  VoidCallback? press02,
  Widget? title,
  EdgeInsetsGeometry? titlePadding,
  TextStyle? titleTextStyle,
  Widget? content,
  EdgeInsetsGeometry? contentPadding,
  TextStyle? contentTextStyle,
  List<Widget>? actions,
  EdgeInsetsGeometry? actionsPadding,
  VerticalDirection? actionsOverflowDirection,
  double? actionsOverflowButtonSpacing,
  EdgeInsetsGeometry? buttonPadding,
  Color? backgroundColor,
  double? elevation,
  String? semanticLabel,
  EdgeInsets? insetPadding,
  Clip? clipBehavior,
  ShapeBorder? shape,
  bool? scrollable,
  bool? barrierDismissible,
  Color? barrierColor,
  String? barrierLabel,
  bool? useSafeArea,
  bool? useRootNavigator,
  RouteSettings? routeSettings,
}) async {
  button01 ??= OKOption();
  button02 ??= CancelOption();
  bool? result;
  if (App.useMaterial) {
    result = await showDialog<bool>(
      context: context,
      barrierDismissible: barrierDismissible ?? true,
      barrierColor: barrierColor ?? Colors.black54,
      barrierLabel: barrierLabel,
      useSafeArea: useSafeArea ?? true,
      useRootNavigator: useRootNavigator ?? true,
      routeSettings: routeSettings,
      builder: (BuildContext context) => AlertDialog(
          title: title,
          titlePadding: titlePadding,
          titleTextStyle: titleTextStyle,
          content: content ?? Text(text ?? ' '),
          contentPadding:
              contentPadding ?? const EdgeInsets.fromLTRB(24, 20, 24, 24),
          contentTextStyle: contentTextStyle,
          actionsPadding: actionsPadding ?? EdgeInsets.zero,
          actionsOverflowDirection: actionsOverflowDirection,
          actionsOverflowButtonSpacing: actionsOverflowButtonSpacing,
          buttonPadding: buttonPadding,
          backgroundColor: backgroundColor,
          elevation: elevation,
          semanticLabel: semanticLabel,
          insetPadding: insetPadding ??
              const EdgeInsets.symmetric(horizontal: 40, vertical: 24),
          clipBehavior: clipBehavior ?? Clip.none,
          shape: shape,
          scrollable: scrollable ?? false,
          actions: <Widget>[
            TextButton(
              onPressed: () {
                if (press02 != null) {
                  press02();
                }
                if (button02!.onPressed != null) {
                  button02.onPressed!();
                }
                Navigator.pop(context, button02.result ?? false);
              },
              child: Text(button02!.text ?? 'Cancel'),
            ),
            TextButton(
              onPressed: () {
                if (press01 != null) {
                  press01();
                }
                if (button01!.onPressed != null) {
                  button01.onPressed!();
                }
                Navigator.pop(context, button01.result ?? true);
              },
              child: Text(button01!.text ?? 'OK'),
            ),
          ]),
    );
  } else {
    result = await showCupertinoDialog<bool>(
      context: context,
      builder: (BuildContext context) =>
          CupertinoAlertDialog(content: Text(text ?? ' '), actions: <Widget>[
        CupertinoDialogAction(
          onPressed: () {
            if (press02 != null) {
              press02();
            }
            if (button02!.onPressed != null) {
              button02.onPressed!();
            }
            Navigator.pop(context, button02.result ?? false);
          },
          child: Text(button02!.text ?? 'Cancel'),
        ),
        CupertinoDialogAction(
          onPressed: () {
            if (press01 != null) {
              press01();
            }
            if (button01!.onPressed != null) {
              button01.onPressed!();
            }
            Navigator.pop(context, button01.result ?? true);
          },
          child: Text(button01!.text ?? 'OK'),
        ),
      ]),
    );
  }
  return result ?? false;
}