refactoring
This commit is contained in:
@@ -1,71 +1,129 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../dialogs/add_event_dialog.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 {
|
||||
const EventScreen({super.key});
|
||||
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'),
|
||||
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: () {
|
||||
_showAddEventDialog(context);
|
||||
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: ListView.builder(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
itemCount: 10,
|
||||
itemBuilder: (context, index) {
|
||||
return EventCard(
|
||||
profileImage: 'lib/assets/images/profile_picture.png',
|
||||
name: 'Nom Prénom',
|
||||
datePosted: 'Posté le 24/08/2024',
|
||||
eventTitle: 'Titre de l\'événement',
|
||||
eventDescription: 'Description détaillée de l\'événement...',
|
||||
eventImageUrl: 'lib/assets/images/profile_picture.png',
|
||||
reactionsCount: 120,
|
||||
commentsCount: 45,
|
||||
sharesCount: 30,
|
||||
onReact: () {
|
||||
// Logique pour réagir à l'événement
|
||||
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}');
|
||||
},
|
||||
);
|
||||
},
|
||||
onComment: () {
|
||||
// Logique pour commenter l'événement
|
||||
},
|
||||
onShare: () {
|
||||
// Logique pour partager l'événement
|
||||
},
|
||||
onParticipate: () {
|
||||
// Logique pour participer à l'événement
|
||||
},
|
||||
onCloseEvent: () {
|
||||
// Logique pour fermer l'événement
|
||||
},
|
||||
onMoreOptions: () {
|
||||
// Logique pour afficher plus d'options
|
||||
},
|
||||
assetImage: 'lib/assets/images/placeholder.png', // Ajoutez ce paramètre requis
|
||||
);
|
||||
},
|
||||
),
|
||||
backgroundColor: const Color(0xFF1E1E2C),
|
||||
);
|
||||
}
|
||||
|
||||
void _showAddEventDialog(BuildContext context) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return const AddEventDialog();
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user