askForConfirmation function
Future<bool>
askForConfirmation({
- required BuildContext context,
- required String title,
- required String message,
- required ConfirmationAction action,
- ConfirmationVariant? overridePlatformType,
Asks the user for confirmation before proceeding to a given action using a modal component. By default, this component tries to adhere to the platform's expected behavior.
A modal bottom sheet is used on compact screens while a dialog is preferred on larger screens.
The isDestructiveAction
parameter is used on platforms adhering to the Human
Interface Guidelines (iOS, macOS) to style the action accordingly.
The overridePlatformType
parameter can be used to force a specific platform
variant.
Returns true
if the user confirms the action, false
otherwise.
Implementation
Future<bool> askForConfirmation({
required BuildContext context,
required String title,
required String message,
required ConfirmationAction action,
ConfirmationVariant? overridePlatformType,
}) {
final platformType =
overridePlatformType ?? ConfirmationVariant.from(context);
return switch (platformType) {
ConfirmationVariant.iosCompact =>
_showIosCompact(context, title, message, action),
ConfirmationVariant.iosLarge =>
_showIosLarge(context, title, message, action),
ConfirmationVariant.macos => _showMacos(context, title, message, action),
ConfirmationVariant.material =>
_showMaterial(context, title, message, action),
};
}