refactoring

This commit is contained in:
DahoudG
2024-11-02 15:27:26 +00:00
parent 8e625c1080
commit 9cf96b7acf
44 changed files with 2281 additions and 354 deletions

View File

@@ -6,17 +6,17 @@ 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 'package:afterwork/presentation/screens/notifications/notifications_screen.dart'; // Écran de notifications
import '../../../core/constants/colors.dart';
import '../../../core/theme/theme_provider.dart'; // Pour basculer le thème
import '../../../core/theme/theme_provider.dart';
import '../friends/friends_screen.dart'; // Écran des amis
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
final String userProfileImage; // Image de profil de l'utilisateur
const HomeScreen({
Key? key,
@@ -69,54 +69,53 @@ class _HomeScreenState extends State<HomeScreen> with SingleTickerProviderStateM
headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
return <Widget>[
SliverAppBar(
backgroundColor: AppColors.backgroundColor, // Gère dynamiquement la couleur d'arrière-plan
backgroundColor: AppColors.backgroundColor,
floating: true,
pinned: true,
snap: true,
elevation: 2, // Réduction de l'élévation pour un design plus léger
elevation: 2,
leading: Padding(
padding: const EdgeInsets.all(4.0), // Réduction du padding
padding: const EdgeInsets.all(4.0), // Ajustement du padding
child: Image.asset(
'lib/assets/images/logo.png',
height: 40, // Taille réduite du logo
height: 40, // Taille ajustée du logo
),
),
actions: [
_buildActionIcon(Icons.add, 'Publier', context),
_buildActionIcon(Icons.search, 'Rechercher', context),
_buildActionIcon(Icons.message, 'Message', context),
_buildNotificationsIcon(context, 45),
_buildNotificationsIcon(context, 5), // Gérer la logique des notifications ici
// Ajout du bouton pour basculer entre les thèmes
// Bouton pour basculer entre les thèmes
Switch(
value: themeProvider.isDarkMode,
onChanged: (value) {
themeProvider.toggleTheme(); // Bascule le thème lorsqu'on clique
themeProvider.toggleTheme(); // Changer le thème
},
activeColor: AppColors.accentColor,
),
],
bottom: TabBar(
controller: _tabController,
indicatorColor: AppColors.lightPrimary, // Tab active en bleu
indicatorColor: AppColors.lightPrimary,
labelStyle: const TextStyle(
fontSize: 12, // Réduction de la taille du texte des onglets
fontSize: 12, // Taille réduite du texte
fontWeight: FontWeight.w500,
),
unselectedLabelStyle: const TextStyle(
fontSize: 11, // Réduction pour les onglets non sélectionnés
fontSize: 11, // Taille ajustée 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
labelColor: AppColors.lightPrimary,
unselectedLabelColor: AppColors.iconSecondary,
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(),
const Tab(icon: Icon(Icons.people_alt_outlined, size: 24), text: 'Ami(e)s'),
_buildProfileTab(), // Onglet profil
],
),
),
@@ -133,7 +132,7 @@ class _HomeScreenState extends State<HomeScreen> with SingleTickerProviderStateM
),
const EstablishmentsScreen(),
const SocialScreen(),
const NotificationsScreen(),
FriendsScreen(userId: widget.userId), // Correction ici : passer l'userId
const ProfileScreen(),
],
),
@@ -141,27 +140,26 @@ class _HomeScreenState extends State<HomeScreen> with SingleTickerProviderStateM
);
}
// Widget pour afficher la photo de profil de l'utilisateur dans l'onglet
// Widget pour l'affichage de la photo de profil 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
color: Colors.blue,
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
radius: 16,
backgroundColor: Colors.grey[200], // Couleur de fond par défaut
child: ClipOval(
child: FadeInImage.assetNetwork(
placeholder: 'lib/assets/images/user_placeholder.png', // Chemin de l'image par défaut
placeholder: 'lib/assets/images/user_placeholder.png',
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);
},
),
@@ -171,12 +169,12 @@ class _HomeScreenState extends State<HomeScreen> with SingleTickerProviderStateM
);
}
// Widget pour afficher l'icône de notifications avec un badge si nécessaire
// Icône pour les notifications avec un badge
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
clipBehavior: Clip.none, // Permet d'afficher le badge en dehors des limites
children: [
CircleAvatar(
backgroundColor: AppColors.surface,
@@ -184,7 +182,6 @@ class _HomeScreenState extends State<HomeScreen> with SingleTickerProviderStateM
child: IconButton(
icon: const Icon(Icons.notifications, color: AppColors.darkOnPrimary, size: 20),
onPressed: () {
// Rediriger vers l'écran des notifications
Navigator.push(
context,
MaterialPageRoute(
@@ -194,7 +191,6 @@ class _HomeScreenState extends State<HomeScreen> with SingleTickerProviderStateM
},
),
),
// Affiche le badge si le nombre de notifications est supérieur à 0
if (notificationCount > 0)
Positioned(
right: -6,
@@ -202,7 +198,7 @@ class _HomeScreenState extends State<HomeScreen> with SingleTickerProviderStateM
child: Container(
padding: const EdgeInsets.all(2),
decoration: const BoxDecoration(
color: Colors.red, // Couleur du badge
color: Colors.red,
shape: BoxShape.circle,
),
constraints: const BoxConstraints(
@@ -210,7 +206,7 @@ class _HomeScreenState extends State<HomeScreen> with SingleTickerProviderStateM
minHeight: 18,
),
child: Text(
notificationCount > 99 ? '99+' : '$notificationCount', // Affiche "99+" si le nombre dépasse 99
notificationCount > 99 ? '99+' : '$notificationCount',
style: const TextStyle(
color: Colors.white,
fontSize: 10,
@@ -225,14 +221,15 @@ class _HomeScreenState extends State<HomeScreen> with SingleTickerProviderStateM
);
}
// Icône d'action générique
Widget _buildActionIcon(IconData iconData, String label, BuildContext context) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 6.0), // Réduction de l'espacement
padding: const EdgeInsets.symmetric(horizontal: 6.0),
child: CircleAvatar(
backgroundColor: AppColors.surface,
radius: 18, // Réduction de la taille des avatars
radius: 18,
child: IconButton(
icon: Icon(iconData, color: AppColors.darkOnPrimary, size: 20), // Taille réduite de l'icône
icon: Icon(iconData, color: AppColors.darkOnPrimary, size: 20),
onPressed: () {
_onMenuSelected(context, label);
},