confirmAction method
dynamic
confirmAction(
- dynamic action(), {
- required String title,
- String dismissText = "Cancel",
- CupertinoThemeData? cupertinoThemeData,
- ThemeData? themeData,
- Color barrierColor = kCupertinoModalBarrierColor,
- bool barrierDismissible = true,
- bool semanticsDismissible = false,
- RouteSettings? routeSettings,
- Offset? anchorPoint,
Allow the user to confirm an action
.
Provide a title
for the confirm button. You can also provide a
dismissText
for the cancel button.
E.g.
confirmAction(() {
... perform action
}, title: "Confirm Action", dismissText: "Cancel");
Implementation
confirmAction(
Function() action, {
required String title,
String dismissText = "Cancel",
CupertinoThemeData? cupertinoThemeData,
ThemeData? themeData,
Color barrierColor = kCupertinoModalBarrierColor,
bool barrierDismissible = true,
bool useRootNavigator = true,
bool semanticsDismissible = false,
RouteSettings? routeSettings,
Offset? anchorPoint,
}) {
if (!kIsWeb && Platform.isIOS) {
showCupertinoModalPopup(
barrierColor: barrierColor,
barrierDismissible: barrierDismissible,
useRootNavigator: useRootNavigator,
semanticsDismissible: semanticsDismissible,
routeSettings: routeSettings,
anchorPoint: anchorPoint,
context: context,
builder: (context) {
CupertinoActionSheet cupertinoActionSheet = CupertinoActionSheet(
actions: [
CupertinoActionSheetAction(
isDefaultAction: true,
onPressed: () {
Navigator.pop(context);
action();
},
child: Text(
title,
),
),
],
cancelButton: CupertinoActionSheetAction(
child: Text(
dismissText.tr(),
),
onPressed: () => Navigator.pop(context),
),
);
if (cupertinoThemeData != null) {
return CupertinoTheme(
data: cupertinoThemeData, child: cupertinoActionSheet);
}
return cupertinoActionSheet;
});
return;
}
showDialog(
context: context,
builder: (context) {
AlertDialog alertDialog = AlertDialog(
title: Text(title),
actions: [
TextButton(
onPressed: () {
Navigator.pop(context);
action();
},
child: Text(
title,
),
),
TextButton(
onPressed: () => Navigator.pop(context),
child: Text(
dismissText.tr(),
),
),
],
);
if (themeData != null) {
return Theme(data: themeData, child: alertDialog);
}
return alertDialog;
},
);
}