showConfirmationDialog<T> function
Null safety
- {required BuildContext context,
- required String title,
- String? message,
- String? okLabel,
- String? cancelLabel,
- double? contentMaxHeight,
- List<
AlertDialogAction< actions = const [],T> > - T? initialSelectedActionKey,
- bool barrierDismissible = true,
- AdaptiveStyle? style,
- bool shrinkWrap = true,
- bool fullyCapitalizedForMaterial = true,
- WillPopCallback? onWillPop,
- AdaptiveDialogBuilder? builder,
- RouteSettings? routeSettings}
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.
Implementation
@useResult
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,
WillPopCallback? onWillPop,
AdaptiveDialogBuilder? builder,
RouteSettings? routeSettings,
}) {
final navigator = Navigator.of(
context,
rootNavigator: useRootNavigator,
);
void pop(T? key) => navigator.pop(key);
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: pop,
message: message,
okLabel: okLabel,
cancelLabel: cancelLabel,
actions: actions,
initialSelectedActionKey: initialSelectedActionKey,
contentMaxHeight: contentMaxHeight,
shrinkWrap: shrinkWrap,
fullyCapitalized: fullyCapitalizedForMaterial,
onWillPop: onWillPop,
);
return builder == null ? dialog : builder(context, dialog);
},
)
: showModalActionSheet(
context: context,
title: title,
message: message,
cancelLabel: cancelLabel,
actions: actions.convertToSheetActions(),
style: style,
useRootNavigator: useRootNavigator,
onWillPop: onWillPop,
builder: builder,
routeSettings: routeSettings,
);
}