launchConfirmDialog function
generic confirmation dialog
Implementation
@pragma("vm:prefer-inline")
Future<void> launchConfirmDialog(BuildContext context,
{required Widget message,
Icon? icon,
bool showTitle = true,
String title = "Are you sure?",
bool showOkLabel = true,
String okLabel = "Yes",
String denyLabel = "No",
bool callAfter = false,
required void Function() onConfirm,
void Function()? onDeny}) async {
Debug().info(
"Launched a CONFIRM_DIALOG with ${message.hashCode}"); // we use the provided context
await showDialog(
context: context,
builder: (BuildContext context) => AlertDialog(
icon: icon ?? const Icon(Icons.warning_amber_rounded),
title: showTitle ? Text(title) : null,
content: message,
actions: <Widget>[
if (showOkLabel)
TextButton.icon(
icon: const Icon(Icons.check_rounded),
label: Text(okLabel,
style: const TextStyle(
fontWeight: FontWeight.w700)),
onPressed: () {
if (callAfter) {
Navigator.of(context).pop();
onConfirm.call();
Debug().info(
"CONFIRM_DIALOG [${message.hashCode}] ended with CONFIRM");
} else {
onConfirm.call();
Navigator.of(context).pop();
Debug().info(
"CONFIRM_DIALOG [${message.hashCode}] ended with CONFIRM");
}
},
),
TextButton.icon(
icon: const Icon(Icons.not_interested_rounded),
label: Text(denyLabel,
style: const TextStyle(
fontWeight: FontWeight.w700)),
onPressed: () {
onDeny?.call();
Navigator.of(context).pop();
Debug().info(
"CONFIRM_DIALOG [${message.hashCode}] ended with DENY");
},
)
]));
}