Add confirmation dialog to deleting a plan

This commit is contained in:
Brandon Presley 2023-11-11 15:18:23 +13:00
parent 4097a79205
commit cbb2e2c4b0
1 changed files with 29 additions and 0 deletions

View File

@ -44,12 +44,41 @@ class _EditPlanPageState extends State<EditPlanPage> {
super.dispose();
}
Future<bool?> _showConfirmationDialog(BuildContext context) {
return showDialog<bool>(
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: <Widget>[
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<Widget> 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);