Début refacto en MVVM (Login, drawer OK
This commit is contained in:
		| @@ -1,128 +1,136 @@ | ||||
| import 'package:em2rp/providers/user_provider.dart'; | ||||
| import 'package:em2rp/providers/local_auth_provider.dart'; | ||||
| import 'package:em2rp/utils/colors.dart'; | ||||
| import 'package:em2rp/views/calendar_page.dart'; | ||||
| import 'package:em2rp/views/my_account_page.dart'; | ||||
| import 'package:em2rp/views/user_management_page.dart'; | ||||
| import 'package:flutter/material.dart'; | ||||
| import 'package:em2rp/views/widgets/image/profile_picture.dart'; | ||||
| import 'package:provider/provider.dart'; | ||||
|  | ||||
| class MainDrawer extends StatelessWidget { | ||||
|   final String currentPage; | ||||
|   final UserProvider userProvider; | ||||
|  | ||||
|   const MainDrawer( | ||||
|       {super.key, required this.currentPage, required this.userProvider}); | ||||
|   const MainDrawer({super.key, required this.currentPage}); | ||||
|  | ||||
|   @override | ||||
|   Widget build(BuildContext context) { | ||||
|     return Drawer( | ||||
|       child: ListView( | ||||
|         padding: EdgeInsets.zero, | ||||
|         children: <Widget>[ | ||||
|           DrawerHeader( | ||||
|             // Header du drawer | ||||
|             decoration: BoxDecoration( | ||||
|               image: DecorationImage( | ||||
|                 image: AssetImage('assets/EM2_NsurB.jpg'), | ||||
|                 fit: BoxFit.cover, | ||||
|                 colorFilter: ColorFilter.mode( | ||||
|                   AppColors.noir.withOpacity(0.4), | ||||
|                   BlendMode.darken, | ||||
|                 ), | ||||
|               ), | ||||
|             ), | ||||
|             child: Container( | ||||
|               padding: const EdgeInsets.all(16.0), | ||||
|               alignment: Alignment.bottomLeft, | ||||
|               child: Column( | ||||
|                 // Use Column to arrange logo and user name | ||||
|                 crossAxisAlignment: CrossAxisAlignment.start, | ||||
|                 mainAxisAlignment: MainAxisAlignment.end, | ||||
|                 children: [ | ||||
|                   ProfilePictureWidget( | ||||
|                     userId: userProvider.uid!, | ||||
|                     radius: 30, | ||||
|     return Consumer<LocalAuthProvider>( | ||||
|       builder: (context, userProvider, child) { | ||||
|         final hasUser = userProvider.currentUser != null; | ||||
|  | ||||
|         return Drawer( | ||||
|           child: ListView( | ||||
|             padding: EdgeInsets.zero, | ||||
|             children: <Widget>[ | ||||
|               DrawerHeader( | ||||
|                 decoration: BoxDecoration( | ||||
|                   image: DecorationImage( | ||||
|                     image: AssetImage('assets/EM2_NsurB.jpg'), | ||||
|                     fit: BoxFit.cover, | ||||
|                     colorFilter: ColorFilter.mode( | ||||
|                       AppColors.noir.withOpacity(0.4), | ||||
|                       BlendMode.darken, | ||||
|                     ), | ||||
|                   ), | ||||
|                   const SizedBox(height: 8), | ||||
|                   Text( | ||||
|                     'Bonjour, ${userProvider.firstName ?? 'Erreur'}', | ||||
|                     style: TextStyle( | ||||
|                       color: AppColors.blanc, | ||||
|                       fontSize: 18, | ||||
|                       fontWeight: FontWeight.bold, | ||||
|                       shadows: [ | ||||
|                         Shadow( | ||||
|                           blurRadius: 3.0, | ||||
|                           color: AppColors.noir, | ||||
|                           offset: Offset(1.0, 1.0), | ||||
|                 ), | ||||
|                 child: Container( | ||||
|                   padding: const EdgeInsets.all(16.0), | ||||
|                   alignment: Alignment.bottomLeft, | ||||
|                   child: SingleChildScrollView( | ||||
|                     child: Column( | ||||
|                       crossAxisAlignment: CrossAxisAlignment.start, | ||||
|                       mainAxisAlignment: MainAxisAlignment.end, | ||||
|                       children: [ | ||||
|                         if (hasUser) | ||||
|                           ProfilePictureWidget( | ||||
|                             userId: userProvider.currentUser!.uid, | ||||
|                             radius: 30, | ||||
|                           ) | ||||
|                         else | ||||
|                           CircleAvatar( | ||||
|                             radius: 30, | ||||
|                             child: Icon(Icons.account_circle, size: 45), | ||||
|                           ), | ||||
|                         const SizedBox(height: 8), | ||||
|                         Text( | ||||
|                           hasUser | ||||
|                               ? 'Bonjour, ${userProvider.currentUser!.firstName}' | ||||
|                               : 'Bonjour, Utilisateur', | ||||
|                           style: TextStyle( | ||||
|                             color: AppColors.blanc, | ||||
|                             fontSize: 18, | ||||
|                             fontWeight: FontWeight.bold, | ||||
|                             shadows: [ | ||||
|                               Shadow( | ||||
|                                 blurRadius: 3.0, | ||||
|                                 color: AppColors.noir, | ||||
|                                 offset: Offset(1.0, 1.0), | ||||
|                               ), | ||||
|                             ], | ||||
|                           ), | ||||
|                         ), | ||||
|                       ], | ||||
|                     ), | ||||
|                   ), | ||||
|                 ], | ||||
|                 ), | ||||
|               ), | ||||
|             ), | ||||
|           ), | ||||
|           ListTile( | ||||
|             // Lien vers la page Calendrier | ||||
|             leading: const Icon(Icons.calendar_today), | ||||
|             title: const Text('Calendrier'), | ||||
|             selected: currentPage == '/calendar', | ||||
|             selectedColor: AppColors.rouge, | ||||
|             onTap: () { | ||||
|               Navigator.pop(context); | ||||
|               Navigator.pushReplacement( | ||||
|                 context, | ||||
|                 MaterialPageRoute(builder: (context) => CalendarPage()), | ||||
|               ); | ||||
|             }, | ||||
|           ), | ||||
|           ExpansionTileTheme( | ||||
|             data: const ExpansionTileThemeData( | ||||
|               iconColor: AppColors.noir, | ||||
|               collapsedIconColor: AppColors.noir, | ||||
|             ), | ||||
|             child: ExpansionTile( | ||||
|               leading: const Icon(Icons.settings), | ||||
|               title: const Text('Paramètres'), | ||||
|               children: <Widget>[ | ||||
|                 ListTile( | ||||
|                   leading: const Icon(Icons.account_circle), | ||||
|                   // Lien vers "Mon Compte" | ||||
|                   title: const Text('Mon Compte'), | ||||
|                   selected: currentPage == '/my_account', | ||||
|                   selectedColor: AppColors.rouge, | ||||
|                   onTap: () { | ||||
|                     Navigator.pop(context); | ||||
|                     Navigator.pushReplacement( | ||||
|                       context, | ||||
|                       MaterialPageRoute( | ||||
|                           builder: (context) => const MyAccountPage()), | ||||
|                     ); | ||||
|                   }, | ||||
|               ListTile( | ||||
|                 leading: const Icon(Icons.calendar_today), | ||||
|                 title: const Text('Calendrier'), | ||||
|                 selected: currentPage == '/calendar', | ||||
|                 selectedColor: AppColors.rouge, | ||||
|                 onTap: () { | ||||
|                   Navigator.pop(context); | ||||
|                   Navigator.pushReplacement( | ||||
|                     context, | ||||
|                     MaterialPageRoute(builder: (context) => CalendarPage()), | ||||
|                   ); | ||||
|                 }, | ||||
|               ), | ||||
|               ExpansionTileTheme( | ||||
|                 data: const ExpansionTileThemeData( | ||||
|                   iconColor: AppColors.noir, | ||||
|                   collapsedIconColor: AppColors.noir, | ||||
|                 ), | ||||
|                 ListTile( | ||||
|                   leading: const Icon(Icons.group), | ||||
|                   // Lien vers "Gestion des Utilisateurs" | ||||
|                   title: const Text('Gestion des Utilisateurs'), | ||||
|                   selected: currentPage == | ||||
|                       '/user_management', // Check if current page is UserManagementPage | ||||
|                   selectedColor: AppColors.rouge, | ||||
|                   onTap: () { | ||||
|                     Navigator.pop(context); // Ferme le drawer | ||||
|                     Navigator.pushReplacement( | ||||
|                       // Navigue vers UserManagementPage | ||||
|                       context, | ||||
|                       MaterialPageRoute( | ||||
|                           builder: (context) => const UserManagementPage()), | ||||
|                     ); | ||||
|                   }, | ||||
|                 child: ExpansionTile( | ||||
|                   leading: const Icon(Icons.settings), | ||||
|                   title: const Text('Paramètres'), | ||||
|                   children: <Widget>[ | ||||
|                     ListTile( | ||||
|                       leading: const Icon(Icons.account_circle), | ||||
|                       title: const Text('Mon Compte'), | ||||
|                       selected: currentPage == '/my_account', | ||||
|                       selectedColor: AppColors.rouge, | ||||
|                       onTap: () { | ||||
|                         Navigator.pop(context); | ||||
|                         Navigator.pushReplacement( | ||||
|                           context, | ||||
|                           MaterialPageRoute( | ||||
|                               builder: (context) => const MyAccountPage()), | ||||
|                         ); | ||||
|                       }, | ||||
|                     ), | ||||
|                     ListTile( | ||||
|                       leading: const Icon(Icons.group), | ||||
|                       title: const Text('Gestion des Utilisateurs'), | ||||
|                       selected: currentPage == '/user_management', | ||||
|                       selectedColor: AppColors.rouge, | ||||
|                       onTap: () { | ||||
|                         Navigator.pop(context); | ||||
|                         Navigator.pushReplacement( | ||||
|                           context, | ||||
|                           MaterialPageRoute( | ||||
|                               builder: (context) => const UserManagementPage()), | ||||
|                         ); | ||||
|                       }, | ||||
|                     ), | ||||
|                   ], | ||||
|                 ), | ||||
|               ], | ||||
|             ), | ||||
|               ), | ||||
|             ], | ||||
|           ), | ||||
|         ], | ||||
|       ), | ||||
|         ); | ||||
|       }, | ||||
|     ); | ||||
|   } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user