make the folder drawer a widget by itself
This commit is contained in:
		
							parent
							
								
									d29650a7d0
								
							
						
					
					
						commit
						afcb58b152
					
				
					 1 changed files with 64 additions and 0 deletions
				
			
		
							
								
								
									
										64
									
								
								lib/folder_drawer.dart
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										64
									
								
								lib/folder_drawer.dart
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,64 @@
 | 
				
			||||||
 | 
					//drawer with the folders for emails a.k.a mailboxes
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import 'package:flutter/material.dart';
 | 
				
			||||||
 | 
					import 'api_service.dart';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					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),
 | 
				
			||||||
 | 
					              onTap: () {
 | 
				
			||||||
 | 
					                widget.onFolderTap(folder);
 | 
				
			||||||
 | 
					                Navigator.pop(context); // Close the drawer after selecting a folder
 | 
				
			||||||
 | 
					              },
 | 
				
			||||||
 | 
					            );
 | 
				
			||||||
 | 
					          }).toList(),
 | 
				
			||||||
 | 
					          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
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					          ),
 | 
				
			||||||
 | 
					        ],
 | 
				
			||||||
 | 
					      ),
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue