From e104f445ab1c6ee1b25957c6ee3da349aa10f1ef Mon Sep 17 00:00:00 2001 From: juan Date: Mon, 28 Apr 2025 20:08:35 -0400 Subject: [PATCH] confirm dialog when deleting a folder --- lib/folder_drawer.dart | 81 ++++++++++++++++++++++++++++++------------ 1 file changed, 59 insertions(+), 22 deletions(-) diff --git a/lib/folder_drawer.dart b/lib/folder_drawer.dart index 257a98d..edc7eca 100644 --- a/lib/folder_drawer.dart +++ b/lib/folder_drawer.dart @@ -90,32 +90,62 @@ class _FolderDrawerState extends State { context: context, builder: (BuildContext context) { return AlertDialog( - title: Text("Rename Mailbox"), - content: TextField( - controller: _renameController, - decoration: const InputDecoration( - hintText: "New Name", - ), - ), - actions: [ - TextButton( - onPressed: () { - String newfolderName = _renameController.text; - if (newfolderName.isNotEmpty) { - //make an and to make sure there's two folders with the same name - ApiService().renameFolder(oldFolder, newfolderName); - } - Navigator.of(context).pop(); - }, - child: const Text("Rename"), - ) - ], - ); + title: Text("Rename Mailbox"), + content: TextField( + controller: _renameController, + decoration: const InputDecoration( + hintText: "New Name", + ), + ), + actions: [ + TextButton( + onPressed: () { + String newfolderName = _renameController.text; + if (newfolderName.isNotEmpty) { + //make an and to make sure there's two folders with the same name + ApiService().renameFolder(oldFolder, newfolderName); + } + Navigator.of(context).pop(); + }, + child: const Text("Rename"), + ), + TextButton( + onPressed: () { + Navigator.of(context).pop(); + }, + child: const Text("Cancel"), + ) + ], + ); }); return false; } + Future doubleCheckDelete(String folderTobeDeleted) async { + return showDialog( + context: context, + barrierDismissible: false, + builder: (BuildContext context) { + return AlertDialog( + title: Text("Confirm delete of: $folderTobeDeleted"), + actions: [ + TextButton( + onPressed: () { + ApiService().deleteFolder(folderTobeDeleted); + Navigator.of(context).pop(); + }, + child: Text("Yes")), + TextButton( + onPressed: () { + Navigator.of(context).pop(); + }, + child: Text("No")), + ], + ); + }); + } + void _showOptions(BuildContext context, String folderName) async { final RenderBox overlay = Overlay.of(context).context.findRenderObject() as RenderBox; @@ -143,7 +173,8 @@ class _FolderDrawerState extends State { } else if (value == 'Delete') { // Logic for deleting the folder print("Deleting $folderName"); - ApiService().deleteFolder(folderName); + doubleCheckDelete(folderName); + // ApiService().deleteFolder(folderName); print('Deleted folder'); } }); @@ -179,6 +210,12 @@ class NewMailbox extends StatelessWidget { }, child: const Text("Approve"), ), + TextButton( + onPressed: () { + Navigator.of(context).pop(); + }, + child: const Text("Cancel"), + ) ], ); }