//drawer with the folders for emails a.k.a mailboxes import 'package:flutter/material.dart'; import 'api_service.dart'; // ignore: must_be_immutable class FolderDrawer extends StatefulWidget { ApiService apiService; Function(String) onFolderTap; FolderDrawer({required this.apiService, required this.onFolderTap}); @override _FolderDrawerState createState() => _FolderDrawerState(); } class _FolderDrawerState extends State { List folders = []; @override void initState() { super.initState(); _fetchFolders(); } Future _fetchFolders() async { try { List fetchedFolders = await widget.apiService.fetchFolders(); setState(() { folders = fetchedFolders; }); } catch (e) { print('Error fetching folders: $e'); } } @override Widget build(BuildContext context) { return Drawer( child: ListView( padding: EdgeInsets.zero, children: [ ...folders.map((folder) { return ListTile( leading: Icon(Icons.mail), title: Text(folder), trailing: IconButton( icon: Icon(Icons.more_vert), onPressed: () => { ///show options _showOptions(context) }, ), onTap: () { widget.onFolderTap(folder); Navigator.pop( context); // Close the drawer after selecting a folder }, ); }).toList(), ListTile( leading: Icon(Icons.add), title: Text("New Mailbox"), onTap: () { showDialog( context: context, builder: (BuildContext context) { return NewMailbox(apiService: widget.apiService); }, ); // Navigator.of(context).pop(); }, ), ListTile( leading: Icon(Icons.refresh), title: Text('Refresh Folders'), onTap: () { _fetchFolders(); // Refresh folders when this tile is tapped Navigator.pop(context); // Close the drawer after refresh }, ), ], ), ); } void _showOptions(BuildContext context) async { final RenderBox overlay = Overlay.of(context).context.findRenderObject() as RenderBox; await showMenu( context: context, position: RelativeRect.fromLTRB(100, 100, overlay.size.width, overlay.size.height), items: >[ PopupMenuItem( value: 'Rename', child: Text('Rename Folder'), ), PopupMenuItem( value: 'Delete', child: Text('Delete Folder'), ), ], ).then((value) { // Handle the action based on the selected menu item if (value == 'Rename') { // Logic for renaming the folder print('Rename folder'); } else if (value == 'Delete') { // Logic for deleting the folder print('Delete folder'); } }); } } class NewMailbox extends StatelessWidget { final ApiService apiService; // final Function(String) onFolderCreated; final TextEditingController _textFieldController = TextEditingController(); NewMailbox({required this.apiService}); @override Widget build(BuildContext context) { return AlertDialog( title: const Text("Create a new Mailbox"), content: TextField( controller: _textFieldController, decoration: const InputDecoration( hintText: "EPIC FOLDER", // Your custom hint text here ), ), actions: [ TextButton( onPressed: () { print("Folder name: ${_textFieldController.text}"); String folderName = _textFieldController.text; if (folderName.isNotEmpty) { apiService.createFolder(folderName); // onFolderCreated(folderName); } // apiService.createFolder(_textFieldController.text); Navigator.of(context).pop(); }, child: const Text("Approve"), ), ], ); } }