show<T> static method
Future<T?>
show<T>({
- required BuildContext context,
- required List<
GlassDialogAction> actions, - String? title,
- String? message,
- Widget? content,
- LiquidGlassSettings? settings,
- GlassQuality? quality,
- bool barrierDismissible = false,
- Color? barrierColor,
- double? maxWidth,
- LiquidShape? shape,
- LiquidShape? actionShape,
- TextStyle? actionTextStyle,
Shows a glass dialog.
Returns a Future that resolves to the value (if any) passed to Navigator.pop when the dialog is dismissed.
Parameters:
context: Build context for showing the dialogtitle: Title text (optional)message: Message text (optional)content: Custom content widget (optional)actions: Action buttons (required, 1-3 actions)settings: Glass effect settings (null uses defaults)quality: Rendering quality (null inherits from the ambient layer or GlassTheme, falling back to standard)barrierDismissible: Whether tapping outside dismisses (default: false)barrierColor: Color of the modal barrier (defaults to the native dimming onios26/ios27, and the Cupertino modal barrier color onclassic)maxWidth: Maximum width of dialog (null follows the active style: 320 onios26/ios27, 280 onclassic)shape: Custom dialog shape (null uses the style default)actionShape: Custom action button shape (null uses the style default)actionTextStyle: Merged over action label styles (role colors still apply)
Example:
final result = await GlassDialog.show<bool>(
context: context,
title: 'Confirm',
message: 'Are you sure?',
actions: [
GlassDialogAction(
label: 'Cancel',
onPressed: () => Navigator.pop(context, false),
),
GlassDialogAction(
label: 'Confirm',
onPressed: () => Navigator.pop(context, true),
),
],
);
Implementation
static Future<T?> show<T>({
required BuildContext context,
required List<GlassDialogAction> actions,
String? title,
String? message,
Widget? content,
LiquidGlassSettings? settings,
GlassQuality? quality,
bool barrierDismissible = false,
Color? barrierColor,
double? maxWidth,
LiquidShape? shape,
LiquidShape? actionShape,
TextStyle? actionTextStyle,
}) {
final capturedGlassTheme = GlassTheme.maybeOf(context)?.data;
final capturedCupertinoTheme = CupertinoTheme.of(context);
final isNative =
GlassThemeHelpers.resolveStyle(context) != GlassStyle.classic;
final isDark = GlassTheme.brightnessOf(context) == Brightness.dark;
final resolvedBarrierColor = barrierColor != null
? CupertinoDynamicColor.resolve(barrierColor, context)
: (isNative
? glassAlertBarrierColor(isDark: isDark)
: CupertinoDynamicColor.resolve(
kCupertinoModalBarrierColor,
context,
));
return pushGlassAlertRoute<T>(
context: context,
barrierDismissible: barrierDismissible,
barrierColor: resolvedBarrierColor,
builder: (dialogContext) {
Widget dialog = GlassDialog(
title: title,
message: message,
content: content,
actions: actions,
settings: settings,
quality: quality,
maxWidth: maxWidth,
shape: shape,
actionShape: actionShape,
actionTextStyle: actionTextStyle,
);
dialog = CupertinoTheme(
data: capturedCupertinoTheme,
child: dialog,
);
if (capturedGlassTheme != null) {
dialog = GlassTheme(
data: capturedGlassTheme,
child: dialog,
);
}
return dialog;
},
);
}