showOkAlertDialog function

Future<OkCancelResult> showOkAlertDialog (
  1. {@required BuildContext context,
  2. String title,
  3. String message,
  4. String okLabel,
  5. bool barrierDismissible: true,
  6. AdaptiveStyle alertStyle: AdaptiveStyle.adaptive,
  7. bool useActionSheetForCupertino: false,
  8. bool useRootNavigator: true,
  9. VerticalDirection actionsOverflowDirection: VerticalDirection.up}
)

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,
  AdaptiveStyle alertStyle = AdaptiveStyle.adaptive,
  bool useActionSheetForCupertino = false,
  bool useRootNavigator = true,
  VerticalDirection actionsOverflowDirection = VerticalDirection.up,
}) async {
  final result = await showAlertDialog<OkCancelResult>(
    context: context,
    title: title,
    message: message,
    barrierDismissible: barrierDismissible,
    style: alertStyle,
    useActionSheetForCupertino: useActionSheetForCupertino,
    useRootNavigator: useRootNavigator,
    actionsOverflowDirection: actionsOverflowDirection,
    actions: [
      AlertDialogAction(
        label: okLabel ?? MaterialLocalizations.of(context).okButtonLabel,
        key: OkCancelResult.ok,
      )
    ],
  );
  return result ?? OkCancelResult.cancel;
}