Refactoring et amélioration de la création et l'affichage d'un évènement.

This commit is contained in:
DahoudG
2024-09-02 03:04:40 +00:00
parent b8d7cfcb8d
commit 7bc7761591
9 changed files with 226 additions and 95 deletions

View File

@@ -14,6 +14,7 @@ class EventCard extends StatelessWidget {
final String eventTitle;
final String eventDescription;
final String eventImageUrl;
final String eventStatus; // Ajout du statut de l'événement
final int reactionsCount;
final int commentsCount;
final int sharesCount;
@@ -21,8 +22,8 @@ class EventCard extends StatelessWidget {
final VoidCallback onComment;
final VoidCallback onShare;
final VoidCallback onParticipate;
final VoidCallback onCloseEvent;
final VoidCallback onMoreOptions;
final VoidCallback onCloseEvent;
const EventCard({
Key? key,
@@ -37,6 +38,7 @@ class EventCard extends StatelessWidget {
required this.eventTitle,
required this.eventDescription,
required this.eventImageUrl,
required this.eventStatus, // Initialisation du statut de l'événement
required this.reactionsCount,
required this.commentsCount,
required this.sharesCount,
@@ -44,33 +46,52 @@ class EventCard extends StatelessWidget {
required this.onComment,
required this.onShare,
required this.onParticipate,
required this.onCloseEvent,
required this.onMoreOptions,
required this.onCloseEvent,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Card(
color: const Color(0xFF2C2C3E),
margin: const EdgeInsets.symmetric(vertical: 10.0),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15.0),
),
child: Padding(
padding: const EdgeInsets.all(12.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
return AnimatedOpacity(
opacity: 1.0,
duration: const Duration(milliseconds: 300),
child: Dismissible(
key: ValueKey(eventId),
direction: DismissDirection.startToEnd,
onDismissed: (direction) => onCloseEvent(),
background: Container(
color: Colors.red,
alignment: Alignment.centerLeft,
padding: const EdgeInsets.only(left: 20.0),
child: const Icon(Icons.delete, color: Colors.white),
),
child: Stack(
children: [
_buildHeader(),
const SizedBox(height: 10),
_buildEventDetails(),
const SizedBox(height: 10),
_buildEventImage(),
const SizedBox(height: 10),
Divider(color: Colors.white.withOpacity(0.2)),
_buildInteractionRow(),
const SizedBox(height: 10),
_buildParticipateButton(),
Card(
color: const Color(0xFF2C2C3E),
margin: const EdgeInsets.symmetric(vertical: 10.0),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15.0),
),
child: Padding(
padding: const EdgeInsets.all(12.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_buildHeader(context),
const SizedBox(height: 10),
_buildEventDetails(),
const SizedBox(height: 10),
_buildEventImage(),
const SizedBox(height: 10),
Divider(color: Colors.white.withOpacity(0.2)),
_buildInteractionRow(),
const SizedBox(height: 10),
_buildParticipateButton(),
],
),
),
),
],
),
),
@@ -78,7 +99,7 @@ class EventCard extends StatelessWidget {
}
/// Construire l'en-tête de la carte avec les informations de l'utilisateur.
Widget _buildHeader() {
Widget _buildHeader(BuildContext context) {
return Row(
children: [
CircleAvatar(
@@ -98,21 +119,28 @@ class EventCard extends StatelessWidget {
fontWeight: FontWeight.bold,
),
),
Text(
datePosted,
style: const TextStyle(color: Colors.white70, fontSize: 14),
Row(
children: [
Text(
datePosted,
style: const TextStyle(color: Colors.white70, fontSize: 14),
),
const SizedBox(width: 10),
_buildStatusBadge(), // Badge de statut aligné sur la même ligne que la date du post
],
),
],
),
),
IconButton(
icon: const Icon(Icons.more_vert, color: Colors.white),
onPressed: _onMoreOptions,
),
IconButton(
icon: const Icon(Icons.close, color: Colors.white),
onPressed: _onCloseEvent,
onPressed: onMoreOptions,
),
if (eventStatus != 'CLOSED') // Masquer le bouton de fermeture si l'événement est fermé
IconButton(
icon: const Icon(Icons.close, color: Colors.white),
onPressed: onCloseEvent,
),
],
);
}
@@ -213,7 +241,7 @@ class EventCard extends StatelessWidget {
/// Bouton pour participer à l'événement.
Widget _buildParticipateButton() {
return ElevatedButton(
onPressed: _onParticipate,
onPressed: eventStatus == 'CLOSED' ? null : onParticipate, // Désactiver si l'événement est fermé
style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xFF1DBF73),
shape: RoundedRectangleBorder(
@@ -222,57 +250,40 @@ class EventCard extends StatelessWidget {
padding: const EdgeInsets.symmetric(vertical: 12.0),
minimumSize: const Size(double.infinity, 40),
),
child: const Text('Participer', style: TextStyle(color: Colors.white)),
child: Text(
eventStatus == 'CLOSED' ? 'Événement fermé' : 'Participer',
style: const TextStyle(color: Colors.white),
),
);
}
// Logique pour réagir à l'événement.
void _onReact() async {
try {
print('Tentative de réaction à l\'événement $eventId par l\'utilisateur $userId');
await eventRemoteDataSource.reactToEvent(eventId, userId);
print('Réaction à l\'événement réussie');
// Mettre à jour l'interface utilisateur, par exemple augmenter le compteur de réactions.
} catch (e) {
// Gérer l'erreur.
print('Erreur lors de la réaction à l\'événement: $e');
/// Construire un badge pour afficher le statut de l'événement.
Widget _buildStatusBadge() {
Color badgeColor;
switch (eventStatus) {
case 'CLOSED':
badgeColor = Colors.redAccent;
break;
case 'OPEN':
default:
badgeColor = Colors.greenAccent;
break;
}
}
// Logique pour commenter l'événement.
void _onComment() {
// Implémenter la logique pour commenter un événement.
print('Commentaire sur l\'événement $eventId par l\'utilisateur $userId');
}
// Logique pour partager l'événement.
void _onShare() {
// Implémenter la logique pour partager un événement.
print('Partage de l\'événement $eventId par l\'utilisateur $userId');
}
// Logique pour participer à l'événement.
void _onParticipate() async {
try {
print('Tentative de participation à l\'événement $eventId par l\'utilisateur $userId');
await eventRemoteDataSource.participateInEvent(eventId, userId);
print('Participation à l\'événement réussie');
// Mettre à jour l'interface utilisateur, par exemple afficher un message de succès.
} catch (e) {
// Gérer l'erreur.
print('Erreur lors de la participation à l\'événement: $e');
}
}
// Logique pour fermer l'événement.
void _onCloseEvent() {
// Implémenter la logique pour fermer un événement.
print('Fermeture de l\'événement $eventId');
}
// Logique pour afficher plus d'options.
void _onMoreOptions() {
// Implémenter la logique pour afficher plus d'options.
print('Affichage des options supplémentaires pour l\'événement $eventId');
return Container(
padding: const EdgeInsets.symmetric(horizontal: 8.0, vertical: 4.0),
decoration: BoxDecoration(
color: badgeColor.withOpacity(0.7),
borderRadius: BorderRadius.circular(8.0),
),
child: Text(
eventStatus.toUpperCase(),
style: const TextStyle(
color: Colors.white,
fontSize: 10, // Réduction de la taille du texte
fontWeight: FontWeight.bold,
),
),
);
}
}