123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- //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<FolderDrawer> {
- List<String> folders = [];
- @override
- void initState() {
- super.initState();
- _fetchFolders();
- }
- Future<void> _fetchFolders() async {
- try {
- List<String> 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<String>(
- context: context,
- position: RelativeRect.fromLTRB(100, 100, overlay.size.width, overlay.size.height),
- items: <PopupMenuEntry<String>>[
- PopupMenuItem<String>(
- value: 'Rename',
- child: Text('Rename Folder'),
- ),
- PopupMenuItem<String>(
- 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: <Widget>[
- 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"),
- ),
- ],
- );
- }
- }
|