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();
|
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
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
List<Widget> actions = [];
|
List<Widget> actions = [];
|
||||||
if (widget.plan.id.present)
|
if (widget.plan.id.present)
|
||||||
actions.add(IconButton(
|
actions.add(IconButton(
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
|
bool? confirm = await _showConfirmationDialog(context);
|
||||||
|
if (!confirm!) return;
|
||||||
await db.plans.deleteOne(widget.plan);
|
await db.plans.deleteOne(widget.plan);
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user