173 lines
5.5 KiB
Dart
173 lines
5.5 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:afterwork/data/models/event_model.dart';
|
|
import 'package:afterwork/core/utils/date_formatter.dart'; // Importer DateFormatter
|
|
|
|
/// Widget pour afficher une carte d'événement.
|
|
class EventCard extends StatelessWidget {
|
|
final EventModel event;
|
|
final String userId;
|
|
final String userName;
|
|
final String userLastName;
|
|
final VoidCallback onReact;
|
|
final VoidCallback onComment;
|
|
final VoidCallback onShare;
|
|
final VoidCallback onParticipate;
|
|
final VoidCallback onCloseEvent;
|
|
final VoidCallback onReopenEvent;
|
|
|
|
const EventCard({
|
|
Key? key,
|
|
required this.event,
|
|
required this.userId,
|
|
required this.userName,
|
|
required this.userLastName,
|
|
required this.onReact,
|
|
required this.onComment,
|
|
required this.onShare,
|
|
required this.onParticipate,
|
|
required this.onCloseEvent,
|
|
required this.onReopenEvent,
|
|
}) : 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,
|
|
children: [
|
|
_buildHeader(),
|
|
const SizedBox(height: 10),
|
|
Text(
|
|
event.title,
|
|
style: const TextStyle(color: Colors.white, fontSize: 18, fontWeight: FontWeight.bold),
|
|
),
|
|
const SizedBox(height: 5),
|
|
Text(
|
|
event.description,
|
|
style: const TextStyle(color: Colors.white70, fontSize: 14),
|
|
maxLines: 3,
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
const SizedBox(height: 10),
|
|
_buildEventImage(),
|
|
const Divider(color: Colors.white24),
|
|
_buildInteractionRow(),
|
|
const SizedBox(height: 10),
|
|
_buildStatusAndActions(),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildHeader() {
|
|
// Convertir la date de l'événement (de String à DateTime)
|
|
DateTime? eventDate;
|
|
try {
|
|
eventDate = DateTime.parse(event.startDate);
|
|
} catch (e) {
|
|
eventDate = null; // Gérer le cas où la date ne serait pas valide
|
|
}
|
|
|
|
// Utiliser DateFormatter pour afficher une date lisible si elle est valide
|
|
String formattedDate = eventDate != null ? DateFormatter.formatDate(eventDate) : 'Date inconnue';
|
|
|
|
return Row(
|
|
children: [
|
|
CircleAvatar(backgroundImage: NetworkImage(event.imageUrl ?? 'lib/assets/images/placeholder.png')),
|
|
const SizedBox(width: 10),
|
|
Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
'$userName $userLastName',
|
|
style: const TextStyle(color: Colors.white, fontSize: 16, fontWeight: FontWeight.bold),
|
|
),
|
|
const SizedBox(height: 5),
|
|
Text(
|
|
formattedDate, // Utiliser la date formatée ici
|
|
style: const TextStyle(color: Colors.white70, fontSize: 14),
|
|
),
|
|
],
|
|
),
|
|
const Spacer(),
|
|
IconButton(
|
|
icon: const Icon(Icons.more_vert, color: Colors.white),
|
|
onPressed: () {
|
|
// Logique d'affichage d'options supplémentaires pour l'événement.
|
|
// Vous pouvez utiliser un menu déroulant ou une boîte de dialogue ici.
|
|
},
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
Widget _buildEventImage() {
|
|
return ClipRRect(
|
|
borderRadius: BorderRadius.circular(10.0),
|
|
child: Image.network(
|
|
event.imageUrl ?? 'lib/assets/images/placeholder.png',
|
|
height: 180,
|
|
width: double.infinity,
|
|
fit: BoxFit.cover,
|
|
errorBuilder: (context, error, stackTrace) {
|
|
return Image.asset('lib/assets/images/placeholder.png'); // Image par défaut si erreur de chargement
|
|
}
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildInteractionRow() {
|
|
return Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
|
children: [
|
|
_buildIconButton(Icons.thumb_up_alt_outlined, 'Réagir', event.reactionsCount, onReact),
|
|
_buildIconButton(Icons.comment_outlined, 'Commenter', event.commentsCount, onComment),
|
|
_buildIconButton(Icons.share_outlined, 'Partager', event.sharesCount, onShare),
|
|
],
|
|
);
|
|
}
|
|
|
|
Widget _buildIconButton(IconData icon, String label, int count, VoidCallback onPressed) {
|
|
return TextButton.icon(
|
|
onPressed: onPressed,
|
|
icon: Icon(icon, color: const Color(0xFF1DBF73), size: 20),
|
|
label: Text(
|
|
'$label ($count)',
|
|
style: const TextStyle(color: Colors.white70, fontSize: 12),
|
|
),
|
|
);
|
|
}
|
|
|
|
// Widget pour afficher le statut de l'événement et les actions associées (fermer, réouvrir)
|
|
Widget _buildStatusAndActions() {
|
|
return Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Text(
|
|
event.status == 'closed' ? 'Événement fermé' : 'Événement ouvert',
|
|
style: TextStyle(
|
|
color: event.status == 'closed' ? Colors.red : Colors.green,
|
|
fontSize: 14,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
event.status == 'closed'
|
|
? ElevatedButton(
|
|
onPressed: onReopenEvent,
|
|
child: const Text('Rouvrir l\'événement'),
|
|
)
|
|
: ElevatedButton(
|
|
onPressed: onCloseEvent,
|
|
child: const Text('Fermer l\'événement'),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|