279 lines
8.2 KiB
Dart
279 lines
8.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:afterwork/data/datasources/event_remote_data_source.dart';
|
|
|
|
/// Widget pour afficher une carte d'événement.
|
|
class EventCard extends StatelessWidget {
|
|
final String eventId;
|
|
final EventRemoteDataSource eventRemoteDataSource;
|
|
final String userId;
|
|
final String userName;
|
|
final String userLastName;
|
|
final String profileImage;
|
|
final String name;
|
|
final String datePosted;
|
|
final String eventTitle;
|
|
final String eventDescription;
|
|
final String eventImageUrl;
|
|
final int reactionsCount;
|
|
final int commentsCount;
|
|
final int sharesCount;
|
|
final VoidCallback onReact;
|
|
final VoidCallback onComment;
|
|
final VoidCallback onShare;
|
|
final VoidCallback onParticipate;
|
|
final VoidCallback onCloseEvent;
|
|
final VoidCallback onMoreOptions;
|
|
|
|
const EventCard({
|
|
Key? key,
|
|
required this.eventId,
|
|
required this.eventRemoteDataSource,
|
|
required this.userId,
|
|
required this.userName,
|
|
required this.userLastName,
|
|
required this.profileImage,
|
|
required this.name,
|
|
required this.datePosted,
|
|
required this.eventTitle,
|
|
required this.eventDescription,
|
|
required this.eventImageUrl,
|
|
required this.reactionsCount,
|
|
required this.commentsCount,
|
|
required this.sharesCount,
|
|
required this.onReact,
|
|
required this.onComment,
|
|
required this.onShare,
|
|
required this.onParticipate,
|
|
required this.onCloseEvent,
|
|
required this.onMoreOptions,
|
|
}) : 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),
|
|
_buildEventDetails(),
|
|
const SizedBox(height: 10),
|
|
_buildEventImage(),
|
|
const SizedBox(height: 10),
|
|
Divider(color: Colors.white.withOpacity(0.2)),
|
|
_buildInteractionRow(),
|
|
const SizedBox(height: 10),
|
|
_buildParticipateButton(),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
/// Construire l'en-tête de la carte avec les informations de l'utilisateur.
|
|
Widget _buildHeader() {
|
|
return Row(
|
|
children: [
|
|
CircleAvatar(
|
|
backgroundImage: AssetImage(profileImage),
|
|
radius: 25,
|
|
),
|
|
const SizedBox(width: 10),
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
name,
|
|
style: const TextStyle(
|
|
color: Colors.white,
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
Text(
|
|
datePosted,
|
|
style: const TextStyle(color: Colors.white70, fontSize: 14),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
IconButton(
|
|
icon: const Icon(Icons.more_vert, color: Colors.white),
|
|
onPressed: _onMoreOptions,
|
|
),
|
|
IconButton(
|
|
icon: const Icon(Icons.close, color: Colors.white),
|
|
onPressed: _onCloseEvent,
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
/// Afficher les détails de l'événement.
|
|
Widget _buildEventDetails() {
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
eventTitle,
|
|
style: const TextStyle(
|
|
color: Colors.white,
|
|
fontSize: 18,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
const SizedBox(height: 5),
|
|
Text(
|
|
eventDescription,
|
|
style: const TextStyle(color: Colors.white70, fontSize: 14),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
/// Afficher l'image de l'événement.
|
|
Widget _buildEventImage() {
|
|
return ClipRRect(
|
|
borderRadius: BorderRadius.circular(10.0),
|
|
child: Image.network(
|
|
eventImageUrl,
|
|
height: 180,
|
|
width: double.infinity,
|
|
fit: BoxFit.cover,
|
|
errorBuilder: (context, error, stackTrace) {
|
|
print('Erreur de chargement de l\'image: $error');
|
|
return Image.asset(
|
|
'lib/assets/images/placeholder.png',
|
|
height: 180,
|
|
width: double.infinity,
|
|
fit: BoxFit.cover,
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
|
|
/// Afficher les icônes d'interaction (réagir, commenter, partager).
|
|
Widget _buildInteractionRow() {
|
|
return Padding(
|
|
padding: const EdgeInsets.symmetric(vertical: 8.0),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
_buildIconButton(
|
|
icon: Icons.thumb_up_alt_outlined,
|
|
label: 'Réagir',
|
|
count: reactionsCount,
|
|
onPressed: onReact,
|
|
),
|
|
_buildIconButton(
|
|
icon: Icons.comment_outlined,
|
|
label: 'Commenter',
|
|
count: commentsCount,
|
|
onPressed: onComment,
|
|
),
|
|
_buildIconButton(
|
|
icon: Icons.share_outlined,
|
|
label: 'Partager',
|
|
count: sharesCount,
|
|
onPressed: onShare,
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
/// Bouton d'interaction personnalisé.
|
|
Widget _buildIconButton({
|
|
required IconData icon,
|
|
required String label,
|
|
required int count,
|
|
required VoidCallback onPressed,
|
|
}) {
|
|
return Expanded(
|
|
child: 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),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
/// Bouton pour participer à l'événement.
|
|
Widget _buildParticipateButton() {
|
|
return ElevatedButton(
|
|
onPressed: _onParticipate,
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: const Color(0xFF1DBF73),
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(8.0),
|
|
),
|
|
padding: const EdgeInsets.symmetric(vertical: 12.0),
|
|
minimumSize: const Size(double.infinity, 40),
|
|
),
|
|
child: const Text('Participer', style: 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');
|
|
}
|
|
}
|
|
|
|
// 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');
|
|
}
|
|
}
|