showOkAlertDialog function

Future<OkCancelResult> showOkAlertDialog({
  1. required BuildContext context,
  2. String? title,
  3. String? message,
  4. String? okLabel,
  5. bool barrierDismissible = true,
  6. @Deprecated('Use `style` instead.') AdaptiveStyle? alertStyle,
  7. AdaptiveStyle? style,
  8. @Deprecated('Use `ios` instead. Will be removed in v2.') bool useActionSheetForCupertino = false,
  9. bool useActionSheetForIOS = false,
  10. bool useRootNavigator = true,
  11. VerticalDirection actionsOverflowDirection = VerticalDirection.up,
  12. bool fullyCapitalizedForMaterial = true,
  13. bool canPop = true,
  14. PopInvokedCallback? onPopInvoked,
  15. AdaptiveDialogBuilder? builder,
  16. RouteSettings? routeSettings,
})

Show OK alert dialog, whose appearance is adaptive according to platform

This is convenient wrapper of showAlertDialog. barrierDismissible (default: true) only works for material style, and if it is set to false, pressing OK button is only way to close alert. actionsOverflowDirection works only for Material style currently.

Implementation

Future<OkCancelResult> showOkAlertDialog({
  required BuildContext context,
  String? title,
  String? message,
  String? okLabel,
  bool barrierDismissible = true,
  @Deprecated('Use `style` instead.') AdaptiveStyle? alertStyle,
  AdaptiveStyle? style,
  @Deprecated('Use `ios` instead. Will be removed in v2.')
  bool useActionSheetForCupertino = false,
  bool useActionSheetForIOS = false,
  bool useRootNavigator = true,
  VerticalDirection actionsOverflowDirection = VerticalDirection.up,
  bool fullyCapitalizedForMaterial = true,
  bool canPop = true,
  PopInvokedCallback? onPopInvoked,
  AdaptiveDialogBuilder? builder,
  RouteSettings? routeSettings,
}) async {
  final theme = Theme.of(context);
  final adaptiveStyle = style ?? AdaptiveDialog.instance.defaultStyle;
  final isMacOS = adaptiveStyle.effectiveStyle(theme) == AdaptiveStyle.macOS;
  final result = await showAlertDialog<OkCancelResult>(
    routeSettings: routeSettings,
    context: context,
    title: title,
    message: message,
    barrierDismissible: barrierDismissible,
    style: alertStyle ?? style,
    useActionSheetForIOS: useActionSheetForCupertino || useActionSheetForIOS,
    useRootNavigator: useRootNavigator,
    actionsOverflowDirection: actionsOverflowDirection,
    fullyCapitalizedForMaterial: fullyCapitalizedForMaterial,
    canPop: canPop,
    onPopInvoked: onPopInvoked,
    builder: builder,
    actions: [
      AlertDialogAction(
        label: okLabel ?? MaterialLocalizations.of(context).okButtonLabel,
        key: OkCancelResult.ok,
        isDefaultAction: isMacOS,
      ),
    ],
  );
  return result ?? OkCancelResult.cancel;
}