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,32 +1,29 @@
import 'package:flutter/material.dart';
import 'package:logger/logger.dart'; // Pour la gestion des logs.
import '../../../core/constants/design_system.dart';
import '../../../core/constants/env_config.dart';
import '../../../core/utils/date_formatter.dart';
import '../../../data/models/event_model.dart';
import '../../widgets/animated_widgets.dart';
import '../../widgets/event_header.dart';
import '../../widgets/event_image.dart';
import '../../widgets/event_interaction_row.dart';
import '../../widgets/event_status_badge.dart';
import '../../widgets/swipe_background.dart';
/// Widget représentant une carte d'événement affichant les informations
/// principales de l'événement avec diverses options d'interaction.
/// Widget représentant une carte d'événement avec design moderne et compact.
///
/// Cette carte affiche les informations principales de l'événement avec
/// diverses options d'interaction et un design optimisé.
///
/// **Fonctionnalités:**
/// - Affichage des informations de l'événement
/// - Interactions (réagir, commenter, partager, participer)
/// - Actions de fermeture/réouverture
/// - Swipe pour actions rapides
/// - Description expandable
class EventCard extends StatefulWidget {
final EventModel event; // Modèle de données pour l'événement.
final String userId; // ID de l'utilisateur affichant l'événement.
final String userFirstName; // Prénom de l'utilisateur.
final String userLastName; // Nom de l'utilisateur.
final String profileImageUrl; // Image de profile
final String status; // Statut de l'événement (ouvert ou fermé).
final VoidCallback onReact; // Callback pour réagir à l'événement.
final VoidCallback onComment; // Callback pour commenter l'événement.
final VoidCallback onShare; // Callback pour partager l'événement.
final VoidCallback onParticipate; // Callback pour participer à l'événement.
final VoidCallback onCloseEvent; // Callback pour fermer l'événement.
final VoidCallback onReopenEvent; // Callback pour rouvrir l'événement.
final Function onRemoveEvent; // Fonction pour supprimer l'événement.
const EventCard({
Key? key,
required this.event,
required this.userId,
required this.userFirstName,
@@ -40,150 +37,222 @@ class EventCard extends StatefulWidget {
required this.onCloseEvent,
required this.onReopenEvent,
required this.onRemoveEvent,
}) : super(key: key);
super.key,
});
final EventModel event;
final String userId;
final String userFirstName;
final String userLastName;
final String profileImageUrl;
final String status;
final VoidCallback onReact;
final VoidCallback onComment;
final VoidCallback onShare;
final VoidCallback onParticipate;
final VoidCallback onCloseEvent;
final VoidCallback onReopenEvent;
final Function(String) onRemoveEvent;
@override
_EventCardState createState() => _EventCardState();
State<EventCard> createState() => _EventCardState();
}
class _EventCardState extends State<EventCard> {
bool _isExpanded = false; // Contrôle si la description est développée.
static const int _descriptionThreshold = 100; // Limite de caractères.
bool _isClosed = false; // Ajout d'une variable pour suivre l'état de l'événement.
final Logger _logger = Logger();
// ============================================================================
// ÉTATS
// ============================================================================
@override
void initState() {
super.initState();
_isClosed = widget.event.status == 'fermé'; // Initialiser l'état selon le statut de l'événement.
}
bool _isDescriptionExpanded = false;
static const int _descriptionThreshold = 100;
bool get _isClosed => widget.event.status.toLowerCase() == 'fermé';
bool get _shouldTruncateDescription =>
widget.event.description.length > _descriptionThreshold;
// ============================================================================
// BUILD
// ============================================================================
@override
Widget build(BuildContext context) {
_logger.i("Construction de la carte d'événement"); // Log pour la construction du widget.
final GlobalKey menuKey = GlobalKey(); // Clé pour le menu contextuel.
final String descriptionText = widget.event.description; // Description de l'événement.
final bool shouldTruncate = descriptionText.length > _descriptionThreshold; // Détermine si le texte doit être tronqué.
final theme = Theme.of(context);
final menuKey = GlobalKey();
return Dismissible(
key: ValueKey(widget.event.id), // Clé unique pour chaque carte d'événement.
direction: widget.event.status == 'fermé' // Direction du glissement basée sur le statut.
key: ValueKey(widget.event.id),
direction: _isClosed
? DismissDirection.startToEnd
: DismissDirection.endToStart,
onDismissed: (direction) { // Action déclenchée lors d'un glissement.
if (_isClosed) {
_logger.i("Rouverte de l'événement ${widget.event.id}");
widget.onReopenEvent();
setState(() {
_isClosed = false; // Mise à jour de l'état local.
});
} else {
_logger.i("Fermeture de l'événement ${widget.event.id}");
widget.onCloseEvent();
widget.onRemoveEvent(widget.event.id); // Suppression de l'événement.
setState(() {
_isClosed = true; // Mise à jour de l'état local.
});
}
},
background: SwipeBackground( // Arrière-plan pour les actions de glissement.
color: _isClosed ? Colors.green : Colors.red,
icon: _isClosed ? Icons.lock_open : Icons.lock,
label: _isClosed ? 'Rouvrir' : 'Fermer',
),
child: Card(
color: const Color(0xFF2C2C3E), // Couleur de fond de la carte.
margin: const EdgeInsets.symmetric(vertical: 10.0),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(15.0)), // Bordure arrondie.
onDismissed: _handleDismiss,
background: _buildSwipeBackground(),
child: AnimatedCard(
margin: const EdgeInsets.only(bottom: DesignSystem.spacingMd),
borderRadius: DesignSystem.borderRadiusMd,
elevation: 1,
hoverElevation: 3,
padding: EdgeInsets.zero,
child: Padding(
padding: const EdgeInsets.all(12.0), // Marge intérieure de la carte.
padding: const EdgeInsets.all(DesignSystem.spacingLg),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Affichage de l'en-tête de l'événement.
EventHeader(
creatorFirstName: widget.event.creatorFirstName,
creatorLastName: widget.event.creatorLastName,
profileImageUrl: widget.event.profileImageUrl,
eventDate: widget.event.startDate,
imageUrl: widget.event.imageUrl,
menuKey: menuKey,
menuContext: context,
location: widget.event.location,
onClose: () {
_logger.i("Menu de fermeture actionné pour l'événement ${widget.event.id}");
},
),
const Divider(color: Colors.white24), // Ligne de séparation visuelle.
_buildHeader(menuKey),
const SizedBox(height: DesignSystem.spacingMd),
Row(
children: [
const Spacer(), // Pousse le badge de statut à droite.
EventStatusBadge(status: widget.status), // Badge de statut.
Expanded(child: _buildTitle(theme)),
const SizedBox(width: DesignSystem.spacingSm),
_buildStatusBadge(theme),
],
),
Text(
widget.event.title, // Titre de l'événement.
style: const TextStyle(
color: Colors.white,
fontSize: 18,
fontWeight: FontWeight.bold),
),
const SizedBox(height: 5), // Espacement entre le titre et la description.
GestureDetector(
onTap: () {
setState(() {
_isExpanded = !_isExpanded; // Change l'état d'expansion.
});
_logger.i("Changement d'état d'expansion pour la description de l'événement ${widget.event.id}");
},
child: Text(
_isExpanded || !shouldTruncate
? descriptionText
: "${descriptionText.substring(0, _descriptionThreshold)}...",
style: const TextStyle(color: Colors.white70, fontSize: 14),
maxLines: _isExpanded ? null : 3,
overflow: _isExpanded ? TextOverflow.visible : TextOverflow.ellipsis,
),
),
if (shouldTruncate) // Bouton "Afficher plus" si la description est longue.
GestureDetector(
onTap: () {
setState(() {
_isExpanded = !_isExpanded;
});
_logger.i("Affichage de la description complète de l'événement ${widget.event.id}");
},
child: Text(
_isExpanded ? "Afficher moins" : "Afficher plus",
style: const TextStyle(
color: Colors.blue,
fontSize: 10,
fontWeight: FontWeight.bold,
),
),
),
const SizedBox(height: 10), // Espacement avant l'image.
EventImage(imageUrl: widget.event.imageUrl), // Affichage de l'image de l'événement.
const Divider(color: Colors.white24), // Nouvelle ligne de séparation.
// Rangée pour les interactions de l'événement (réagir, commenter, partager).
EventInteractionRow(
onReact: widget.onReact,
onComment: widget.onComment,
onShare: widget.onShare,
reactionsCount: widget.event.reactionsCount,
commentsCount: widget.event.commentsCount,
sharesCount: widget.event.sharesCount,
),
const SizedBox(height: DesignSystem.spacingSm),
_buildDescription(theme),
if (widget.event.imageUrl != null) ...[
const SizedBox(height: DesignSystem.spacingMd),
_buildImage(theme),
],
const SizedBox(height: DesignSystem.spacingMd),
Divider(height: 1, color: theme.dividerColor.withOpacity(0.5)),
const SizedBox(height: DesignSystem.spacingSm),
_buildInteractions(theme),
],
),
),
),
);
}
}
// ============================================================================
// WIDGETS
// ============================================================================
/// Construit l'en-tête de l'événement.
Widget _buildHeader(GlobalKey menuKey) {
return EventHeader(
creatorFirstName: widget.event.creatorFirstName,
creatorLastName: widget.event.creatorLastName,
profileImageUrl: widget.event.profileImageUrl,
eventDate: widget.event.startDate,
imageUrl: widget.event.imageUrl,
menuKey: menuKey,
menuContext: context,
location: widget.event.location,
onClose: () {
if (EnvConfig.enableDetailedLogs) {
debugPrint('[EventCard] Menu fermé pour ${widget.event.id}');
}
},
);
}
/// Construit le badge de statut.
Widget _buildStatusBadge(ThemeData theme) {
return EventStatusBadge(status: widget.status);
}
/// Construit le titre.
Widget _buildTitle(ThemeData theme) {
return Text(
widget.event.title,
style: theme.textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.bold,
fontSize: 17,
height: 1.3,
),
maxLines: 2,
overflow: TextOverflow.ellipsis,
);
}
/// Construit la description avec expansion.
Widget _buildDescription(ThemeData theme) {
final description = widget.event.description;
final displayText = _isDescriptionExpanded || !_shouldTruncateDescription
? description
: '${description.substring(0, _descriptionThreshold)}...';
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
displayText,
style: theme.textTheme.bodySmall?.copyWith(
color: theme.colorScheme.onSurface.withOpacity(0.65),
fontSize: 13,
height: 1.4,
),
maxLines: _isDescriptionExpanded ? null : 2,
overflow: _isDescriptionExpanded
? TextOverflow.visible
: TextOverflow.ellipsis,
),
if (_shouldTruncateDescription) ...[
const SizedBox(height: 2),
GestureDetector(
onTap: _toggleDescription,
child: Text(
_isDescriptionExpanded ? 'Voir moins' : 'Voir plus',
style: theme.textTheme.bodySmall?.copyWith(
color: theme.colorScheme.primary,
fontWeight: FontWeight.w500,
fontSize: 12,
),
),
),
],
],
);
}
/// Construit l'image de l'événement.
Widget _buildImage(ThemeData theme) {
return EventImage(
imageUrl: widget.event.imageUrl,
heroTag: 'event_image_${widget.event.id}',
eventTitle: widget.event.title,
);
}
/// Construit les interactions.
Widget _buildInteractions(ThemeData theme) {
return EventInteractionRow(
onReact: widget.onReact,
onComment: widget.onComment,
onShare: widget.onShare,
reactionsCount: widget.event.reactionsCount,
commentsCount: widget.event.commentsCount,
sharesCount: widget.event.sharesCount,
);
}
/// Construit l'arrière-plan du swipe.
Widget _buildSwipeBackground() {
return SwipeBackground(
color: _isClosed ? Colors.green : Colors.red,
icon: _isClosed ? Icons.lock_open : Icons.lock,
label: _isClosed ? 'Rouvrir' : 'Fermer',
);
}
// ============================================================================
// ACTIONS
// ============================================================================
/// Bascule l'expansion de la description.
void _toggleDescription() {
setState(() {
_isDescriptionExpanded = !_isDescriptionExpanded;
});
}
/// Gère le swipe pour fermer/rouvrir.
void _handleDismiss(DismissDirection direction) {
if (_isClosed) {
widget.onReopenEvent();
} else {
widget.onCloseEvent();
widget.onRemoveEvent(widget.event.id);
}
}
}