showPlatformDialog<T> function
Future<T?>
showPlatformDialog<T>({
- required BuildContext context,
- WidgetBuilder? builder,
- WidgetBuilder? materialBuilder,
- WidgetBuilder? cupertinoBuilder,
- PlatformDialogData? platformDialogData,
- MaterialDialogData? materialDialogData,
- PlatformDialogData? cupertinoDialogData,
- Key? materialKey,
- Color? materialBackgroundColor,
- Duration materialInsetAnimationDuration = _kMaterialInsetAnimationDuration,
- Curve materialInsetAnimationCurve = _kMaterialInsetAnimationCurve,
- SemanticsRole materialSemanticsRole = _kMaterialSemanticsRole,
- AlignmentGeometry? materialAlignment,
- ShapeBorder? materialShape,
- Clip? materialClipBehavior,
- BoxConstraints? materialConstraints,
- double? materialElevation,
- EdgeInsets? materialInsetPadding,
- Color? materialShadowColor,
- Color? materialSurfaceTintColor,
Shows a platform-adaptive dialog that renders Material dialogs on Android and Cupertino dialogs on iOS.
This function automatically selects the appropriate dialog implementation based on the target platform:
- On Android: shows a Material dialog using showDialog
- On iOS: shows a Cupertino dialog using showCupertinoDialog
The dialog can be configured with platform-specific data through materialDialogData
and cupertinoDialogData, or with common properties through platformDialogData.
For Material dialogs, the builder is wrapped in a Dialog widget unless
materialDialogData.fullscreenDialog is true.
Example:
showPlatformDialog(
context: context,
builder: (context) => PlatformAlertDialog(
title: Text('Confirm'),
content: Text('Are you sure?'),
actions: [
PlatformDialogAction(
child: Text('Cancel'),
onPressed: () => Navigator.pop(context),
),
PlatformDialogAction(
child: Text('OK'),
onPressed: () => Navigator.pop(context),
),
],
),
)
The following parameters only have an effect for Material dialogs when
materialDialogData.fullscreenDialog is false:
materialAlignment: Alignment of the dialogmaterialShape: Shape of the dialogmaterialClipBehavior: Clip behavior of the dialogmaterialConstraints: Size constraints of the dialogmaterialElevation: Elevation of the dialogmaterialInsetPadding: Padding around the dialogmaterialShadowColor: Shadow color of the dialogmaterialSurfaceTintColor: Surface tint color of the dialog
Implementation
Future<T?> showPlatformDialog<T>({
required BuildContext context,
WidgetBuilder? builder,
WidgetBuilder? materialBuilder,
WidgetBuilder? cupertinoBuilder,
PlatformDialogData? platformDialogData,
MaterialDialogData? materialDialogData,
PlatformDialogData? cupertinoDialogData,
Key? materialKey,
Color? materialBackgroundColor,
Duration materialInsetAnimationDuration = _kMaterialInsetAnimationDuration,
Curve materialInsetAnimationCurve = _kMaterialInsetAnimationCurve,
SemanticsRole materialSemanticsRole = _kMaterialSemanticsRole,
AlignmentGeometry? materialAlignment,
ShapeBorder? materialShape,
Clip? materialClipBehavior,
BoxConstraints? materialConstraints,
double? materialElevation,
EdgeInsets? materialInsetPadding,
Color? materialShadowColor,
Color? materialSurfaceTintColor,
}) {
assert(
(builder == null) ^ (materialBuilder == null),
'Either provide a builder or a materialBuilder.',
);
assert(
(builder == null) ^ (cupertinoBuilder == null),
'Either provide a builder or a cupertinoBuilder.',
);
final resolvedMaterialBuilder = materialBuilder ?? builder!;
final resolvedCupertinoBuilder = cupertinoBuilder ?? builder!;
return _showBasePlatformDialog<T>(
context: context,
materialBuilder: (context) =>
(materialDialogData?.fullscreenDialog ?? MaterialDialogData.kDefaultFullscreenDialog)
? Dialog.fullscreen(
key: materialKey,
backgroundColor: materialBackgroundColor,
insetAnimationDuration: materialInsetAnimationDuration,
insetAnimationCurve: materialInsetAnimationCurve,
semanticsRole: materialSemanticsRole,
child: resolvedMaterialBuilder(context),
)
: Dialog(
key: materialKey,
backgroundColor: materialBackgroundColor,
insetAnimationDuration: materialInsetAnimationDuration,
insetAnimationCurve: materialInsetAnimationCurve,
semanticsRole: materialSemanticsRole,
alignment: materialAlignment,
shape: materialShape,
clipBehavior: materialClipBehavior,
constraints: materialConstraints,
elevation: materialElevation,
insetPadding: materialInsetPadding,
shadowColor: materialShadowColor,
surfaceTintColor: materialSurfaceTintColor,
child: resolvedMaterialBuilder(context),
),
cupertinoBuilder: resolvedCupertinoBuilder,
platformDialogData: platformDialogData,
materialDialogData: materialDialogData,
cupertinoDialogData: cupertinoDialogData,
);
}