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:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,166 +1,360 @@
|
||||
import 'package:afterwork/presentation/screens/event/event_card.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../../../core/constants/design_system.dart';
|
||||
import '../../../core/constants/env_config.dart';
|
||||
import '../../../core/theme/theme_provider.dart';
|
||||
import '../../../core/utils/page_transitions.dart';
|
||||
import '../../../data/datasources/event_remote_data_source.dart';
|
||||
import '../../state_management/event_bloc.dart';
|
||||
import '../../widgets/animated_widgets.dart';
|
||||
import '../../widgets/custom_button.dart';
|
||||
import '../../widgets/custom_snackbar.dart';
|
||||
import '../../widgets/modern_empty_state.dart';
|
||||
import '../../widgets/shimmer_loading.dart';
|
||||
import '../dialogs/add_event_dialog.dart';
|
||||
import 'event_card.dart';
|
||||
|
||||
/// Écran principal des événements, affichant une liste d'événements.
|
||||
/// Écran principal des événements avec design moderne et compact.
|
||||
///
|
||||
/// Cet écran affiche une liste d'événements avec gestion d'états améliorée,
|
||||
/// animations fluides, et interface utilisateur optimisée.
|
||||
///
|
||||
/// **Fonctionnalités:**
|
||||
/// - Affichage de la liste des événements
|
||||
/// - Création d'événements
|
||||
/// - Actions sur les événements (réaction, participation, etc.)
|
||||
/// - Gestion des états (chargement, erreur, vide)
|
||||
/// - Pull-to-refresh
|
||||
class EventScreen extends StatefulWidget {
|
||||
const EventScreen({
|
||||
required this.userId,
|
||||
required this.userFirstName,
|
||||
required this.userLastName,
|
||||
required this.profileImageUrl,
|
||||
super.key,
|
||||
});
|
||||
|
||||
final String userId;
|
||||
final String userFirstName;
|
||||
final String userLastName;
|
||||
final String profileImageUrl;
|
||||
|
||||
const EventScreen({
|
||||
Key? key,
|
||||
required this.userId,
|
||||
required this.userFirstName,
|
||||
required this.userLastName,
|
||||
required this.profileImageUrl,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
_EventScreenState createState() => _EventScreenState();
|
||||
State<EventScreen> createState() => _EventScreenState();
|
||||
}
|
||||
|
||||
class _EventScreenState extends State<EventScreen> {
|
||||
late final EventRemoteDataSource _eventRemoteDataSource;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
// Charger les événements lors de l'initialisation
|
||||
_eventRemoteDataSource = EventRemoteDataSource(http.Client());
|
||||
_loadEvents();
|
||||
}
|
||||
|
||||
/// Charge les événements au démarrage.
|
||||
void _loadEvents() {
|
||||
context.read<EventBloc>().add(LoadEvents(widget.userId));
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text(
|
||||
'Événements',
|
||||
style: TextStyle(
|
||||
color: Color(0xFF1DBF73), // Définit la couleur verte du texte
|
||||
),
|
||||
),
|
||||
backgroundColor: const Color(0xFF1E1E2C),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.add_circle_outline,
|
||||
size: 28, color: Color(0xFF1DBF73)),
|
||||
onPressed: () {
|
||||
// Naviguer vers une nouvelle page pour ajouter un événement
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => AddEventPage(
|
||||
userId: widget.userId,
|
||||
userFirstName: widget.userFirstName,
|
||||
userLastName: widget.userLastName,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
appBar: _buildAppBar(theme),
|
||||
body: BlocBuilder<EventBloc, EventState>(
|
||||
builder: (context, state) {
|
||||
if (state is EventLoading) {
|
||||
print('[LOG] Chargement en cours des événements...');
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
return _buildLoadingState(theme);
|
||||
} else if (state is EventLoaded) {
|
||||
final events = state.events;
|
||||
print('[LOG] Nombre d\'événements à afficher: ${events.length}');
|
||||
if (events.isEmpty) {
|
||||
return const Center(child: Text('Aucun événement disponible.'));
|
||||
}
|
||||
return ListView.builder(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
itemCount: events.length,
|
||||
itemBuilder: (context, index) {
|
||||
final event = events[index];
|
||||
print('[LOG] Affichage de l\'événement $index : ${event.title}');
|
||||
return EventCard(
|
||||
key: ValueKey(event.id),
|
||||
event: event,
|
||||
userId: widget.userId,
|
||||
userFirstName: widget.userFirstName,
|
||||
userLastName: widget.userLastName,
|
||||
profileImageUrl: widget.profileImageUrl,
|
||||
onReact: () => _onReact(event.id),
|
||||
onComment: () => _onComment(event.id),
|
||||
onShare: () => _onShare(event.id),
|
||||
onParticipate: () => _onParticipate(event.id),
|
||||
onCloseEvent: () => _onCloseEvent(event.id),
|
||||
onReopenEvent: () => _onReopenEvent(event.id),
|
||||
onRemoveEvent: (String eventId) {
|
||||
// Retirer l'événement localement après la fermeture
|
||||
setState(() {
|
||||
// Logique pour retirer l'événement de la liste localement
|
||||
// Par exemple, vous pouvez appeler le bloc ou mettre à jour l'état local ici
|
||||
context.read<EventBloc>().add(RemoveEvent(eventId));
|
||||
});
|
||||
},
|
||||
status: event.status,
|
||||
);
|
||||
},
|
||||
);
|
||||
return _buildLoadedState(context, theme, state);
|
||||
} else if (state is EventError) {
|
||||
print('[ERROR] Message d\'erreur: ${state.message}');
|
||||
return Center(child: Text('Erreur: ${state.message}'));
|
||||
return _buildErrorState(context, theme, state.message);
|
||||
}
|
||||
return const Center(child: Text('Aucun événement disponible.'));
|
||||
return _buildEmptyState(context, theme);
|
||||
},
|
||||
),
|
||||
backgroundColor: const Color(0xFF1E1E2C),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: () {
|
||||
// Recharger les événements
|
||||
context.read<EventBloc>().add(LoadEvents(widget.userId));
|
||||
floatingActionButton: _buildFloatingActionButton(context, theme),
|
||||
);
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// APP BAR
|
||||
// ============================================================================
|
||||
|
||||
/// Construit la barre d'application.
|
||||
PreferredSizeWidget _buildAppBar(ThemeData theme) {
|
||||
return AppBar(
|
||||
elevation: 0,
|
||||
scrolledUnderElevation: 2,
|
||||
title: Text(
|
||||
'Événements',
|
||||
style: theme.textTheme.titleLarge?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
letterSpacing: -0.5,
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.search_rounded, size: 22),
|
||||
tooltip: 'Rechercher',
|
||||
onPressed: _handleSearch,
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.add_circle_outline_rounded, size: 22),
|
||||
tooltip: 'Créer un événement',
|
||||
onPressed: _navigateToCreateEvent,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// ÉTATS
|
||||
// ============================================================================
|
||||
|
||||
/// Construit l'état de chargement avec skeleton loaders.
|
||||
Widget _buildLoadingState(ThemeData theme) {
|
||||
return SkeletonList(
|
||||
itemCount: 3,
|
||||
skeletonWidget: const EventCardSkeleton(),
|
||||
);
|
||||
}
|
||||
|
||||
/// Construit l'état avec événements chargés.
|
||||
Widget _buildLoadedState(
|
||||
BuildContext context,
|
||||
ThemeData theme,
|
||||
EventLoaded state,
|
||||
) {
|
||||
final events = state.events;
|
||||
|
||||
if (events.isEmpty) {
|
||||
return _buildEmptyState(context, theme);
|
||||
}
|
||||
|
||||
return RefreshIndicator(
|
||||
onRefresh: _handleRefresh,
|
||||
color: theme.colorScheme.primary,
|
||||
child: ListView.separated(
|
||||
padding: DesignSystem.paddingAll(DesignSystem.spacingLg),
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
itemCount: events.length,
|
||||
separatorBuilder: (context, index) =>
|
||||
const SizedBox(height: DesignSystem.spacingMd),
|
||||
itemBuilder: (context, index) {
|
||||
final event = events[index];
|
||||
return FadeInWidget(
|
||||
delay: Duration(milliseconds: index * 50),
|
||||
child: EventCard(
|
||||
key: ValueKey(event.id),
|
||||
event: event,
|
||||
userId: widget.userId,
|
||||
userFirstName: widget.userFirstName,
|
||||
userLastName: widget.userLastName,
|
||||
profileImageUrl: widget.profileImageUrl,
|
||||
onReact: () => _handleReact(event.id),
|
||||
onComment: () => _handleComment(event.id),
|
||||
onShare: () => _handleShare(event.id),
|
||||
onParticipate: () => _handleParticipate(event.id),
|
||||
onCloseEvent: () => _handleCloseEvent(event.id),
|
||||
onReopenEvent: () => _handleReopenEvent(event.id),
|
||||
onRemoveEvent: (String eventId) => _handleRemoveEvent(eventId),
|
||||
status: event.status,
|
||||
),
|
||||
);
|
||||
},
|
||||
backgroundColor: const Color(0xFF1DBF73),
|
||||
child: const Icon(Icons.refresh),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _onReact(String eventId) {
|
||||
print('Réaction à l\'événement $eventId');
|
||||
// Implémentez la logique pour réagir à un événement ici
|
||||
/// Construit l'état vide.
|
||||
Widget _buildEmptyState(BuildContext context, ThemeData theme) {
|
||||
return RefreshIndicator(
|
||||
onRefresh: _handleRefresh,
|
||||
color: theme.colorScheme.primary,
|
||||
child: SingleChildScrollView(
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
child: SizedBox(
|
||||
height: MediaQuery.of(context).size.height - 200,
|
||||
child: ModernEmptyState(
|
||||
illustration: EmptyStateIllustration.events,
|
||||
title: 'Aucun événement disponible',
|
||||
description: 'Créez votre premier événement et commencez à organiser des moments inoubliables avec vos amis',
|
||||
actionLabel: 'Créer un événement',
|
||||
onAction: _navigateToCreateEvent,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _onComment(String eventId) {
|
||||
print('Commentaire sur l\'événement $eventId');
|
||||
// Implémentez la logique pour commenter un événement ici
|
||||
/// Construit l'état d'erreur.
|
||||
Widget _buildErrorState(
|
||||
BuildContext context,
|
||||
ThemeData theme,
|
||||
String message,
|
||||
) {
|
||||
return RefreshIndicator(
|
||||
onRefresh: _handleRefresh,
|
||||
color: theme.colorScheme.primary,
|
||||
child: SingleChildScrollView(
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
child: SizedBox(
|
||||
height: MediaQuery.of(context).size.height - 200,
|
||||
child: Center(
|
||||
child: Padding(
|
||||
padding: DesignSystem.paddingAll(DesignSystem.spacingXl),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.error_outline_rounded,
|
||||
size: 56,
|
||||
color: theme.colorScheme.error.withOpacity(0.7),
|
||||
),
|
||||
const SizedBox(height: DesignSystem.spacingLg),
|
||||
Text(
|
||||
'Erreur',
|
||||
style: theme.textTheme.titleMedium?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 17,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: DesignSystem.spacingSm),
|
||||
Text(
|
||||
message,
|
||||
style: theme.textTheme.bodyMedium?.copyWith(
|
||||
color: theme.colorScheme.onSurface.withOpacity(0.6),
|
||||
fontSize: 14,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: DesignSystem.spacingXl),
|
||||
CustomButton(
|
||||
text: 'Réessayer',
|
||||
icon: Icons.refresh_rounded,
|
||||
onPressed: _loadEvents,
|
||||
variant: ButtonVariant.outlined,
|
||||
size: ButtonSize.medium,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _onShare(String eventId) {
|
||||
print('Partage de l\'événement $eventId');
|
||||
// Implémentez la logique pour partager un événement ici
|
||||
// ============================================================================
|
||||
// FLOATING ACTION BUTTON
|
||||
// ============================================================================
|
||||
|
||||
/// Construit le bouton flottant (compact).
|
||||
Widget _buildFloatingActionButton(BuildContext context, ThemeData theme) {
|
||||
return FloatingActionButton(
|
||||
onPressed: _navigateToCreateEvent,
|
||||
tooltip: 'Créer un événement',
|
||||
elevation: 2,
|
||||
child: const Icon(Icons.add_rounded, size: 26),
|
||||
);
|
||||
}
|
||||
|
||||
void _onParticipate(String eventId) {
|
||||
print('Participation à l\'événement $eventId');
|
||||
// Implémentez la logique pour participer à un événement ici
|
||||
// ============================================================================
|
||||
// ACTIONS
|
||||
// ============================================================================
|
||||
|
||||
/// Gère la recherche.
|
||||
void _handleSearch() {
|
||||
context.showInfo('Recherche à venir');
|
||||
}
|
||||
|
||||
void _onCloseEvent(String eventId) {
|
||||
print('Fermeture de l\'événement $eventId');
|
||||
// Appeler le bloc pour fermer l'événement sans recharger la liste entière.
|
||||
/// Navigue vers la création d'événement avec animation.
|
||||
void _navigateToCreateEvent() {
|
||||
context.pushSlideUp(
|
||||
AddEventPage(
|
||||
userId: widget.userId,
|
||||
userFirstName: widget.userFirstName,
|
||||
userLastName: widget.userLastName,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Gère le rafraîchissement.
|
||||
Future<void> _handleRefresh() async {
|
||||
context.read<EventBloc>().add(LoadEvents(widget.userId));
|
||||
await Future.delayed(const Duration(milliseconds: 500));
|
||||
}
|
||||
|
||||
/// Gère la réaction à un événement.
|
||||
Future<void> _handleReact(String eventId) async {
|
||||
try {
|
||||
await _eventRemoteDataSource.reactToEvent(eventId, widget.userId);
|
||||
if (mounted) {
|
||||
context.showSuccess('Réaction enregistrée');
|
||||
// Recharger les événements pour mettre à jour les compteurs
|
||||
context.read<EventBloc>().add(LoadEvents(widget.userId));
|
||||
}
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
context.showError('Erreur lors de la réaction: ${e.toString()}');
|
||||
}
|
||||
if (EnvConfig.enableDetailedLogs) {
|
||||
debugPrint('[EventScreen] Erreur réaction: $e');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Gère le commentaire sur un événement.
|
||||
void _handleComment(String eventId) {
|
||||
context.showInfo('Fonctionnalité de commentaires à venir');
|
||||
}
|
||||
|
||||
/// Gère le partage d'un événement.
|
||||
void _handleShare(String eventId) {
|
||||
context.showInfo('Fonctionnalité de partage à venir');
|
||||
}
|
||||
|
||||
/// Gère la participation à un événement.
|
||||
Future<void> _handleParticipate(String eventId) async {
|
||||
try {
|
||||
await _eventRemoteDataSource.participateInEvent(eventId, widget.userId);
|
||||
if (mounted) {
|
||||
context.showSuccess('Participation enregistrée');
|
||||
// Recharger les événements pour mettre à jour les participants
|
||||
context.read<EventBloc>().add(LoadEvents(widget.userId));
|
||||
}
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
context.showError('Erreur lors de la participation: ${e.toString()}');
|
||||
}
|
||||
if (EnvConfig.enableDetailedLogs) {
|
||||
debugPrint('[EventScreen] Erreur participation: $e');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Gère la fermeture d'un événement.
|
||||
void _handleCloseEvent(String eventId) {
|
||||
context.read<EventBloc>().add(CloseEvent(eventId));
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('L\'événement a été fermé avec succès.')),
|
||||
);
|
||||
context.showSuccess('L\'événement a été fermé avec succès');
|
||||
}
|
||||
|
||||
void _onReopenEvent(String eventId) {
|
||||
print('Réouverture de l\'événement $eventId');
|
||||
// Appeler le bloc pour rouvrir l'événement sans recharger la liste entière.
|
||||
/// Gère la réouverture d'un événement.
|
||||
void _handleReopenEvent(String eventId) {
|
||||
context.read<EventBloc>().add(ReopenEvent(eventId));
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('L\'événement a été rouvert avec succès.')),
|
||||
);
|
||||
context.showSuccess('L\'événement a été rouvert avec succès');
|
||||
}
|
||||
|
||||
|
||||
/// Gère la suppression d'un événement.
|
||||
void _handleRemoveEvent(String eventId) {
|
||||
context.read<EventBloc>().add(RemoveEvent(eventId));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user