From cbb2e2c4b0e3873b8abbe1bf2676335625f669a8 Mon Sep 17 00:00:00 2001 From: Brandon Presley Date: Sat, 11 Nov 2023 15:18:23 +1300 Subject: [PATCH] Add confirmation dialog to deleting a plan --- lib/edit_plan.dart | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/lib/edit_plan.dart b/lib/edit_plan.dart index 3cbde43..c70df10 100644 --- a/lib/edit_plan.dart +++ b/lib/edit_plan.dart @@ -44,12 +44,41 @@ class _EditPlanPageState extends State { super.dispose(); } + Future _showConfirmationDialog(BuildContext context) { + return showDialog( + context: context, + barrierDismissible: false, + builder: (BuildContext context) { + return AlertDialog( + title: const Text('Confirm Delete'), + content: const Text('Are you sure you want to delete this plan?'), + actions: [ + ElevatedButton( + child: const Text('Yes'), + onPressed: () { + Navigator.pop(context, true); // showDialog() returns true + }, + ), + ElevatedButton( + child: const Text('No'), + onPressed: () { + Navigator.pop(context, false); // showDialog() returns false + }, + ), + ], + ); + }, + ); + } + @override Widget build(BuildContext context) { List actions = []; if (widget.plan.id.present) actions.add(IconButton( onPressed: () async { + bool? confirm = await _showConfirmationDialog(context); + if (!confirm!) return; await db.plans.deleteOne(widget.plan); if (!mounted) return; Navigator.pop(context);