showConfirmationDialog<T> function

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. bool barrierDismissible: true,
  9. AdaptiveStyle style: AdaptiveStyle.adaptive,
  10. bool useRootNavigator: true,
  11. bool shrinkWrap: 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.

Implementation

Future<T> showConfirmationDialog<T>({
  @required BuildContext context,
  @required String title,
  String message,
  String okLabel,
  String cancelLabel,
  double contentMaxHeight,
  List<AlertDialogAction<T>> actions = const [],
  bool barrierDismissible = true,
  AdaptiveStyle style = AdaptiveStyle.adaptive,
  bool useRootNavigator = true,
  bool shrinkWrap = true,
}) {
  void pop(T key) => Navigator.of(
        context,
        rootNavigator: useRootNavigator,
      ).pop(key);
  final theme = Theme.of(context);
  return style.isCupertinoStyle(theme)
      ? showModalActionSheet(
          context: context,
          title: title,
          message: message,
          cancelLabel: cancelLabel,
          actions: actions.convertToSheetActions(),
          style: style,
          useRootNavigator: useRootNavigator,
        )
      : showModal(
          context: context,
          useRootNavigator: useRootNavigator,
          configuration: FadeScaleTransitionConfiguration(
            barrierDismissible: barrierDismissible,
          ),
          builder: (context) => _ConfirmationDialog(
            title: title,
            onSelect: pop,
            message: message,
            okLabel: okLabel,
            cancelLabel: cancelLabel,
            actions: actions,
            contentMaxHeight: contentMaxHeight,
            shrinkWrap: shrinkWrap,
          ),
        );
}