Refactoring + Checkpoint

This commit is contained in:
DahoudG
2024-11-17 23:00:18 +00:00
parent 1e888f41e8
commit 77ab8a02a2
56 changed files with 1904 additions and 790 deletions

View File

@@ -1,22 +1,22 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart'; // Pour ThemeProvider
import 'package:provider/provider.dart';
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'; // Écran de notifications
import 'package:afterwork/presentation/screens/notifications/notifications_screen.dart';
import '../../../core/constants/colors.dart';
import '../../../core/theme/theme_provider.dart';
import '../friends/friends_screen.dart'; // Écran des amis
import '../friends/friends_screen.dart';
class HomeScreen extends StatefulWidget {
final EventRemoteDataSource eventRemoteDataSource;
final String userId;
final String userFirstName;
final String userLastName;
final String userProfileImage; // Image de profil de l'utilisateur
final String userProfileImage;
const HomeScreen({
Key? key,
@@ -24,7 +24,7 @@ class HomeScreen extends StatefulWidget {
required this.userId,
required this.userFirstName,
required this.userLastName,
required this.userProfileImage, // Passer l'image de profil ici
required this.userProfileImage,
}) : super(key: key);
@override
@@ -37,7 +37,7 @@ class _HomeScreenState extends State<HomeScreen> with SingleTickerProviderStateM
@override
void initState() {
super.initState();
_tabController = TabController(length: 6, vsync: this); // Ajouter un onglet pour les notifications
_tabController = TabController(length: 6, vsync: this);
}
@override
@@ -47,51 +47,40 @@ class _HomeScreenState extends State<HomeScreen> with SingleTickerProviderStateM
}
void _onMenuSelected(BuildContext context, String option) {
switch (option) {
case 'Publier':
print('Publier sélectionné');
break;
case 'Story':
print('Story sélectionné');
break;
default:
break;
}
print('$option sélectionné'); // Log pour chaque option
}
@override
Widget build(BuildContext context) {
// Accès au ThemeProvider
final themeProvider = Provider.of<ThemeProvider>(context);
return Scaffold(
backgroundColor: AppColors.backgroundColor,
body: NestedScrollView(
headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
return <Widget>[
SliverAppBar(
backgroundColor: AppColors.backgroundColor,
floating: true,
pinned: true,
snap: true,
elevation: 2,
backgroundColor: themeProvider.currentTheme.primaryColor,
leading: Padding(
padding: const EdgeInsets.all(4.0), // Ajustement du padding
padding: const EdgeInsets.all(4.0),
child: Image.asset(
'lib/assets/images/logo.png',
height: 40, // Taille ajustée du logo
height: 40,
),
),
actions: [
_buildActionIcon(Icons.add, 'Publier', context),
_buildActionIcon(Icons.search, 'Rechercher', context),
_buildActionIcon(Icons.message, 'Message', context),
_buildNotificationsIcon(context, 5), // Gérer la logique des notifications ici
// Bouton pour basculer entre les thèmes
_buildNotificationsIcon(context, 105),
Switch(
value: themeProvider.isDarkMode,
onChanged: (value) {
themeProvider.toggleTheme(); // Changer le thème
themeProvider.toggleTheme();
},
activeColor: AppColors.accentColor,
),
@@ -99,23 +88,17 @@ class _HomeScreenState extends State<HomeScreen> with SingleTickerProviderStateM
bottom: TabBar(
controller: _tabController,
indicatorColor: AppColors.lightPrimary,
labelStyle: const TextStyle(
fontSize: 12, // Taille réduite du texte
fontWeight: FontWeight.w500,
),
unselectedLabelStyle: const TextStyle(
fontSize: 11, // Taille ajustée pour les onglets non sélectionnés
),
labelColor: AppColors.lightPrimary,
unselectedLabelColor: AppColors.iconSecondary,
labelStyle: const TextStyle(fontSize: 12, fontWeight: FontWeight.w500),
unselectedLabelStyle: const TextStyle(fontSize: 11),
labelColor: themeProvider.isDarkMode ? AppColors.darkOnPrimary : AppColors.lightOnPrimary,
unselectedLabelColor: themeProvider.isDarkMode ? AppColors.darkIconSecondary : AppColors.lightIconSecondary,
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.people_alt_outlined, size: 24), text: 'Ami(e)s'),
_buildProfileTab(), // Onglet profil
_buildProfileTab(),
],
),
),
@@ -129,10 +112,11 @@ class _HomeScreenState extends State<HomeScreen> with SingleTickerProviderStateM
userId: widget.userId,
userFirstName: widget.userFirstName,
userLastName: widget.userLastName,
profileImageUrl: widget.userProfileImage,
),
const EstablishmentsScreen(),
const SocialScreen(),
FriendsScreen(userId: widget.userId), // Correction ici : passer l'userId
FriendsScreen(userId: widget.userId),
const ProfileScreen(),
],
),
@@ -140,20 +124,19 @@ class _HomeScreenState extends State<HomeScreen> with SingleTickerProviderStateM
);
}
// 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,
color: AppColors.secondary,
width: 2.0,
),
),
child: CircleAvatar(
radius: 16,
backgroundColor: Colors.grey[200], // Couleur de fond par défaut
backgroundColor: AppColors.surface,
child: ClipOval(
child: FadeInImage.assetNetwork(
placeholder: 'lib/assets/images/user_placeholder.png',
@@ -169,18 +152,17 @@ class _HomeScreenState extends State<HomeScreen> with SingleTickerProviderStateM
);
}
// 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 d'afficher le badge en dehors des limites
clipBehavior: Clip.none,
children: [
CircleAvatar(
backgroundColor: AppColors.surface,
radius: 18,
child: IconButton(
icon: const Icon(Icons.notifications, color: AppColors.darkOnPrimary, size: 20),
icon: Icon(Icons.notifications, color: AppColors.iconPrimary, size: 20),
onPressed: () {
Navigator.push(
context,
@@ -197,21 +179,17 @@ class _HomeScreenState extends State<HomeScreen> with SingleTickerProviderStateM
top: -6,
child: Container(
padding: const EdgeInsets.all(2),
decoration: const BoxDecoration(
decoration: BoxDecoration(
color: Colors.red,
shape: BoxShape.circle,
),
constraints: const BoxConstraints(
constraints: BoxConstraints(
minWidth: 18,
minHeight: 18,
),
child: Text(
notificationCount > 99 ? '99+' : '$notificationCount',
style: const TextStyle(
color: Colors.white,
fontSize: 10,
fontWeight: FontWeight.bold,
),
style: const TextStyle(color: Colors.white, fontSize: 10, fontWeight: FontWeight.bold),
textAlign: TextAlign.center,
),
),
@@ -221,7 +199,6 @@ 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),
@@ -229,7 +206,7 @@ class _HomeScreenState extends State<HomeScreen> with SingleTickerProviderStateM
backgroundColor: AppColors.surface,
radius: 18,
child: IconButton(
icon: Icon(iconData, color: AppColors.darkOnPrimary, size: 20),
icon: Icon(iconData, color: AppColors.iconPrimary, size: 20),
onPressed: () {
_onMenuSelected(context, label);
},