130 lines
4.9 KiB
Dart
130 lines
4.9 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:afterwork/data/models/event_model.dart';
|
|
import 'package:afterwork/data/datasources/event_remote_data_source.dart';
|
|
import 'event_card.dart';
|
|
import '../dialogs/add_event_dialog.dart';
|
|
|
|
/// Écran principal pour afficher les événements.
|
|
class EventScreen extends StatelessWidget {
|
|
final EventRemoteDataSource eventRemoteDataSource;
|
|
final String userId;
|
|
final String userName; // Nom de l'utilisateur
|
|
final String userLastName; // Prénom de l'utilisateur
|
|
const EventScreen({
|
|
Key? key,
|
|
required this.eventRemoteDataSource,
|
|
required this.userId,
|
|
required this.userName,
|
|
required this.userLastName,
|
|
}) : super(key: key);
|
|
|
|
@override
|
|
Widget build(BuildContext 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: () async {
|
|
final eventData = await showDialog<Map<String, dynamic>>(
|
|
context: context,
|
|
builder: (BuildContext context) {
|
|
return AddEventDialog(
|
|
userId: userId,
|
|
userName: userName,
|
|
userLastName: userLastName,
|
|
);
|
|
},
|
|
);
|
|
|
|
if (eventData != null) {
|
|
// Appeler l'API pour créer un nouvel événement.
|
|
try {
|
|
print('Tentative de création d\'un nouvel événement par l\'utilisateur $userId');
|
|
await eventRemoteDataSource.createEvent(eventData as EventModel);
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
const SnackBar(content: Text('Événement ajouté avec succès !')),
|
|
);
|
|
} catch (e) {
|
|
print('Erreur lors de la création de l\'événement: $e');
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
SnackBar(content: Text('Erreur : $e')),
|
|
);
|
|
}
|
|
}
|
|
},
|
|
),
|
|
],
|
|
),
|
|
body: FutureBuilder<List<EventModel>>(
|
|
future: eventRemoteDataSource.getAllEvents(),
|
|
builder: (context, snapshot) {
|
|
if (snapshot.connectionState == ConnectionState.waiting) {
|
|
return const Center(child: CircularProgressIndicator());
|
|
} else if (snapshot.hasError) {
|
|
print('Erreur lors de la récupération des événements: ${snapshot.error}');
|
|
return Center(child: Text('Erreur: ${snapshot.error}'));
|
|
} else if (!snapshot.hasData || snapshot.data!.isEmpty) {
|
|
return const Center(child: Text('Aucun événement trouvé.'));
|
|
}
|
|
|
|
final events = snapshot.data!;
|
|
print('Nombre d\'événements récupérés: ${events.length}');
|
|
|
|
return ListView.builder(
|
|
padding: const EdgeInsets.all(16.0),
|
|
itemCount: events.length,
|
|
itemBuilder: (context, index) {
|
|
final event = events[index];
|
|
print('Affichage de l\'événement ${event.id}');
|
|
|
|
return EventCard(
|
|
eventRemoteDataSource: eventRemoteDataSource,
|
|
userId: userId,
|
|
eventId: event.id,
|
|
userName: userName,
|
|
userLastName: userLastName,
|
|
profileImage: 'lib/assets/images/profile_picture.png',
|
|
name: '$userName $userLastName',
|
|
datePosted: 'Posté le 24/08/2024',
|
|
eventTitle: event.title,
|
|
eventDescription: event.description,
|
|
eventImageUrl: event.imageUrl ?? 'lib/assets/images/placeholder.png',
|
|
reactionsCount: 120, // Exemple de valeur
|
|
commentsCount: 45, // Exemple de valeur
|
|
sharesCount: 30, // Exemple de valeur
|
|
onReact: () {
|
|
print('Réaction à l\'événement ${event.id}');
|
|
},
|
|
onComment: () {
|
|
print('Commentaire sur l\'événement ${event.id}');
|
|
},
|
|
onShare: () {
|
|
print('Partage de l\'événement ${event.id}');
|
|
},
|
|
onParticipate: () {
|
|
print('Participation à l\'événement ${event.id}');
|
|
},
|
|
onCloseEvent: () {
|
|
print('Fermeture de l\'événement ${event.id}');
|
|
},
|
|
onMoreOptions: () {
|
|
print('Affichage des options pour l\'événement ${event.id}');
|
|
},
|
|
);
|
|
},
|
|
);
|
|
},
|
|
),
|
|
backgroundColor: const Color(0xFF1E1E2C),
|
|
);
|
|
}
|
|
}
|