showConfirmation function
void
showConfirmation({
- BuildContext? context,
- required String title,
- required String text,
- required void onConfirmPressed(),
- String cancelButtonText = "Cancel",
- String confirmButtonText = "Confirm",
Implementation
void showConfirmation({
BuildContext? context,
required String title,
required String text,
required void Function() onConfirmPressed,
String cancelButtonText = "Cancel",
String confirmButtonText = "Confirm",
}) {
if (context == null && (!state.isContextLoaded || !state.appContext.mounted)) {
assert(false,
"App Context was not loaded or not mounted");
return;
}
if (context != null && !context.mounted) {
assert(false,
"Provided Context was not loaded or not mounted");
return;
}
context = context?? state.appContext;
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text(title),
content: Text(text),
actions: [
TextButton(
child: Text(cancelButtonText),
onPressed: () {
Navigator.of(context).pop();
},
),
TextButton(
child: Text(confirmButtonText),
onPressed: () async {
Navigator.of(context).pop();
onConfirmPressed();
},
),
],
);
},
);
}