Add confirmation dialog to deleting a plan
This commit is contained in:
parent
4097a79205
commit
cbb2e2c4b0
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue
Block a user