import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; // Pour ThemeProvider import 'package:afterwork/presentation/screens/event/event_screen.dart'; import 'package:afterwork/presentation/screens/profile/profile_screen.dart'; import 'package:afterwork/presentation/screens/social/social_screen.dart'; import 'package:afterwork/presentation/screens/establishments/establishments_screen.dart'; import 'package:afterwork/presentation/screens/home/home_content.dart'; import 'package:afterwork/data/datasources/event_remote_data_source.dart'; import 'package:afterwork/presentation/screens/notifications/notifications_screen.dart'; // Importez l'écran de notifications import '../../../core/constants/colors.dart'; import '../../../core/theme/theme_provider.dart'; // Pour basculer le thème class HomeScreen extends StatefulWidget { final EventRemoteDataSource eventRemoteDataSource; final String userId; final String userName; final String userLastName; final String userProfileImage; // Ajouter un champ pour l'image de profil de l'utilisateur const HomeScreen({ Key? key, required this.eventRemoteDataSource, required this.userId, required this.userName, required this.userLastName, required this.userProfileImage, // Passer l'image de profil ici }) : super(key: key); @override _HomeScreenState createState() => _HomeScreenState(); } class _HomeScreenState extends State with SingleTickerProviderStateMixin { late TabController _tabController; @override void initState() { super.initState(); _tabController = TabController(length: 6, vsync: this); // Ajouter un onglet pour les notifications } @override void dispose() { _tabController.dispose(); super.dispose(); } void _onMenuSelected(BuildContext context, String option) { switch (option) { case 'Publier': print('Publier sélectionné'); break; case 'Story': print('Story sélectionné'); break; default: break; } } @override Widget build(BuildContext context) { // Accès au ThemeProvider final themeProvider = Provider.of(context); return Scaffold( body: NestedScrollView( headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) { return [ SliverAppBar( backgroundColor: AppColors.backgroundColor, // Gère dynamiquement la couleur d'arrière-plan floating: true, pinned: true, snap: true, elevation: 2, // Réduction de l'élévation pour un design plus léger leading: Padding( padding: const EdgeInsets.all(4.0), // Réduction du padding child: Image.asset( 'lib/assets/images/logo.png', height: 40, // Taille réduite du logo ), ), actions: [ _buildActionIcon(Icons.add, 'Publier', context), _buildActionIcon(Icons.search, 'Rechercher', context), _buildActionIcon(Icons.message, 'Message', context), _buildNotificationsIcon(context, 45), // Ajout du bouton pour basculer entre les thèmes Switch( value: themeProvider.isDarkMode, onChanged: (value) { themeProvider.toggleTheme(); // Bascule le thème lorsqu'on clique }, activeColor: AppColors.accentColor, ), ], bottom: TabBar( controller: _tabController, indicatorColor: AppColors.lightPrimary, // Tab active en bleu labelStyle: const TextStyle( fontSize: 12, // Réduction de la taille du texte des onglets fontWeight: FontWeight.w500, ), unselectedLabelStyle: const TextStyle( fontSize: 11, // Réduction pour les onglets non sélectionnés ), // Changement des couleurs pour les tabs non sélectionnées et sélectionnées labelColor: AppColors.lightPrimary, // Tab active en bleu unselectedLabelColor: AppColors.iconSecondary, // Tabs non sélectionnées en blanc tabs: [ const Tab(icon: Icon(Icons.home, size: 24), text: 'Accueil'), const Tab(icon: Icon(Icons.event, size: 24), text: 'Événements'), const Tab(icon: Icon(Icons.location_city, size: 24), text: 'Établissements'), const Tab(icon: Icon(Icons.people, size: 24), text: 'Social'), const Tab(icon: Icon(Icons.notifications, size: 24), text: 'Notifications'), _buildProfileTab(), ], ), ), ]; }, body: TabBarView( controller: _tabController, children: [ const HomeContentScreen(), EventScreen( userId: widget.userId, userName: widget.userName, userLastName: widget.userLastName, ), const EstablishmentsScreen(), const SocialScreen(), const NotificationsScreen(), const ProfileScreen(), ], ), ), ); } // Widget pour afficher la photo de profil de l'utilisateur dans l'onglet Tab _buildProfileTab() { return Tab( child: Container( decoration: BoxDecoration( shape: BoxShape.circle, border: Border.all( color: Colors.blue, // Définir la couleur de la bordure ici width: 2.0, ), ), child: CircleAvatar( radius: 16, // Ajustez la taille si nécessaire backgroundColor: Colors.grey[200], // Couleur de fond pour le cas où l'image ne charge pas child: ClipOval( child: FadeInImage.assetNetwork( placeholder: 'lib/assets/images/user_placeholder.png', // Chemin de l'image par défaut image: widget.userProfileImage, fit: BoxFit.cover, imageErrorBuilder: (context, error, stackTrace) { // Si l'image ne charge pas, afficher une image par défaut return Image.asset('lib/assets/images/profile_picture.png', fit: BoxFit.cover); }, ), ), ), ), ); } // Widget pour afficher l'icône de notifications avec un badge si nécessaire Widget _buildNotificationsIcon(BuildContext context, int notificationCount) { return Padding( padding: const EdgeInsets.symmetric(horizontal: 6.0), child: Stack( clipBehavior: Clip.none, // Permet de positionner le badge en dehors des limites du Stack children: [ CircleAvatar( backgroundColor: AppColors.surface, radius: 18, child: IconButton( icon: const Icon(Icons.notifications, color: AppColors.darkOnPrimary, size: 20), onPressed: () { // Rediriger vers l'écran des notifications Navigator.push( context, MaterialPageRoute( builder: (context) => const NotificationsScreen(), ), ); }, ), ), // Affiche le badge si le nombre de notifications est supérieur à 0 if (notificationCount > 0) Positioned( right: -6, top: -6, child: Container( padding: const EdgeInsets.all(2), decoration: const BoxDecoration( color: Colors.red, // Couleur du badge shape: BoxShape.circle, ), constraints: const BoxConstraints( minWidth: 18, minHeight: 18, ), child: Text( notificationCount > 99 ? '99+' : '$notificationCount', // Affiche "99+" si le nombre dépasse 99 style: const TextStyle( color: Colors.white, fontSize: 10, fontWeight: FontWeight.bold, ), textAlign: TextAlign.center, ), ), ), ], ), ); } Widget _buildActionIcon(IconData iconData, String label, BuildContext context) { return Padding( padding: const EdgeInsets.symmetric(horizontal: 6.0), // Réduction de l'espacement child: CircleAvatar( backgroundColor: AppColors.surface, radius: 18, // Réduction de la taille des avatars child: IconButton( icon: Icon(iconData, color: AppColors.darkOnPrimary, size: 20), // Taille réduite de l'icône onPressed: () { _onMenuSelected(context, label); }, ), ), ); } }