confirm dialog when deleting a folder

This commit is contained in:
Juan Marulanda De Los Rios 2025-04-28 20:08:35 -04:00
parent a7c30732f4
commit e104f445ab

View File

@ -90,32 +90,62 @@ class _FolderDrawerState extends State<FolderDrawer> {
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text("Rename Mailbox"),
content: TextField(
controller: _renameController,
decoration: const InputDecoration(
hintText: "New Name",
),
),
actions: <Widget>[
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: <Widget>[
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<void> doubleCheckDelete(String folderTobeDeleted) async {
return showDialog<void>(
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<FolderDrawer> {
} 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"),
)
],
);
}