showGlassConfirmationDialog<T> function
Future<T?>
showGlassConfirmationDialog<T>({
- required BuildContext context,
- required List<
GlassConfirmationDialogAction> actions, - String? title,
- String? message,
- String? cancelLabel,
- bool? showCancelButton,
- GlassMorphAnchor? morphFrom,
- Rect? morphFromRect,
- GlassMenuAlignment? alignment,
- MorphSpeed morphSpeed = MorphSpeed.normal,
- bool barrierDismissible = true,
- Color? barrierColor,
- double? maxWidth,
- LiquidGlassSettings? settings,
- GlassQuality? quality,
- bool platformViewBackdrop = false,
- LiquidShape? shape,
- LiquidShape? actionShape,
- TextStyle? actionTextStyle,
Presents a native iOS 26/27 Liquid Glass confirmation dialog, mirroring
SwiftUI's .confirmationDialog() and UIKit's
UIAlertController(preferredStyle: .actionSheet).
Source-anchored vs. unanchored presentation
- Source-anchored (
morphFromvia GlassMorphTrigger, or explicitmorphFromRect): liquid-morphs directly out of the source trigger into a calibrated240 ptfloating Liquid Glass popover platter with a clear dismiss barrier, omitting the Cancel button by default (since tapping outside dismisses), and retracts back into the trigger with catch recoil on dismissal. - Unanchored (
morphFrom == null && morphFromRect == null): presents the calibrated320 ptcentered Liquid Glass platter with stacked48 ptcapsule actions and a Cancel button included by default at the bottom.
Pass showCancelButton explicitly (true or false) to override the
automatic anchored/unanchored Cancel button rule.
Usage
Anchored to a trigger button (recommended on iOS 26/27)
GlassMorphTrigger(
builder: (context, anchor) => GlassIconButton(
icon: const Icon(CupertinoIcons.trash),
onPressed: () => showGlassConfirmationDialog<void>(
context: context,
morphFrom: anchor,
title: 'Delete Draft?',
message: 'This draft cannot be recovered once deleted.',
actions: [
GlassConfirmationDialogAction(
label: 'Save Draft',
onPressed: _saveDraft,
),
GlassConfirmationDialogAction(
label: 'Delete Draft',
isDestructive: true,
onPressed: _deleteDraft,
),
],
),
),
)
Unanchored (centered platter with Cancel)
await showGlassConfirmationDialog<void>(
context: context,
title: 'Choose Action',
message: 'Pick what to do with this item.',
actions: [
GlassConfirmationDialogAction(label: 'Share', onPressed: _share),
GlassConfirmationDialogAction(
label: 'Delete',
isDestructive: true,
onPressed: _delete,
),
],
);
Implementation
Future<T?> showGlassConfirmationDialog<T>({
required BuildContext context,
required List<GlassConfirmationDialogAction> actions,
String? title,
String? message,
String? cancelLabel,
bool? showCancelButton,
GlassMorphAnchor? morphFrom,
Rect? morphFromRect,
GlassMenuAlignment? alignment,
MorphSpeed morphSpeed = MorphSpeed.normal,
bool barrierDismissible = true,
Color? barrierColor,
double? maxWidth,
LiquidGlassSettings? settings,
GlassQuality? quality,
bool platformViewBackdrop = false,
LiquidShape? shape,
LiquidShape? actionShape,
TextStyle? actionTextStyle,
bool useRootNavigator = true,
}) {
assert(
morphFrom == null || morphFromRect == null,
'Pass either morphFrom (the GlassMorphAnchor from a GlassMorphTrigger) '
'or morphFromRect (an explicit global rect) — not both.',
);
final capturedThemes = CapturedModalThemes.forNavigator(
context,
useRootNavigator: useRootNavigator,
);
final triggerRect = resolveMorphTriggerRect(
morphFrom,
morphFromRect,
callerName: 'showGlassConfirmationDialog',
);
final effectiveShowCancel = showCancelButton ?? (triggerRect == null);
assert(
actions.isNotEmpty || effectiveShowCancel,
'showGlassConfirmationDialog requires at least one action when '
'showCancelButton is false.',
);
final localizations = glassCupertinoLocalizationsOf(context);
final effectiveCancelLabel = cancelLabel ?? localizations.cancelButtonLabel;
if (triggerRect != null) {
final reduceMotion = GlassAccessibilityData.of(context).reduceMotion;
return Navigator.of(context, rootNavigator: useRootNavigator).push<T>(
_GlassConfirmationPopoverRoute<T>(
triggerRect: triggerRect,
anchor: morphFrom,
alignment: alignment,
morphSpeed: morphSpeed,
reduceMotionAtPush: reduceMotion,
barrierDismissible: barrierDismissible,
barrierColorValue: barrierColor,
barrierLabelValue: localizations.modalBarrierDismissLabel,
capturedThemes: capturedThemes,
title: title,
message: message,
actions: actions,
cancelLabel: effectiveCancelLabel,
showCancelButton: effectiveShowCancel,
maxWidth: maxWidth,
glassSettings: settings,
quality: quality,
platformViewBackdrop: platformViewBackdrop,
shape: shape,
actionShape: actionShape,
actionTextStyle: actionTextStyle,
),
);
}
// Unanchored: calibrated 320 pt centered platter with Cancel by default.
final isDark = GlassTheme.brightnessOf(context) == Brightness.dark;
final resolvedBarrierColor = barrierColor != null
? CupertinoDynamicColor.resolve(barrierColor, context)
: glassAlertBarrierColor(isDark: isDark);
return pushGlassAlertRoute<T>(
context: context,
useRootNavigator: useRootNavigator,
barrierDismissible: barrierDismissible,
barrierColor: resolvedBarrierColor,
builder: (modalContext) {
final route = ModalRoute.of(modalContext);
void dismissIfActive() {
if (route != null && route.isCurrent && route.isActive) {
Navigator.of(modalContext).pop();
}
}
return capturedThemes.wrap(
GlassAlertPlatter(
title: title,
message: message,
settings: settings,
quality: quality,
maxWidth: maxWidth,
forceStacked: true,
semanticsRole: SemanticsRole.dialog,
shape: shape,
actionShape: actionShape,
actionTextStyle: actionTextStyle,
actions: _buildPlatterActions(
actions: actions,
showCancelButton: effectiveShowCancel,
cancelLabel: effectiveCancelLabel,
dismissIfActive: dismissIfActive,
),
),
);
},
);
}