Refactor event type handling and add data management page (options and event types)
This commit is contained in:
		
							
								
								
									
										71
									
								
								em2rp/lib/views/widgets/nav/custom_app_bar.dart
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										71
									
								
								em2rp/lib/views/widgets/nav/custom_app_bar.dart
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,71 @@ | ||||
| import 'package:flutter/material.dart'; | ||||
| import 'package:provider/provider.dart'; | ||||
| import 'package:em2rp/providers/local_user_provider.dart'; | ||||
| import 'package:em2rp/utils/colors.dart'; | ||||
|  | ||||
| class CustomAppBar extends StatefulWidget implements PreferredSizeWidget { | ||||
|   final String title; | ||||
|   final List<Widget>? actions; | ||||
|   final bool showLogoutButton; | ||||
|  | ||||
|   const CustomAppBar({ | ||||
|     super.key, | ||||
|     required this.title, | ||||
|     this.actions, | ||||
|     this.showLogoutButton = true, | ||||
|   }); | ||||
|  | ||||
|   @override | ||||
|   State<CustomAppBar> createState() => _CustomAppBarState(); | ||||
|  | ||||
|   @override | ||||
|   Size get preferredSize => const Size.fromHeight(kToolbarHeight); | ||||
| } | ||||
|  | ||||
| class _CustomAppBarState extends State<CustomAppBar> { | ||||
|   @override | ||||
|   Widget build(BuildContext context) { | ||||
|     return AppBar( | ||||
|       title: Text(widget.title), | ||||
|       backgroundColor: AppColors.rouge, | ||||
|       actions: [ | ||||
|         if (widget.showLogoutButton) | ||||
|           IconButton( | ||||
|             icon: const Icon(Icons.logout, color: AppColors.blanc), | ||||
|             onPressed: () async { | ||||
|               // Afficher une boîte de dialogue de confirmation | ||||
|               final shouldLogout = await showDialog<bool>( | ||||
|                 context: context, | ||||
|                 builder: (context) => AlertDialog( | ||||
|                   title: const Text('Déconnexion'), | ||||
|                   content: | ||||
|                       const Text('Voulez-vous vraiment vous déconnecter ?'), | ||||
|                   actions: [ | ||||
|                     TextButton( | ||||
|                       onPressed: () => Navigator.pop(context, false), | ||||
|                       child: const Text('Annuler'), | ||||
|                     ), | ||||
|                     TextButton( | ||||
|                       onPressed: () => Navigator.pop(context, true), | ||||
|                       child: const Text('Déconnexion'), | ||||
|                     ), | ||||
|                   ], | ||||
|                 ), | ||||
|               ); | ||||
|  | ||||
|               if (shouldLogout == true && context.mounted) { | ||||
|                 // Déconnexion | ||||
|                 final provider = | ||||
|                     Provider.of<LocalUserProvider>(context, listen: false); | ||||
|                 await provider.signOut(); | ||||
|                 if (context.mounted) { | ||||
|                   Navigator.of(context).pushReplacementNamed('/login'); | ||||
|                 } | ||||
|               } | ||||
|             }, | ||||
|           ), | ||||
|         if (widget.actions != null) ...widget.actions!, | ||||
|       ], | ||||
|     ); | ||||
|   } | ||||
| } | ||||
| @@ -3,6 +3,7 @@ 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:em2rp/views/data_management_page.dart'; | ||||
| import 'package:flutter/material.dart'; | ||||
| import 'package:em2rp/views/widgets/image/profile_picture.dart'; | ||||
| import 'package:provider/provider.dart'; | ||||
| @@ -133,6 +134,20 @@ class MainDrawer extends StatelessWidget { | ||||
|                         }, | ||||
|                       ), | ||||
|                     ), | ||||
|                     ListTile( | ||||
|                       leading: const Icon(Icons.data_usage), | ||||
|                       title: const Text('Gestion des Données'), | ||||
|                       selected: currentPage == '/data_management', | ||||
|                       selectedColor: AppColors.rouge, | ||||
|                       onTap: () { | ||||
|                         Navigator.pop(context); | ||||
|                         Navigator.pushReplacement( | ||||
|                           context, | ||||
|                           MaterialPageRoute( | ||||
|                               builder: (context) => const DataManagementPage()), | ||||
|                         ); | ||||
|                       }, | ||||
|                     ), | ||||
|                   ], | ||||
|                 ), | ||||
|               ), | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 ElPoyo
					ElPoyo