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);