Skip to content

Instantly share code, notes, and snippets.

@jtmuller5
Created May 22, 2021 23:40
Show Gist options
  • Select an option

  • Save jtmuller5/ccba4fa1517f5914f5dd346e8f9b0405 to your computer and use it in GitHub Desktop.

Select an option

Save jtmuller5/ccba4fa1517f5914f5dd346e8f9b0405 to your computer and use it in GitHub Desktop.
Ask the user to approve or cancel an action in a pop-up
Future<bool> askConfirmation({
required BuildContext context,
required String title,
String yes = 'Continue',
String no = 'Cancel',
}) async {
return await showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: Center(child: Text(title)),
actions: [
TextButton(
child: Text(no),
onPressed: () {
appRouter.pop(false);
},
),
TextButton(
child: Text(
yes,
style: TextStyle(color: Colors.red),
),
onPressed: () {
appRouter.pop(true);
},
)
],
);
},
) ??
false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment