show static method
Future<int?>
show({
- required BuildContext context,
- required String title,
- String? message,
- required List<
BaseAlertAction> actions, - int? preferredActionIndex,
- BaseParam? cupertino,
- BaseParam? material,
Shows a native alert dialog.
context: The build context for Material fallback dialogs.title: The title of the alert (required).message: Optional informative text that adds value.actions: List of action buttons (up to 3 recommended).preferredActionIndex: Index of the preferred (default) action.cupertino: Cupertino-specific parameters.material: Material-specific parameters.
Returns the index of the action that was tapped, or null if dismissed.
Implementation
static Future<int?> show({
required BuildContext context,
required String title,
String? message,
required List<BaseAlertAction> actions,
int? preferredActionIndex,
BaseParam? cupertino,
BaseParam? material,
}) async {
if (actions.isEmpty) {
throw ArgumentError('Alert must have at least one action');
}
if (preferredActionIndex != null &&
(preferredActionIndex < 0 || preferredActionIndex >= actions.length)) {
throw ArgumentError('preferredActionIndex out of range');
}
// Determine which platform implementation to use
final bool useCupertino = _shouldUseCupertino(context, cupertino, material);
if (useCupertino) {
// Convert BaseAlertAction to CNAlertAction for iOS
final cnActions = actions.map((action) => action.toCNAlertAction()).toList();
return _showCupertinoNativeAlert(
title: title,
message: message,
actions: cnActions,
preferredActionIndex: preferredActionIndex,
);
} else {
return _showMaterialAlert(
context: context,
title: title,
message: message,
actions: actions,
preferredActionIndex: preferredActionIndex,
);
}
}