showConfirmationDialog<T> function

  1. @useResult
Future<T?> showConfirmationDialog<T>({
  1. required BuildContext context,
  2. required String title,
  3. String? message,
  4. String? okLabel,
  5. String? cancelLabel,
  6. double? contentMaxHeight,
  7. List<AlertDialogAction<T>> actions = const [],
  8. T? initialSelectedActionKey,
  9. bool barrierDismissible = true,
  10. AdaptiveStyle? style,
  11. bool useRootNavigator = true,
  12. bool shrinkWrap = true,
  13. bool fullyCapitalizedForMaterial = true,
  14. bool canPop = true,
  15. PopInvokedCallback? onPopInvoked,
  16. AdaptiveDialogBuilder? builder,
  17. RouteSettings? routeSettings,
  18. bool toggleable = true,

Show confirmation dialog, whose appearance is adaptive according to platform

For Cupertino, fallback to ActionSheet.

If shrinkWrap is true, material dialog height is determined by the contents. This argument defaults to true. If you know the content height is taller than the height of screen, it is recommended to set to false for performance optimization. if initialSelectedActionKey is set, corresponding action is selected initially. This works only for Android style. toggleable option is only supported in material dialog. When set to false, the selected action cannot be unselected by tapping. The default value is true.


Future<T?> showConfirmationDialog<T>({
  required BuildContext context,
  required String title,
  String? message,
  String? okLabel,
  String? cancelLabel,
  double? contentMaxHeight,
  List<AlertDialogAction<T>> actions = const [],
  T? initialSelectedActionKey,
  bool barrierDismissible = true,
  AdaptiveStyle? style,
  bool useRootNavigator = true,
  bool shrinkWrap = true,
  bool fullyCapitalizedForMaterial = true,
  bool canPop = true,
  PopInvokedCallback? onPopInvoked,
  AdaptiveDialogBuilder? builder,
  RouteSettings? routeSettings,
  bool toggleable = true,
}) {
  void pop({required BuildContext context, required T? key}) => Navigator.of(
        rootNavigator: useRootNavigator,

  final theme = Theme.of(context);
  final adaptiveStyle = style ?? AdaptiveDialog.instance.defaultStyle;
  return adaptiveStyle.isMaterial(theme)
      ? showModal(
          context: context,
          useRootNavigator: useRootNavigator,
          routeSettings: routeSettings,
          configuration: FadeScaleTransitionConfiguration(
            barrierDismissible: barrierDismissible,
          builder: (context) {
            final dialog = _ConfirmationMaterialDialog(
              title: title,
              onSelect: (key) => pop(context: context, key: key),
              message: message,
              okLabel: okLabel,
              cancelLabel: cancelLabel,
              actions: actions,
              initialSelectedActionKey: initialSelectedActionKey,
              contentMaxHeight: contentMaxHeight,
              shrinkWrap: shrinkWrap,
              fullyCapitalized: fullyCapitalizedForMaterial,
              canPop: canPop,
              onPopInvoked: onPopInvoked,
              toggleable: toggleable,
            return builder == null ? dialog : builder(context, dialog);
      : showModalActionSheet(
          context: context,
          title: title,
          message: message,
          cancelLabel: cancelLabel,
          actions: actions.convertToSheetActions(),
          style: style,
          useRootNavigator: useRootNavigator,
          canPop: canPop,
          onPopInvoked: onPopInvoked,
          builder: builder,
          routeSettings: routeSettings,