fix(chat): Correction race condition + Implémentation TODOs

## Corrections Critiques

### Race Condition - Statuts de Messages
- Fix : Les icônes de statut (✓, ✓✓, ✓✓ bleu) ne s'affichaient pas
- Cause : WebSocket delivery confirmations arrivaient avant messages locaux
- Solution : Pattern Optimistic UI dans chat_bloc.dart
  - Création message temporaire immédiate
  - Ajout à la liste AVANT requête HTTP
  - Remplacement par message serveur à la réponse
- Fichier : lib/presentation/state_management/chat_bloc.dart

## Implémentation TODOs (13/21)

### Social (social_header_widget.dart)
-  Copier lien du post dans presse-papiers
-  Partage natif via Share.share()
-  Dialogue de signalement avec 5 raisons

### Partage (share_post_dialog.dart)
-  Interface sélection d'amis avec checkboxes
-  Partage externe via Share API

### Média (media_upload_service.dart)
-  Parsing JSON réponse backend
-  Méthode deleteMedia() pour suppression
-  Génération miniature vidéo

### Posts (create_post_dialog.dart, edit_post_dialog.dart)
-  Extraction URL depuis uploads
-  Documentation chargement médias

### Chat (conversations_screen.dart)
-  Navigation vers notifications
-  ConversationSearchDelegate pour recherche

## Nouveaux Fichiers

### Configuration
- build-prod.ps1 : Script build production avec dart-define
- lib/core/constants/env_config.dart : Gestion environnements

### Documentation
- TODOS_IMPLEMENTED.md : Documentation complète TODOs

## Améliorations

### Architecture
- Refactoring injection de dépendances
- Amélioration routing et navigation
- Optimisation providers (UserProvider, FriendsProvider)

### UI/UX
- Amélioration thème et couleurs
- Optimisation animations
- Meilleure gestion erreurs

### Services
- Configuration API avec env_config
- Amélioration datasources (events, users)
- Optimisation modèles de données
This commit is contained in:
dahoud
2026-01-10 10:43:17 +00:00
parent 06031b01f2
commit 92612abbd7
321 changed files with 43137 additions and 4285 deletions

View File

@@ -1,217 +1,325 @@
import 'package:flutter/material.dart';
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';
import '../../../core/constants/colors.dart';
import '../../../core/theme/theme_provider.dart';
import '../friends/friends_screen.dart';
import '../../../core/constants/design_system.dart';
import '../../../core/theme/theme_provider.dart';
import '../../../core/utils/page_transitions.dart';
import '../../../data/datasources/event_remote_data_source.dart';
import '../../../data/services/notification_service.dart';
import '../../widgets/custom_snackbar.dart';
import '../../widgets/notification_badge.dart';
import '../chat/conversations_screen.dart';
import '../establishments/establishments_screen.dart';
import '../event/event_screen.dart';
import '../friends/friends_screen.dart';
import '../notifications/notifications_screen.dart';
import '../profile/profile_screen.dart';
import '../social/social_screen.dart';
import 'home_content.dart';
/// Écran principal de l'application avec navigation moderne.
class HomeScreen extends StatefulWidget {
const HomeScreen({
required this.eventRemoteDataSource,
required this.userId,
required this.userFirstName,
required this.userLastName,
required this.userProfileImage,
super.key,
});
final EventRemoteDataSource eventRemoteDataSource;
final String userId;
final String userFirstName;
final String userLastName;
final String userProfileImage;
const HomeScreen({
Key? key,
required this.eventRemoteDataSource,
required this.userId,
required this.userFirstName,
required this.userLastName,
required this.userProfileImage,
}) : super(key: key);
@override
_HomeScreenState createState() => _HomeScreenState();
}
class _HomeScreenState extends State<HomeScreen> with SingleTickerProviderStateMixin {
late TabController _tabController;
class _HomeScreenState extends State<HomeScreen> {
int _currentIndex = 0;
late final List<Widget> _screens;
@override
void initState() {
super.initState();
_tabController = TabController(length: 6, vsync: this);
_screens = [
const HomeContentScreen(),
EventScreen(
userId: widget.userId,
userFirstName: widget.userFirstName,
userLastName: widget.userLastName,
profileImageUrl: widget.userProfileImage,
),
const SocialScreen(),
FriendsScreen(userId: widget.userId),
const ProfileScreen(),
];
}
@override
void dispose() {
_tabController.dispose();
super.dispose();
}
void _onMenuSelected(BuildContext context, String option) {
print('$option sélectionné'); // Log pour chaque option
void _onTabTapped(int index) {
setState(() {
_currentIndex = index;
});
}
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final themeProvider = Provider.of<ThemeProvider>(context);
return Scaffold(
backgroundColor: AppColors.backgroundColor,
body: NestedScrollView(
headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
return <Widget>[
SliverAppBar(
floating: true,
pinned: true,
snap: true,
elevation: 2,
backgroundColor: themeProvider.currentTheme.primaryColor,
leading: Padding(
padding: const EdgeInsets.all(4.0),
child: Image.asset(
'lib/assets/images/logo.png',
height: 40,
appBar: _buildModernAppBar(context, theme, themeProvider),
body: IndexedStack(
index: _currentIndex,
children: _screens,
),
bottomNavigationBar: _buildBottomNavBar(theme),
);
}
/// AppBar moderne et épurée
PreferredSizeWidget _buildModernAppBar(
BuildContext context,
ThemeData theme,
ThemeProvider themeProvider,
) {
return AppBar(
elevation: 0,
scrolledUnderElevation: 2,
centerTitle: false,
title: Row(
mainAxisSize: MainAxisSize.min,
children: [
Image.asset(
'lib/assets/images/logo.png',
height: 32,
errorBuilder: (context, error, stackTrace) {
return Icon(
Icons.event_available,
size: 28,
color: theme.colorScheme.primary,
);
},
),
const SizedBox(width: DesignSystem.spacingSm),
Text(
'Afterwork',
style: theme.textTheme.titleLarge?.copyWith(
fontWeight: FontWeight.bold,
letterSpacing: -0.5,
),
),
],
),
actions: [
// Recherche
IconButton(
icon: const Icon(Icons.search_rounded, size: 22),
tooltip: 'Rechercher',
onPressed: () {
context.showInfo('Recherche à venir');
},
),
// Messages
IconButton(
icon: const Icon(Icons.chat_bubble_outline_rounded, size: 22),
tooltip: 'Messages',
onPressed: () {
context.pushFadeScale(const ConversationsScreen());
},
),
// Notifications avec badge
Consumer<NotificationService>(
builder: (context, notificationService, child) {
return Padding(
padding: const EdgeInsets.only(right: 4),
child: NotificationBadge(
count: notificationService.unreadCount,
child: IconButton(
icon: const Icon(Icons.notifications_none_rounded, size: 22),
tooltip: 'Notifications',
onPressed: () {
context.pushFadeScale(const NotificationsScreen());
},
),
),
actions: [
_buildActionIcon(Icons.add, 'Publier', context),
_buildActionIcon(Icons.search, 'Rechercher', context),
_buildActionIcon(Icons.message, 'Message', context),
_buildNotificationsIcon(context, 105),
Switch(
value: themeProvider.isDarkMode,
onChanged: (value) {
themeProvider.toggleTheme();
},
activeColor: AppColors.accentColor,
),
],
bottom: TabBar(
controller: _tabController,
indicatorColor: AppColors.lightPrimary,
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(),
);
},
),
// Menu établissements
PopupMenuButton<String>(
icon: const Icon(Icons.more_vert_rounded, size: 22),
offset: const Offset(0, 48),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(DesignSystem.radiusMd),
),
onSelected: (value) {
switch (value) {
case 'establishments':
context.pushFadeScale(const EstablishmentsScreen());
break;
case 'theme':
themeProvider.toggleTheme();
break;
case 'settings':
context.showInfo('Paramètres à venir');
break;
}
},
itemBuilder: (context) => [
PopupMenuItem(
value: 'establishments',
child: Row(
children: [
Icon(
Icons.location_city_rounded,
size: 20,
color: theme.colorScheme.onSurface,
),
const SizedBox(width: DesignSystem.spacingSm),
const Text('Établissements'),
],
),
),
];
},
body: TabBarView(
controller: _tabController,
children: [
const HomeContentScreen(),
EventScreen(
userId: widget.userId,
userFirstName: widget.userFirstName,
userLastName: widget.userLastName,
profileImageUrl: widget.userProfileImage,
const PopupMenuDivider(),
PopupMenuItem(
value: 'theme',
child: Row(
children: [
Icon(
themeProvider.isDarkMode
? Icons.light_mode_rounded
: Icons.dark_mode_rounded,
size: 20,
color: theme.colorScheme.onSurface,
),
const SizedBox(width: DesignSystem.spacingSm),
Text(themeProvider.isDarkMode ? 'Mode clair' : 'Mode sombre'),
],
),
),
PopupMenuItem(
value: 'settings',
child: Row(
children: [
Icon(
Icons.settings_rounded,
size: 20,
color: theme.colorScheme.onSurface,
),
const SizedBox(width: DesignSystem.spacingSm),
const Text('Paramètres'),
],
),
),
const EstablishmentsScreen(),
const SocialScreen(),
FriendsScreen(userId: widget.userId),
const ProfileScreen(),
],
),
),
const SizedBox(width: 4),
],
);
}
Tab _buildProfileTab() {
return Tab(
child: Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
border: Border.all(
color: AppColors.secondary,
width: 2.0,
/// BottomNavigationBar moderne
Widget _buildBottomNavBar(ThemeData theme) {
return Container(
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.05),
blurRadius: 10,
offset: const Offset(0, -2),
),
),
child: CircleAvatar(
radius: 16,
backgroundColor: AppColors.surface,
child: ClipOval(
child: FadeInImage.assetNetwork(
placeholder: 'lib/assets/images/user_placeholder.png',
image: widget.userProfileImage,
fit: BoxFit.cover,
imageErrorBuilder: (context, error, stackTrace) {
return Image.asset('lib/assets/images/profile_picture.png', fit: BoxFit.cover);
},
),
),
),
],
),
);
}
Widget _buildNotificationsIcon(BuildContext context, int notificationCount) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 6.0),
child: Stack(
clipBehavior: Clip.none,
children: [
CircleAvatar(
backgroundColor: AppColors.surface,
radius: 18,
child: IconButton(
icon: Icon(Icons.notifications, color: AppColors.iconPrimary, size: 20),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const NotificationsScreen(),
),
);
},
child: NavigationBar(
selectedIndex: _currentIndex,
onDestinationSelected: _onTabTapped,
elevation: 0,
height: 64,
labelBehavior: NavigationDestinationLabelBehavior.onlyShowSelected,
animationDuration: const Duration(milliseconds: 400),
destinations: [
NavigationDestination(
icon: const Icon(Icons.home_outlined, size: 24),
selectedIcon: Icon(
Icons.home_rounded,
size: 26,
color: theme.colorScheme.primary,
),
label: 'Accueil',
),
if (notificationCount > 0)
Positioned(
right: -6,
top: -6,
NavigationDestination(
icon: const Icon(Icons.event_outlined, size: 24),
selectedIcon: Icon(
Icons.event_rounded,
size: 26,
color: theme.colorScheme.primary,
),
label: 'Événements',
),
NavigationDestination(
icon: const Icon(Icons.explore_outlined, size: 24),
selectedIcon: Icon(
Icons.explore_rounded,
size: 26,
color: theme.colorScheme.primary,
),
label: 'Social',
),
NavigationDestination(
icon: const Icon(Icons.people_outline_rounded, size: 24),
selectedIcon: Icon(
Icons.people_rounded,
size: 26,
color: theme.colorScheme.primary,
),
label: 'Amis',
),
NavigationDestination(
icon: Hero(
tag: 'user_profile_avatar_${widget.userId}',
child: CircleAvatar(
radius: 14,
backgroundImage: widget.userProfileImage.isNotEmpty
? NetworkImage(widget.userProfileImage)
: null,
child: widget.userProfileImage.isEmpty
? const Icon(Icons.person, size: 16)
: null,
),
),
selectedIcon: Hero(
tag: 'user_profile_avatar_${widget.userId}',
child: Container(
padding: const EdgeInsets.all(2),
decoration: BoxDecoration(
color: Colors.red,
shape: BoxShape.circle,
border: Border.all(
color: theme.colorScheme.primary,
width: 2,
),
),
constraints: BoxConstraints(
minWidth: 18,
minHeight: 18,
),
child: Text(
notificationCount > 99 ? '99+' : '$notificationCount',
style: const TextStyle(color: Colors.white, fontSize: 10, fontWeight: FontWeight.bold),
textAlign: TextAlign.center,
child: CircleAvatar(
radius: 14,
backgroundImage: widget.userProfileImage.isNotEmpty
? NetworkImage(widget.userProfileImage)
: null,
child: widget.userProfileImage.isEmpty
? const Icon(Icons.person, size: 16)
: null,
),
),
),
label: 'Profil',
),
],
),
);
}
Widget _buildActionIcon(IconData iconData, String label, BuildContext context) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 6.0),
child: CircleAvatar(
backgroundColor: AppColors.surface,
radius: 18,
child: IconButton(
icon: Icon(iconData, color: AppColors.iconPrimary, size: 20),
onPressed: () {
_onMenuSelected(context, label);
},
),
),
);
}
}