Initial commit: unionflow-mobile-apps
Application Flutter complète (sans build artifacts). Signed-off-by: lions dev Team
This commit is contained in:
476
lib/features/events/bloc/evenements_bloc.dart
Normal file
476
lib/features/events/bloc/evenements_bloc.dart
Normal file
@@ -0,0 +1,476 @@
|
||||
/// BLoC pour la gestion des événements
|
||||
library evenements_bloc;
|
||||
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
import 'evenements_event.dart';
|
||||
import 'evenements_state.dart';
|
||||
import '../domain/usecases/get_events.dart';
|
||||
import '../domain/usecases/get_event_by_id.dart';
|
||||
import '../domain/usecases/create_event.dart' as uc;
|
||||
import '../domain/usecases/update_event.dart' as uc;
|
||||
import '../domain/usecases/delete_event.dart' as uc;
|
||||
import '../domain/usecases/register_for_event.dart';
|
||||
import '../domain/usecases/cancel_registration.dart';
|
||||
import '../domain/usecases/get_my_registrations.dart';
|
||||
import '../domain/usecases/get_event_participants.dart';
|
||||
import '../domain/repositories/evenement_repository.dart';
|
||||
|
||||
/// BLoC pour la gestion des événements (Clean Architecture)
|
||||
@injectable
|
||||
class EvenementsBloc extends Bloc<EvenementsEvent, EvenementsState> {
|
||||
final GetEvents _getEvents;
|
||||
final GetEventById _getEventById;
|
||||
final uc.CreateEvent _createEvent;
|
||||
final uc.UpdateEvent _updateEvent;
|
||||
final uc.DeleteEvent _deleteEvent;
|
||||
final RegisterForEvent _registerForEvent;
|
||||
final CancelRegistration _cancelRegistration;
|
||||
final GetMyRegistrations _getMyRegistrations;
|
||||
final GetEventParticipants _getEventParticipants;
|
||||
final IEvenementRepository _repository; // Pour méthodes non-couvertes par use cases
|
||||
|
||||
EvenementsBloc(
|
||||
this._getEvents,
|
||||
this._getEventById,
|
||||
this._createEvent,
|
||||
this._updateEvent,
|
||||
this._deleteEvent,
|
||||
this._registerForEvent,
|
||||
this._cancelRegistration,
|
||||
this._getMyRegistrations,
|
||||
this._getEventParticipants,
|
||||
this._repository,
|
||||
) : super(const EvenementsInitial()) {
|
||||
on<LoadEvenements>(_onLoadEvenements);
|
||||
on<LoadEvenementById>(_onLoadEvenementById);
|
||||
on<CreateEvenement>(_onCreateEvenement);
|
||||
on<UpdateEvenement>(_onUpdateEvenement);
|
||||
on<DeleteEvenement>(_onDeleteEvenement);
|
||||
on<LoadEvenementsAVenir>(_onLoadEvenementsAVenir);
|
||||
on<LoadEvenementsEnCours>(_onLoadEvenementsEnCours);
|
||||
on<LoadEvenementsPasses>(_onLoadEvenementsPasses);
|
||||
on<InscrireEvenement>(_onInscrireEvenement);
|
||||
on<DesinscrireEvenement>(_onDesinscrireEvenement);
|
||||
on<LoadParticipants>(_onLoadParticipants);
|
||||
on<LoadEvenementsStats>(_onLoadEvenementsStats);
|
||||
}
|
||||
|
||||
/// Charge la liste des événements
|
||||
Future<void> _onLoadEvenements(
|
||||
LoadEvenements event,
|
||||
Emitter<EvenementsState> emit,
|
||||
) async {
|
||||
try {
|
||||
if (event.refresh && state is EvenementsLoaded) {
|
||||
final currentState = state as EvenementsLoaded;
|
||||
emit(EvenementsRefreshing(currentState.evenements));
|
||||
} else {
|
||||
emit(const EvenementsLoading());
|
||||
}
|
||||
|
||||
final result = await _getEvents(
|
||||
page: event.page,
|
||||
size: event.size,
|
||||
recherche: event.recherche,
|
||||
);
|
||||
|
||||
emit(EvenementsLoaded(
|
||||
evenements: result.evenements,
|
||||
total: result.total,
|
||||
page: result.page,
|
||||
size: result.size,
|
||||
totalPages: result.totalPages,
|
||||
));
|
||||
} on DioException catch (e) {
|
||||
emit(EvenementsNetworkError(
|
||||
message: _getNetworkErrorMessage(e),
|
||||
code: e.response?.statusCode.toString(),
|
||||
error: e,
|
||||
));
|
||||
} catch (e) {
|
||||
emit(EvenementsError(
|
||||
message: 'Erreur inattendue lors du chargement des événements: $e',
|
||||
error: e,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/// Charge un événement par ID
|
||||
Future<void> _onLoadEvenementById(
|
||||
LoadEvenementById event,
|
||||
Emitter<EvenementsState> emit,
|
||||
) async {
|
||||
try {
|
||||
emit(const EvenementsLoading());
|
||||
|
||||
final evenement = await _getEventById(event.id);
|
||||
|
||||
if (evenement != null) {
|
||||
emit(EvenementDetailLoaded(evenement));
|
||||
} else {
|
||||
emit(const EvenementsError(
|
||||
message: 'Événement non trouvé',
|
||||
code: '404',
|
||||
));
|
||||
}
|
||||
} on DioException catch (e) {
|
||||
emit(EvenementsNetworkError(
|
||||
message: _getNetworkErrorMessage(e),
|
||||
code: e.response?.statusCode.toString(),
|
||||
error: e,
|
||||
));
|
||||
} catch (e) {
|
||||
emit(EvenementsError(
|
||||
message: 'Erreur lors du chargement de l\'événement: $e',
|
||||
error: e,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/// Crée un nouvel événement
|
||||
Future<void> _onCreateEvenement(
|
||||
CreateEvenement event,
|
||||
Emitter<EvenementsState> emit,
|
||||
) async {
|
||||
try {
|
||||
emit(const EvenementsLoading());
|
||||
|
||||
final evenement = await _createEvent(event.evenement);
|
||||
|
||||
emit(EvenementCreated(evenement));
|
||||
} on DioException catch (e) {
|
||||
if (e.response?.statusCode == 400) {
|
||||
final errors = _extractValidationErrors(e.response?.data);
|
||||
emit(EvenementsValidationError(
|
||||
message: 'Erreur de validation',
|
||||
validationErrors: errors,
|
||||
code: '400',
|
||||
));
|
||||
} else {
|
||||
emit(EvenementsNetworkError(
|
||||
message: _getNetworkErrorMessage(e),
|
||||
code: e.response?.statusCode.toString(),
|
||||
error: e,
|
||||
));
|
||||
}
|
||||
} catch (e) {
|
||||
emit(EvenementsError(
|
||||
message: 'Erreur lors de la création de l\'événement: $e',
|
||||
error: e,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/// Met à jour un événement
|
||||
Future<void> _onUpdateEvenement(
|
||||
UpdateEvenement event,
|
||||
Emitter<EvenementsState> emit,
|
||||
) async {
|
||||
try {
|
||||
emit(const EvenementsLoading());
|
||||
|
||||
final evenement = await _updateEvent(event.id, event.evenement);
|
||||
|
||||
emit(EvenementUpdated(evenement));
|
||||
} on DioException catch (e) {
|
||||
if (e.response?.statusCode == 400) {
|
||||
final errors = _extractValidationErrors(e.response?.data);
|
||||
emit(EvenementsValidationError(
|
||||
message: 'Erreur de validation',
|
||||
validationErrors: errors,
|
||||
code: '400',
|
||||
));
|
||||
} else {
|
||||
emit(EvenementsNetworkError(
|
||||
message: _getNetworkErrorMessage(e),
|
||||
code: e.response?.statusCode.toString(),
|
||||
error: e,
|
||||
));
|
||||
}
|
||||
} catch (e) {
|
||||
emit(EvenementsError(
|
||||
message: 'Erreur lors de la mise à jour de l\'événement: $e',
|
||||
error: e,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/// Supprime un événement
|
||||
Future<void> _onDeleteEvenement(
|
||||
DeleteEvenement event,
|
||||
Emitter<EvenementsState> emit,
|
||||
) async {
|
||||
try {
|
||||
emit(const EvenementsLoading());
|
||||
|
||||
await _deleteEvent(event.id);
|
||||
|
||||
emit(EvenementDeleted(event.id));
|
||||
} on DioException catch (e) {
|
||||
emit(EvenementsNetworkError(
|
||||
message: _getNetworkErrorMessage(e),
|
||||
code: e.response?.statusCode.toString(),
|
||||
error: e,
|
||||
));
|
||||
} catch (e) {
|
||||
emit(EvenementsError(
|
||||
message: 'Erreur lors de la suppression de l\'événement: $e',
|
||||
error: e,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/// Charge les événements à venir
|
||||
Future<void> _onLoadEvenementsAVenir(
|
||||
LoadEvenementsAVenir event,
|
||||
Emitter<EvenementsState> emit,
|
||||
) async {
|
||||
try {
|
||||
emit(const EvenementsLoading());
|
||||
|
||||
final result = await _repository.getEvenementsAVenir(
|
||||
page: event.page,
|
||||
size: event.size,
|
||||
);
|
||||
|
||||
emit(EvenementsLoaded(
|
||||
evenements: result.evenements,
|
||||
total: result.total,
|
||||
page: result.page,
|
||||
size: result.size,
|
||||
totalPages: result.totalPages,
|
||||
));
|
||||
} on DioException catch (e) {
|
||||
emit(EvenementsNetworkError(
|
||||
message: _getNetworkErrorMessage(e),
|
||||
code: e.response?.statusCode.toString(),
|
||||
error: e,
|
||||
));
|
||||
} catch (e) {
|
||||
emit(EvenementsError(
|
||||
message: 'Erreur lors du chargement des événements à venir: $e',
|
||||
error: e,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/// Charge les événements en cours
|
||||
Future<void> _onLoadEvenementsEnCours(
|
||||
LoadEvenementsEnCours event,
|
||||
Emitter<EvenementsState> emit,
|
||||
) async {
|
||||
try {
|
||||
emit(const EvenementsLoading());
|
||||
|
||||
final result = await _repository.getEvenementsEnCours(
|
||||
page: event.page,
|
||||
size: event.size,
|
||||
);
|
||||
|
||||
emit(EvenementsLoaded(
|
||||
evenements: result.evenements,
|
||||
total: result.total,
|
||||
page: result.page,
|
||||
size: result.size,
|
||||
totalPages: result.totalPages,
|
||||
));
|
||||
} on DioException catch (e) {
|
||||
emit(EvenementsNetworkError(
|
||||
message: _getNetworkErrorMessage(e),
|
||||
code: e.response?.statusCode.toString(),
|
||||
error: e,
|
||||
));
|
||||
} catch (e) {
|
||||
emit(EvenementsError(
|
||||
message: 'Erreur lors du chargement des événements en cours: $e',
|
||||
error: e,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/// Charge les événements passés
|
||||
Future<void> _onLoadEvenementsPasses(
|
||||
LoadEvenementsPasses event,
|
||||
Emitter<EvenementsState> emit,
|
||||
) async {
|
||||
try {
|
||||
emit(const EvenementsLoading());
|
||||
|
||||
final result = await _repository.getEvenementsPasses(
|
||||
page: event.page,
|
||||
size: event.size,
|
||||
);
|
||||
|
||||
emit(EvenementsLoaded(
|
||||
evenements: result.evenements,
|
||||
total: result.total,
|
||||
page: result.page,
|
||||
size: result.size,
|
||||
totalPages: result.totalPages,
|
||||
));
|
||||
} on DioException catch (e) {
|
||||
emit(EvenementsNetworkError(
|
||||
message: _getNetworkErrorMessage(e),
|
||||
code: e.response?.statusCode.toString(),
|
||||
error: e,
|
||||
));
|
||||
} catch (e) {
|
||||
emit(EvenementsError(
|
||||
message: 'Erreur lors du chargement des événements passés: $e',
|
||||
error: e,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/// S'inscrire à un événement
|
||||
Future<void> _onInscrireEvenement(
|
||||
InscrireEvenement event,
|
||||
Emitter<EvenementsState> emit,
|
||||
) async {
|
||||
try {
|
||||
emit(const EvenementsLoading());
|
||||
|
||||
await _registerForEvent(event.evenementId);
|
||||
|
||||
emit(EvenementInscrit(event.evenementId));
|
||||
} on DioException catch (e) {
|
||||
emit(EvenementsNetworkError(
|
||||
message: _getNetworkErrorMessage(e),
|
||||
code: e.response?.statusCode.toString(),
|
||||
error: e,
|
||||
));
|
||||
} catch (e) {
|
||||
emit(EvenementsError(
|
||||
message: 'Erreur lors de l\'inscription à l\'événement: $e',
|
||||
error: e,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/// Se désinscrire d'un événement
|
||||
Future<void> _onDesinscrireEvenement(
|
||||
DesinscrireEvenement event,
|
||||
Emitter<EvenementsState> emit,
|
||||
) async {
|
||||
try {
|
||||
emit(const EvenementsLoading());
|
||||
|
||||
await _cancelRegistration(event.evenementId);
|
||||
|
||||
emit(EvenementDesinscrit(event.evenementId));
|
||||
} on DioException catch (e) {
|
||||
emit(EvenementsNetworkError(
|
||||
message: _getNetworkErrorMessage(e),
|
||||
code: e.response?.statusCode.toString(),
|
||||
error: e,
|
||||
));
|
||||
} catch (e) {
|
||||
emit(EvenementsError(
|
||||
message: 'Erreur lors de la désinscription de l\'événement: $e',
|
||||
error: e,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/// Charge les participants
|
||||
Future<void> _onLoadParticipants(
|
||||
LoadParticipants event,
|
||||
Emitter<EvenementsState> emit,
|
||||
) async {
|
||||
try {
|
||||
emit(const EvenementsLoading());
|
||||
|
||||
final participants = await _getEventParticipants(event.evenementId);
|
||||
|
||||
emit(ParticipantsLoaded(
|
||||
evenementId: event.evenementId,
|
||||
participants: participants,
|
||||
));
|
||||
} on DioException catch (e) {
|
||||
emit(EvenementsNetworkError(
|
||||
message: _getNetworkErrorMessage(e),
|
||||
code: e.response?.statusCode.toString(),
|
||||
error: e,
|
||||
));
|
||||
} catch (e) {
|
||||
emit(EvenementsError(
|
||||
message: 'Erreur lors du chargement des participants: $e',
|
||||
error: e,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/// Charge les statistiques
|
||||
Future<void> _onLoadEvenementsStats(
|
||||
LoadEvenementsStats event,
|
||||
Emitter<EvenementsState> emit,
|
||||
) async {
|
||||
try {
|
||||
emit(const EvenementsLoading());
|
||||
|
||||
final stats = await _repository.getEvenementsStats();
|
||||
|
||||
emit(EvenementsStatsLoaded(stats));
|
||||
} on DioException catch (e) {
|
||||
emit(EvenementsNetworkError(
|
||||
message: _getNetworkErrorMessage(e),
|
||||
code: e.response?.statusCode.toString(),
|
||||
error: e,
|
||||
));
|
||||
} catch (e) {
|
||||
emit(EvenementsError(
|
||||
message: 'Erreur lors du chargement des statistiques: $e',
|
||||
error: e,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/// Extrait les erreurs de validation
|
||||
Map<String, String> _extractValidationErrors(dynamic data) {
|
||||
final errors = <String, String>{};
|
||||
if (data is Map<String, dynamic> && data.containsKey('errors')) {
|
||||
final errorsData = data['errors'];
|
||||
if (errorsData is Map<String, dynamic>) {
|
||||
errorsData.forEach((key, value) {
|
||||
errors[key] = value.toString();
|
||||
});
|
||||
}
|
||||
}
|
||||
return errors;
|
||||
}
|
||||
|
||||
/// Génère un message d'erreur réseau approprié
|
||||
String _getNetworkErrorMessage(DioException e) {
|
||||
switch (e.type) {
|
||||
case DioExceptionType.connectionTimeout:
|
||||
return 'Délai de connexion dépassé. Vérifiez votre connexion internet.';
|
||||
case DioExceptionType.sendTimeout:
|
||||
return 'Délai d\'envoi dépassé. Vérifiez votre connexion internet.';
|
||||
case DioExceptionType.receiveTimeout:
|
||||
return 'Délai de réception dépassé. Vérifiez votre connexion internet.';
|
||||
case DioExceptionType.badResponse:
|
||||
final statusCode = e.response?.statusCode;
|
||||
if (statusCode == 401) {
|
||||
return 'Non autorisé. Veuillez vous reconnecter.';
|
||||
} else if (statusCode == 403) {
|
||||
return 'Accès refusé. Vous n\'avez pas les permissions nécessaires.';
|
||||
} else if (statusCode == 404) {
|
||||
return 'Ressource non trouvée.';
|
||||
} else if (statusCode == 409) {
|
||||
return 'Conflit. Cette ressource existe déjà.';
|
||||
} else if (statusCode != null && statusCode >= 500) {
|
||||
return 'Erreur serveur. Veuillez réessayer plus tard.';
|
||||
}
|
||||
return 'Erreur lors de la communication avec le serveur.';
|
||||
case DioExceptionType.cancel:
|
||||
return 'Requête annulée.';
|
||||
case DioExceptionType.unknown:
|
||||
return 'Erreur de connexion. Vérifiez votre connexion internet.';
|
||||
default:
|
||||
return 'Erreur réseau inattendue.';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
150
lib/features/events/bloc/evenements_event.dart
Normal file
150
lib/features/events/bloc/evenements_event.dart
Normal file
@@ -0,0 +1,150 @@
|
||||
/// Événements pour le BLoC des événements
|
||||
library evenements_event;
|
||||
|
||||
import 'package:equatable/equatable.dart';
|
||||
import '../data/models/evenement_model.dart';
|
||||
|
||||
/// Classe de base pour tous les événements
|
||||
abstract class EvenementsEvent extends Equatable {
|
||||
const EvenementsEvent();
|
||||
|
||||
@override
|
||||
List<Object?> get props => [];
|
||||
}
|
||||
|
||||
/// Événement pour charger la liste des événements
|
||||
class LoadEvenements extends EvenementsEvent {
|
||||
final int page;
|
||||
final int size;
|
||||
final String? recherche;
|
||||
final bool refresh;
|
||||
|
||||
const LoadEvenements({
|
||||
this.page = 0,
|
||||
this.size = 20,
|
||||
this.recherche,
|
||||
this.refresh = false,
|
||||
});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [page, size, recherche, refresh];
|
||||
}
|
||||
|
||||
/// Événement pour charger un événement par ID
|
||||
class LoadEvenementById extends EvenementsEvent {
|
||||
final String id;
|
||||
|
||||
const LoadEvenementById(this.id);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [id];
|
||||
}
|
||||
|
||||
/// Événement pour créer un nouvel événement
|
||||
class CreateEvenement extends EvenementsEvent {
|
||||
final EvenementModel evenement;
|
||||
|
||||
const CreateEvenement(this.evenement);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [evenement];
|
||||
}
|
||||
|
||||
/// Événement pour mettre à jour un événement
|
||||
class UpdateEvenement extends EvenementsEvent {
|
||||
final String id;
|
||||
final EvenementModel evenement;
|
||||
|
||||
const UpdateEvenement(this.id, this.evenement);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [id, evenement];
|
||||
}
|
||||
|
||||
/// Événement pour supprimer un événement
|
||||
class DeleteEvenement extends EvenementsEvent {
|
||||
final String id;
|
||||
|
||||
const DeleteEvenement(this.id);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [id];
|
||||
}
|
||||
|
||||
/// Événement pour charger les événements à venir
|
||||
class LoadEvenementsAVenir extends EvenementsEvent {
|
||||
final int page;
|
||||
final int size;
|
||||
|
||||
const LoadEvenementsAVenir({
|
||||
this.page = 0,
|
||||
this.size = 20,
|
||||
});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [page, size];
|
||||
}
|
||||
|
||||
/// Événement pour charger les événements en cours
|
||||
class LoadEvenementsEnCours extends EvenementsEvent {
|
||||
final int page;
|
||||
final int size;
|
||||
|
||||
const LoadEvenementsEnCours({
|
||||
this.page = 0,
|
||||
this.size = 20,
|
||||
});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [page, size];
|
||||
}
|
||||
|
||||
/// Événement pour charger les événements passés
|
||||
class LoadEvenementsPasses extends EvenementsEvent {
|
||||
final int page;
|
||||
final int size;
|
||||
|
||||
const LoadEvenementsPasses({
|
||||
this.page = 0,
|
||||
this.size = 20,
|
||||
});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [page, size];
|
||||
}
|
||||
|
||||
/// Événement pour s'inscrire à un événement
|
||||
class InscrireEvenement extends EvenementsEvent {
|
||||
final String evenementId;
|
||||
|
||||
const InscrireEvenement(this.evenementId);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [evenementId];
|
||||
}
|
||||
|
||||
/// Événement pour se désinscrire d'un événement
|
||||
class DesinscrireEvenement extends EvenementsEvent {
|
||||
final String evenementId;
|
||||
|
||||
const DesinscrireEvenement(this.evenementId);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [evenementId];
|
||||
}
|
||||
|
||||
/// Événement pour charger les participants
|
||||
class LoadParticipants extends EvenementsEvent {
|
||||
final String evenementId;
|
||||
|
||||
const LoadParticipants(this.evenementId);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [evenementId];
|
||||
}
|
||||
|
||||
/// Événement pour charger les statistiques
|
||||
class LoadEvenementsStats extends EvenementsEvent {
|
||||
const LoadEvenementsStats();
|
||||
}
|
||||
|
||||
194
lib/features/events/bloc/evenements_state.dart
Normal file
194
lib/features/events/bloc/evenements_state.dart
Normal file
@@ -0,0 +1,194 @@
|
||||
/// États pour le BLoC des événements
|
||||
library evenements_state;
|
||||
|
||||
import 'package:equatable/equatable.dart';
|
||||
import '../data/models/evenement_model.dart';
|
||||
|
||||
/// Classe de base pour tous les états
|
||||
abstract class EvenementsState extends Equatable {
|
||||
const EvenementsState();
|
||||
|
||||
@override
|
||||
List<Object?> get props => [];
|
||||
}
|
||||
|
||||
/// État initial
|
||||
class EvenementsInitial extends EvenementsState {
|
||||
const EvenementsInitial();
|
||||
}
|
||||
|
||||
/// État de chargement
|
||||
class EvenementsLoading extends EvenementsState {
|
||||
const EvenementsLoading();
|
||||
}
|
||||
|
||||
/// État de chargement avec données existantes (pour refresh)
|
||||
class EvenementsRefreshing extends EvenementsState {
|
||||
final List<EvenementModel> currentEvenements;
|
||||
|
||||
const EvenementsRefreshing(this.currentEvenements);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [currentEvenements];
|
||||
}
|
||||
|
||||
/// État de succès avec liste d'événements
|
||||
class EvenementsLoaded extends EvenementsState {
|
||||
final List<EvenementModel> evenements;
|
||||
final int total;
|
||||
final int page;
|
||||
final int size;
|
||||
final int totalPages;
|
||||
final bool hasMore;
|
||||
|
||||
const EvenementsLoaded({
|
||||
required this.evenements,
|
||||
required this.total,
|
||||
this.page = 0,
|
||||
this.size = 20,
|
||||
required this.totalPages,
|
||||
}) : hasMore = page < totalPages - 1;
|
||||
|
||||
@override
|
||||
List<Object?> get props => [evenements, total, page, size, totalPages, hasMore];
|
||||
|
||||
EvenementsLoaded copyWith({
|
||||
List<EvenementModel>? evenements,
|
||||
int? total,
|
||||
int? page,
|
||||
int? size,
|
||||
int? totalPages,
|
||||
}) {
|
||||
return EvenementsLoaded(
|
||||
evenements: evenements ?? this.evenements,
|
||||
total: total ?? this.total,
|
||||
page: page ?? this.page,
|
||||
size: size ?? this.size,
|
||||
totalPages: totalPages ?? this.totalPages,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// État de succès avec un seul événement
|
||||
class EvenementDetailLoaded extends EvenementsState {
|
||||
final EvenementModel evenement;
|
||||
|
||||
const EvenementDetailLoaded(this.evenement);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [evenement];
|
||||
}
|
||||
|
||||
/// État de succès après création
|
||||
class EvenementCreated extends EvenementsState {
|
||||
final EvenementModel evenement;
|
||||
|
||||
const EvenementCreated(this.evenement);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [evenement];
|
||||
}
|
||||
|
||||
/// État de succès après mise à jour
|
||||
class EvenementUpdated extends EvenementsState {
|
||||
final EvenementModel evenement;
|
||||
|
||||
const EvenementUpdated(this.evenement);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [evenement];
|
||||
}
|
||||
|
||||
/// État de succès après suppression
|
||||
class EvenementDeleted extends EvenementsState {
|
||||
final String id;
|
||||
|
||||
const EvenementDeleted(this.id);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [id];
|
||||
}
|
||||
|
||||
/// État de succès après inscription
|
||||
class EvenementInscrit extends EvenementsState {
|
||||
final String evenementId;
|
||||
|
||||
const EvenementInscrit(this.evenementId);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [evenementId];
|
||||
}
|
||||
|
||||
/// État de succès après désinscription
|
||||
class EvenementDesinscrit extends EvenementsState {
|
||||
final String evenementId;
|
||||
|
||||
const EvenementDesinscrit(this.evenementId);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [evenementId];
|
||||
}
|
||||
|
||||
/// État avec liste de participants
|
||||
class ParticipantsLoaded extends EvenementsState {
|
||||
final String evenementId;
|
||||
final List<Map<String, dynamic>> participants;
|
||||
|
||||
const ParticipantsLoaded({
|
||||
required this.evenementId,
|
||||
required this.participants,
|
||||
});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [evenementId, participants];
|
||||
}
|
||||
|
||||
/// État avec statistiques
|
||||
class EvenementsStatsLoaded extends EvenementsState {
|
||||
final Map<String, dynamic> stats;
|
||||
|
||||
const EvenementsStatsLoaded(this.stats);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [stats];
|
||||
}
|
||||
|
||||
/// État d'erreur
|
||||
class EvenementsError extends EvenementsState {
|
||||
final String message;
|
||||
final String? code;
|
||||
final dynamic error;
|
||||
|
||||
const EvenementsError({
|
||||
required this.message,
|
||||
this.code,
|
||||
this.error,
|
||||
});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [message, code, error];
|
||||
}
|
||||
|
||||
/// État d'erreur réseau
|
||||
class EvenementsNetworkError extends EvenementsError {
|
||||
const EvenementsNetworkError({
|
||||
required super.message,
|
||||
super.code,
|
||||
super.error,
|
||||
});
|
||||
}
|
||||
|
||||
/// État d'erreur de validation
|
||||
class EvenementsValidationError extends EvenementsError {
|
||||
final Map<String, String> validationErrors;
|
||||
|
||||
const EvenementsValidationError({
|
||||
required super.message,
|
||||
required this.validationErrors,
|
||||
super.code,
|
||||
});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [message, code, validationErrors];
|
||||
}
|
||||
|
||||
348
lib/features/events/data/models/evenement_model.dart
Normal file
348
lib/features/events/data/models/evenement_model.dart
Normal file
@@ -0,0 +1,348 @@
|
||||
/// Modèle complet de données pour un événement
|
||||
/// Aligné avec le backend EvenementDTO
|
||||
library evenement_model;
|
||||
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'evenement_model.g.dart';
|
||||
|
||||
/// Énumération des types d'événements
|
||||
enum TypeEvenement {
|
||||
@JsonValue('ASSEMBLEE_GENERALE')
|
||||
assembleeGenerale,
|
||||
@JsonValue('REUNION')
|
||||
reunion,
|
||||
@JsonValue('FORMATION')
|
||||
formation,
|
||||
@JsonValue('CONFERENCE')
|
||||
conference,
|
||||
@JsonValue('ATELIER')
|
||||
atelier,
|
||||
@JsonValue('SEMINAIRE')
|
||||
seminaire,
|
||||
@JsonValue('EVENEMENT_SOCIAL')
|
||||
evenementSocial,
|
||||
@JsonValue('MANIFESTATION')
|
||||
manifestation,
|
||||
@JsonValue('CELEBRATION')
|
||||
celebration,
|
||||
@JsonValue('AUTRE')
|
||||
autre,
|
||||
}
|
||||
|
||||
/// Énumération des statuts d'événements
|
||||
enum StatutEvenement {
|
||||
@JsonValue('PLANIFIE')
|
||||
planifie,
|
||||
@JsonValue('CONFIRME')
|
||||
confirme,
|
||||
@JsonValue('EN_COURS')
|
||||
enCours,
|
||||
@JsonValue('TERMINE')
|
||||
termine,
|
||||
@JsonValue('ANNULE')
|
||||
annule,
|
||||
@JsonValue('REPORTE')
|
||||
reporte,
|
||||
}
|
||||
|
||||
/// Énumération des priorités
|
||||
enum PrioriteEvenement {
|
||||
@JsonValue('BASSE')
|
||||
basse,
|
||||
@JsonValue('MOYENNE')
|
||||
moyenne,
|
||||
@JsonValue('HAUTE')
|
||||
haute,
|
||||
}
|
||||
|
||||
/// Modèle complet d'un événement
|
||||
@JsonSerializable()
|
||||
class EvenementModel extends Equatable {
|
||||
/// Identifiant unique
|
||||
final int? id;
|
||||
|
||||
/// Titre de l'événement
|
||||
final String titre;
|
||||
|
||||
/// Description détaillée
|
||||
final String? description;
|
||||
|
||||
/// Date et heure de début
|
||||
@JsonKey(name: 'dateDebut')
|
||||
final DateTime dateDebut;
|
||||
|
||||
/// Date et heure de fin
|
||||
@JsonKey(name: 'dateFin')
|
||||
final DateTime dateFin;
|
||||
|
||||
/// Lieu de l'événement
|
||||
final String? lieu;
|
||||
|
||||
/// Adresse complète
|
||||
final String? adresse;
|
||||
|
||||
/// Ville
|
||||
final String? ville;
|
||||
|
||||
/// Code postal
|
||||
@JsonKey(name: 'codePostal')
|
||||
final String? codePostal;
|
||||
|
||||
/// Type d'événement
|
||||
final TypeEvenement type;
|
||||
|
||||
/// Statut de l'événement
|
||||
final StatutEvenement statut;
|
||||
|
||||
/// Nombre maximum de participants
|
||||
@JsonKey(name: 'maxParticipants')
|
||||
final int? maxParticipants;
|
||||
|
||||
/// Nombre de participants actuels
|
||||
@JsonKey(name: 'participantsActuels')
|
||||
final int participantsActuels;
|
||||
|
||||
/// ID de l'organisateur
|
||||
@JsonKey(name: 'organisateurId')
|
||||
final int? organisateurId;
|
||||
|
||||
/// Nom de l'organisateur (pour affichage)
|
||||
@JsonKey(name: 'organisateurNom')
|
||||
final String? organisateurNom;
|
||||
|
||||
/// ID de l'organisation
|
||||
@JsonKey(name: 'organisationId')
|
||||
final int? organisationId;
|
||||
|
||||
/// Nom de l'organisation (pour affichage)
|
||||
@JsonKey(name: 'organisationNom')
|
||||
final String? organisationNom;
|
||||
|
||||
/// Priorité de l'événement
|
||||
final PrioriteEvenement priorite;
|
||||
|
||||
/// Événement public
|
||||
@JsonKey(name: 'estPublic')
|
||||
final bool estPublic;
|
||||
|
||||
/// Inscription requise
|
||||
@JsonKey(name: 'inscriptionRequise')
|
||||
final bool inscriptionRequise;
|
||||
|
||||
/// Coût de participation
|
||||
final double? cout;
|
||||
|
||||
/// Devise
|
||||
final String devise;
|
||||
|
||||
/// Tags/mots-clés
|
||||
final List<String> tags;
|
||||
|
||||
/// URL de l'image
|
||||
@JsonKey(name: 'imageUrl')
|
||||
final String? imageUrl;
|
||||
|
||||
/// URL du document
|
||||
@JsonKey(name: 'documentUrl')
|
||||
final String? documentUrl;
|
||||
|
||||
/// Notes internes
|
||||
final String? notes;
|
||||
|
||||
/// Date de création
|
||||
@JsonKey(name: 'dateCreation')
|
||||
final DateTime? dateCreation;
|
||||
|
||||
/// Date de modification
|
||||
@JsonKey(name: 'dateModification')
|
||||
final DateTime? dateModification;
|
||||
|
||||
/// Actif
|
||||
final bool actif;
|
||||
|
||||
const EvenementModel({
|
||||
this.id,
|
||||
required this.titre,
|
||||
this.description,
|
||||
required this.dateDebut,
|
||||
required this.dateFin,
|
||||
this.lieu,
|
||||
this.adresse,
|
||||
this.ville,
|
||||
this.codePostal,
|
||||
this.type = TypeEvenement.autre,
|
||||
this.statut = StatutEvenement.planifie,
|
||||
this.maxParticipants,
|
||||
this.participantsActuels = 0,
|
||||
this.organisateurId,
|
||||
this.organisateurNom,
|
||||
this.organisationId,
|
||||
this.organisationNom,
|
||||
this.priorite = PrioriteEvenement.moyenne,
|
||||
this.estPublic = true,
|
||||
this.inscriptionRequise = false,
|
||||
this.cout,
|
||||
this.devise = 'XOF',
|
||||
this.tags = const [],
|
||||
this.imageUrl,
|
||||
this.documentUrl,
|
||||
this.notes,
|
||||
this.dateCreation,
|
||||
this.dateModification,
|
||||
this.actif = true,
|
||||
});
|
||||
|
||||
/// Création depuis JSON
|
||||
factory EvenementModel.fromJson(Map<String, dynamic> json) =>
|
||||
_$EvenementModelFromJson(json);
|
||||
|
||||
/// Conversion vers JSON
|
||||
Map<String, dynamic> toJson() => _$EvenementModelToJson(this);
|
||||
|
||||
/// Copie avec modifications
|
||||
EvenementModel copyWith({
|
||||
int? id,
|
||||
String? titre,
|
||||
String? description,
|
||||
DateTime? dateDebut,
|
||||
DateTime? dateFin,
|
||||
String? lieu,
|
||||
String? adresse,
|
||||
String? ville,
|
||||
String? codePostal,
|
||||
TypeEvenement? type,
|
||||
StatutEvenement? statut,
|
||||
int? maxParticipants,
|
||||
int? participantsActuels,
|
||||
int? organisateurId,
|
||||
String? organisateurNom,
|
||||
int? organisationId,
|
||||
String? organisationNom,
|
||||
PrioriteEvenement? priorite,
|
||||
bool? estPublic,
|
||||
bool? inscriptionRequise,
|
||||
double? cout,
|
||||
String? devise,
|
||||
List<String>? tags,
|
||||
String? imageUrl,
|
||||
String? documentUrl,
|
||||
String? notes,
|
||||
DateTime? dateCreation,
|
||||
DateTime? dateModification,
|
||||
bool? actif,
|
||||
}) {
|
||||
return EvenementModel(
|
||||
id: id ?? this.id,
|
||||
titre: titre ?? this.titre,
|
||||
description: description ?? this.description,
|
||||
dateDebut: dateDebut ?? this.dateDebut,
|
||||
dateFin: dateFin ?? this.dateFin,
|
||||
lieu: lieu ?? this.lieu,
|
||||
adresse: adresse ?? this.adresse,
|
||||
ville: ville ?? this.ville,
|
||||
codePostal: codePostal ?? this.codePostal,
|
||||
type: type ?? this.type,
|
||||
statut: statut ?? this.statut,
|
||||
maxParticipants: maxParticipants ?? this.maxParticipants,
|
||||
participantsActuels: participantsActuels ?? this.participantsActuels,
|
||||
organisateurId: organisateurId ?? this.organisateurId,
|
||||
organisateurNom: organisateurNom ?? this.organisateurNom,
|
||||
organisationId: organisationId ?? this.organisationId,
|
||||
organisationNom: organisationNom ?? this.organisationNom,
|
||||
priorite: priorite ?? this.priorite,
|
||||
estPublic: estPublic ?? this.estPublic,
|
||||
inscriptionRequise: inscriptionRequise ?? this.inscriptionRequise,
|
||||
cout: cout ?? this.cout,
|
||||
devise: devise ?? this.devise,
|
||||
tags: tags ?? this.tags,
|
||||
imageUrl: imageUrl ?? this.imageUrl,
|
||||
documentUrl: documentUrl ?? this.documentUrl,
|
||||
notes: notes ?? this.notes,
|
||||
dateCreation: dateCreation ?? this.dateCreation,
|
||||
dateModification: dateModification ?? this.dateModification,
|
||||
actif: actif ?? this.actif,
|
||||
);
|
||||
}
|
||||
|
||||
/// Durée de l'événement en heures
|
||||
double get dureeHeures {
|
||||
return dateFin.difference(dateDebut).inMinutes / 60.0;
|
||||
}
|
||||
|
||||
/// Nombre de jours avant l'événement
|
||||
int get joursAvantEvenement {
|
||||
return dateDebut.difference(DateTime.now()).inDays;
|
||||
}
|
||||
|
||||
/// Est dans le futur
|
||||
bool get estAVenir => dateDebut.isAfter(DateTime.now());
|
||||
|
||||
/// Est en cours
|
||||
bool get estEnCours {
|
||||
final now = DateTime.now();
|
||||
return now.isAfter(dateDebut) && now.isBefore(dateFin);
|
||||
}
|
||||
|
||||
/// Est passé
|
||||
bool get estPasse => dateFin.isBefore(DateTime.now());
|
||||
|
||||
/// Places disponibles
|
||||
int? get placesDisponibles {
|
||||
if (maxParticipants == null) return null;
|
||||
return maxParticipants! - participantsActuels;
|
||||
}
|
||||
|
||||
/// Est complet
|
||||
bool get estComplet {
|
||||
if (maxParticipants == null) return false;
|
||||
return participantsActuels >= maxParticipants!;
|
||||
}
|
||||
|
||||
/// Peut s'inscrire
|
||||
bool get peutSinscrire {
|
||||
return estAVenir &&
|
||||
!estComplet &&
|
||||
statut == StatutEvenement.confirme &&
|
||||
inscriptionRequise;
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [
|
||||
id,
|
||||
titre,
|
||||
description,
|
||||
dateDebut,
|
||||
dateFin,
|
||||
lieu,
|
||||
adresse,
|
||||
ville,
|
||||
codePostal,
|
||||
type,
|
||||
statut,
|
||||
maxParticipants,
|
||||
participantsActuels,
|
||||
organisateurId,
|
||||
organisateurNom,
|
||||
organisationId,
|
||||
organisationNom,
|
||||
priorite,
|
||||
estPublic,
|
||||
inscriptionRequise,
|
||||
cout,
|
||||
devise,
|
||||
tags,
|
||||
imageUrl,
|
||||
documentUrl,
|
||||
notes,
|
||||
dateCreation,
|
||||
dateModification,
|
||||
actif,
|
||||
];
|
||||
|
||||
@override
|
||||
String toString() =>
|
||||
'EvenementModel(id: $id, titre: $titre, dateDebut: $dateDebut, statut: $statut)';
|
||||
}
|
||||
|
||||
111
lib/features/events/data/models/evenement_model.g.dart
Normal file
111
lib/features/events/data/models/evenement_model.g.dart
Normal file
@@ -0,0 +1,111 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'evenement_model.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
EvenementModel _$EvenementModelFromJson(Map<String, dynamic> json) =>
|
||||
EvenementModel(
|
||||
id: (json['id'] as num?)?.toInt(),
|
||||
titre: json['titre'] as String,
|
||||
description: json['description'] as String?,
|
||||
dateDebut: DateTime.parse(json['dateDebut'] as String),
|
||||
dateFin: DateTime.parse(json['dateFin'] as String),
|
||||
lieu: json['lieu'] as String?,
|
||||
adresse: json['adresse'] as String?,
|
||||
ville: json['ville'] as String?,
|
||||
codePostal: json['codePostal'] as String?,
|
||||
type: $enumDecodeNullable(_$TypeEvenementEnumMap, json['type']) ??
|
||||
TypeEvenement.autre,
|
||||
statut: $enumDecodeNullable(_$StatutEvenementEnumMap, json['statut']) ??
|
||||
StatutEvenement.planifie,
|
||||
maxParticipants: (json['maxParticipants'] as num?)?.toInt(),
|
||||
participantsActuels: (json['participantsActuels'] as num?)?.toInt() ?? 0,
|
||||
organisateurId: (json['organisateurId'] as num?)?.toInt(),
|
||||
organisateurNom: json['organisateurNom'] as String?,
|
||||
organisationId: (json['organisationId'] as num?)?.toInt(),
|
||||
organisationNom: json['organisationNom'] as String?,
|
||||
priorite:
|
||||
$enumDecodeNullable(_$PrioriteEvenementEnumMap, json['priorite']) ??
|
||||
PrioriteEvenement.moyenne,
|
||||
estPublic: json['estPublic'] as bool? ?? true,
|
||||
inscriptionRequise: json['inscriptionRequise'] as bool? ?? false,
|
||||
cout: (json['cout'] as num?)?.toDouble(),
|
||||
devise: json['devise'] as String? ?? 'XOF',
|
||||
tags:
|
||||
(json['tags'] as List<dynamic>?)?.map((e) => e as String).toList() ??
|
||||
const [],
|
||||
imageUrl: json['imageUrl'] as String?,
|
||||
documentUrl: json['documentUrl'] as String?,
|
||||
notes: json['notes'] as String?,
|
||||
dateCreation: json['dateCreation'] == null
|
||||
? null
|
||||
: DateTime.parse(json['dateCreation'] as String),
|
||||
dateModification: json['dateModification'] == null
|
||||
? null
|
||||
: DateTime.parse(json['dateModification'] as String),
|
||||
actif: json['actif'] as bool? ?? true,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$EvenementModelToJson(EvenementModel instance) =>
|
||||
<String, dynamic>{
|
||||
'id': instance.id,
|
||||
'titre': instance.titre,
|
||||
'description': instance.description,
|
||||
'dateDebut': instance.dateDebut.toIso8601String(),
|
||||
'dateFin': instance.dateFin.toIso8601String(),
|
||||
'lieu': instance.lieu,
|
||||
'adresse': instance.adresse,
|
||||
'ville': instance.ville,
|
||||
'codePostal': instance.codePostal,
|
||||
'type': _$TypeEvenementEnumMap[instance.type]!,
|
||||
'statut': _$StatutEvenementEnumMap[instance.statut]!,
|
||||
'maxParticipants': instance.maxParticipants,
|
||||
'participantsActuels': instance.participantsActuels,
|
||||
'organisateurId': instance.organisateurId,
|
||||
'organisateurNom': instance.organisateurNom,
|
||||
'organisationId': instance.organisationId,
|
||||
'organisationNom': instance.organisationNom,
|
||||
'priorite': _$PrioriteEvenementEnumMap[instance.priorite]!,
|
||||
'estPublic': instance.estPublic,
|
||||
'inscriptionRequise': instance.inscriptionRequise,
|
||||
'cout': instance.cout,
|
||||
'devise': instance.devise,
|
||||
'tags': instance.tags,
|
||||
'imageUrl': instance.imageUrl,
|
||||
'documentUrl': instance.documentUrl,
|
||||
'notes': instance.notes,
|
||||
'dateCreation': instance.dateCreation?.toIso8601String(),
|
||||
'dateModification': instance.dateModification?.toIso8601String(),
|
||||
'actif': instance.actif,
|
||||
};
|
||||
|
||||
const _$TypeEvenementEnumMap = {
|
||||
TypeEvenement.assembleeGenerale: 'ASSEMBLEE_GENERALE',
|
||||
TypeEvenement.reunion: 'REUNION',
|
||||
TypeEvenement.formation: 'FORMATION',
|
||||
TypeEvenement.conference: 'CONFERENCE',
|
||||
TypeEvenement.atelier: 'ATELIER',
|
||||
TypeEvenement.seminaire: 'SEMINAIRE',
|
||||
TypeEvenement.evenementSocial: 'EVENEMENT_SOCIAL',
|
||||
TypeEvenement.manifestation: 'MANIFESTATION',
|
||||
TypeEvenement.celebration: 'CELEBRATION',
|
||||
TypeEvenement.autre: 'AUTRE',
|
||||
};
|
||||
|
||||
const _$StatutEvenementEnumMap = {
|
||||
StatutEvenement.planifie: 'PLANIFIE',
|
||||
StatutEvenement.confirme: 'CONFIRME',
|
||||
StatutEvenement.enCours: 'EN_COURS',
|
||||
StatutEvenement.termine: 'TERMINE',
|
||||
StatutEvenement.annule: 'ANNULE',
|
||||
StatutEvenement.reporte: 'REPORTE',
|
||||
};
|
||||
|
||||
const _$PrioriteEvenementEnumMap = {
|
||||
PrioriteEvenement.basse: 'BASSE',
|
||||
PrioriteEvenement.moyenne: 'MOYENNE',
|
||||
PrioriteEvenement.haute: 'HAUTE',
|
||||
};
|
||||
@@ -0,0 +1,352 @@
|
||||
/// Implémentation du repository pour la gestion des événements
|
||||
/// Interface avec l'API backend EvenementResource
|
||||
library evenement_repository_impl;
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:unionflow_mobile_apps/core/network/api_client.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
import '../../domain/repositories/evenement_repository.dart';
|
||||
import '../models/evenement_model.dart';
|
||||
|
||||
/// Résultat de recherche paginé
|
||||
class EvenementSearchResult {
|
||||
final List<EvenementModel> evenements;
|
||||
final int total;
|
||||
final int page;
|
||||
final int size;
|
||||
final int totalPages;
|
||||
|
||||
const EvenementSearchResult({
|
||||
required this.evenements,
|
||||
required this.total,
|
||||
required this.page,
|
||||
required this.size,
|
||||
required this.totalPages,
|
||||
});
|
||||
|
||||
factory EvenementSearchResult.fromJson(Map<String, dynamic> json) {
|
||||
// Support pour les deux formats de réponse
|
||||
if (json.containsKey('data')) {
|
||||
// Format paginé avec métadonnées
|
||||
return EvenementSearchResult(
|
||||
evenements: (json['data'] as List<dynamic>)
|
||||
.map((e) => EvenementModel.fromJson(e as Map<String, dynamic>))
|
||||
.toList(),
|
||||
total: json['total'] as int,
|
||||
page: json['page'] as int,
|
||||
size: json['size'] as int,
|
||||
totalPages: json['totalPages'] as int,
|
||||
);
|
||||
} else {
|
||||
// Format simple (liste directe) - pour compatibilité backend
|
||||
return EvenementSearchResult(
|
||||
evenements: (json['content'] as List<dynamic>)
|
||||
.map((e) => EvenementModel.fromJson(e as Map<String, dynamic>))
|
||||
.toList(),
|
||||
total: json['totalElements'] as int? ?? 0,
|
||||
page: json['number'] as int? ?? 0,
|
||||
size: json['size'] as int? ?? 20,
|
||||
totalPages: json['totalPages'] as int? ?? 1,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Implémentation du repository des événements
|
||||
@LazySingleton(as: IEvenementRepository)
|
||||
class EvenementRepositoryImpl implements IEvenementRepository {
|
||||
final ApiClient _apiClient;
|
||||
static const String _baseUrl = '/api/evenements';
|
||||
|
||||
EvenementRepositoryImpl(this._apiClient);
|
||||
|
||||
/// Parse une réponse API : liste directe ou objet paginé (content / data).
|
||||
EvenementSearchResult _parseSearchResponse(dynamic data, int page, int size) {
|
||||
if (data is List) {
|
||||
final evenements = (data as List<dynamic>)
|
||||
.map((e) => EvenementModel.fromJson(e as Map<String, dynamic>))
|
||||
.toList();
|
||||
return EvenementSearchResult(
|
||||
evenements: evenements,
|
||||
total: evenements.length,
|
||||
page: page,
|
||||
size: size,
|
||||
totalPages: 1,
|
||||
);
|
||||
}
|
||||
return EvenementSearchResult.fromJson(data as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<EvenementSearchResult> getEvenements({
|
||||
int page = 0,
|
||||
int size = 20,
|
||||
String? recherche,
|
||||
}) async {
|
||||
try {
|
||||
final queryParams = <String, dynamic>{
|
||||
'page': page,
|
||||
'size': size,
|
||||
};
|
||||
|
||||
if (recherche?.isNotEmpty == true) {
|
||||
queryParams['recherche'] = recherche;
|
||||
}
|
||||
|
||||
final response = await _apiClient.get(
|
||||
_baseUrl,
|
||||
queryParameters: queryParams,
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
// Le backend peut retourner soit une liste directe, soit un objet paginé
|
||||
if (response.data is List) {
|
||||
// Format liste directe
|
||||
final evenements = (response.data as List<dynamic>)
|
||||
.map((e) => EvenementModel.fromJson(e as Map<String, dynamic>))
|
||||
.toList();
|
||||
return EvenementSearchResult(
|
||||
evenements: evenements,
|
||||
total: evenements.length,
|
||||
page: page,
|
||||
size: size,
|
||||
totalPages: 1,
|
||||
);
|
||||
} else {
|
||||
// Format objet paginé
|
||||
return EvenementSearchResult.fromJson(response.data as Map<String, dynamic>);
|
||||
}
|
||||
} else {
|
||||
throw Exception('Erreur lors de la récupération des événements: ${response.statusCode}');
|
||||
}
|
||||
} on DioException catch (e) {
|
||||
if (e.response != null) {
|
||||
throw Exception('Erreur HTTP ${e.response!.statusCode}: ${e.response!.data}');
|
||||
} else {
|
||||
throw Exception('Erreur réseau: ${e.type} - ${e.message ?? e.error}');
|
||||
}
|
||||
} catch (e) {
|
||||
throw Exception('Erreur inattendue lors de la récupération des événements: $e');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<EvenementModel?> getEvenementById(String id) async {
|
||||
try {
|
||||
final response = await _apiClient.get('$_baseUrl/$id');
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
return EvenementModel.fromJson(response.data as Map<String, dynamic>);
|
||||
} else if (response.statusCode == 404) {
|
||||
return null;
|
||||
} else {
|
||||
throw Exception('Erreur lors de la récupération de l\'événement: ${response.statusCode}');
|
||||
}
|
||||
} on DioException catch (e) {
|
||||
if (e.response?.statusCode == 404) {
|
||||
return null;
|
||||
}
|
||||
throw Exception('Erreur réseau lors de la récupération de l\'événement: ${e.message}');
|
||||
} catch (e) {
|
||||
throw Exception('Erreur inattendue lors de la récupération de l\'événement: $e');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<EvenementModel> createEvenement(EvenementModel evenement) async {
|
||||
try {
|
||||
final response = await _apiClient.post(
|
||||
_baseUrl,
|
||||
data: evenement.toJson(),
|
||||
);
|
||||
|
||||
if (response.statusCode == 201 || response.statusCode == 200) {
|
||||
return EvenementModel.fromJson(response.data as Map<String, dynamic>);
|
||||
} else {
|
||||
throw Exception('Erreur lors de la création de l\'événement: ${response.statusCode}');
|
||||
}
|
||||
} on DioException catch (e) {
|
||||
throw Exception('Erreur réseau lors de la création de l\'événement: ${e.message}');
|
||||
} catch (e) {
|
||||
throw Exception('Erreur inattendue lors de la création de l\'événement: $e');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<EvenementModel> updateEvenement(String id, EvenementModel evenement) async {
|
||||
try {
|
||||
final response = await _apiClient.put(
|
||||
'$_baseUrl/$id',
|
||||
data: evenement.toJson(),
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
return EvenementModel.fromJson(response.data as Map<String, dynamic>);
|
||||
} else {
|
||||
throw Exception('Erreur lors de la mise à jour de l\'événement: ${response.statusCode}');
|
||||
}
|
||||
} on DioException catch (e) {
|
||||
throw Exception('Erreur réseau lors de la mise à jour de l\'événement: ${e.message}');
|
||||
} catch (e) {
|
||||
throw Exception('Erreur inattendue lors de la mise à jour de l\'événement: $e');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> deleteEvenement(String id) async {
|
||||
try {
|
||||
final response = await _apiClient.delete('$_baseUrl/$id');
|
||||
|
||||
if (response.statusCode != 204 && response.statusCode != 200) {
|
||||
throw Exception('Erreur lors de la suppression de l\'événement: ${response.statusCode}');
|
||||
}
|
||||
} on DioException catch (e) {
|
||||
throw Exception('Erreur réseau lors de la suppression de l\'événement: ${e.message}');
|
||||
} catch (e) {
|
||||
throw Exception('Erreur inattendue lors de la suppression de l\'événement: $e');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<EvenementSearchResult> getEvenementsAVenir({int page = 0, int size = 20}) async {
|
||||
try {
|
||||
final response = await _apiClient.get(
|
||||
'$_baseUrl/a-venir',
|
||||
queryParameters: {'page': page, 'size': size},
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
return _parseSearchResponse(response.data, page, size);
|
||||
} else {
|
||||
throw Exception('Erreur lors de la récupération des événements à venir: ${response.statusCode}');
|
||||
}
|
||||
} on DioException catch (e) {
|
||||
throw Exception('Erreur réseau lors de la récupération des événements à venir: ${e.message}');
|
||||
} catch (e) {
|
||||
throw Exception('Erreur inattendue lors de la récupération des événements à venir: $e');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<EvenementSearchResult> getEvenementsEnCours({int page = 0, int size = 20}) async {
|
||||
try {
|
||||
final response = await _apiClient.get(
|
||||
'$_baseUrl/en-cours',
|
||||
queryParameters: {'page': page, 'size': size},
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
return _parseSearchResponse(response.data, page, size);
|
||||
} else {
|
||||
throw Exception('Erreur lors de la récupération des événements en cours: ${response.statusCode}');
|
||||
}
|
||||
} on DioException catch (e) {
|
||||
throw Exception('Erreur réseau lors de la récupération des événements en cours: ${e.message}');
|
||||
} catch (e) {
|
||||
throw Exception('Erreur inattendue lors de la récupération des événements en cours: $e');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<EvenementSearchResult> getEvenementsPasses({int page = 0, int size = 20}) async {
|
||||
try {
|
||||
final response = await _apiClient.get(
|
||||
'$_baseUrl/passes',
|
||||
queryParameters: {'page': page, 'size': size},
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
return _parseSearchResponse(response.data, page, size);
|
||||
} else {
|
||||
throw Exception('Erreur lors de la récupération des événements passés: ${response.statusCode}');
|
||||
}
|
||||
} on DioException catch (e) {
|
||||
throw Exception('Erreur réseau lors de la récupération des événements passés: ${e.message}');
|
||||
} catch (e) {
|
||||
throw Exception('Erreur inattendue lors de la récupération des événements passés: $e');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> inscrireEvenement(String evenementId) async {
|
||||
try {
|
||||
final response = await _apiClient.post('$_baseUrl/$evenementId/inscrire');
|
||||
|
||||
if (response.statusCode != 200 && response.statusCode != 201) {
|
||||
throw Exception('Erreur lors de l\'inscription à l\'événement: ${response.statusCode}');
|
||||
}
|
||||
} on DioException catch (e) {
|
||||
throw Exception('Erreur réseau lors de l\'inscription à l\'événement: ${e.message}');
|
||||
} catch (e) {
|
||||
throw Exception('Erreur inattendue lors de l\'inscription à l\'événement: $e');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> desinscrireEvenement(String evenementId) async {
|
||||
try {
|
||||
final response = await _apiClient.delete('$_baseUrl/$evenementId/desinscrire');
|
||||
|
||||
if (response.statusCode != 200 && response.statusCode != 204) {
|
||||
throw Exception('Erreur lors de la désinscription de l\'événement: ${response.statusCode}');
|
||||
}
|
||||
} on DioException catch (e) {
|
||||
throw Exception('Erreur réseau lors de la désinscription de l\'événement: ${e.message}');
|
||||
} catch (e) {
|
||||
throw Exception('Erreur inattendue lors de la désinscription de l\'événement: $e');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<Map<String, dynamic>>> getParticipants(String evenementId) async {
|
||||
try {
|
||||
final response = await _apiClient.get('$_baseUrl/$evenementId/participants');
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
return (response.data as List<dynamic>)
|
||||
.map((e) => e as Map<String, dynamic>)
|
||||
.toList();
|
||||
} else {
|
||||
throw Exception('Erreur lors de la récupération des participants: ${response.statusCode}');
|
||||
}
|
||||
} on DioException catch (e) {
|
||||
throw Exception('Erreur réseau lors de la récupération des participants: ${e.message}');
|
||||
} catch (e) {
|
||||
throw Exception('Erreur inattendue lors de la récupération des participants: $e');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<bool> getInscriptionStatus(String evenementId) async {
|
||||
try {
|
||||
final response = await _apiClient.get('$_baseUrl/$evenementId/me/inscrit');
|
||||
if (response.statusCode == 200 && response.data is Map) {
|
||||
final data = response.data as Map<String, dynamic>;
|
||||
return data['inscrit'] == true;
|
||||
}
|
||||
return false;
|
||||
} on DioException catch (_) {
|
||||
return false;
|
||||
} catch (_) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Map<String, dynamic>> getEvenementsStats() async {
|
||||
try {
|
||||
final response = await _apiClient.get('$_baseUrl/statistiques');
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
return response.data as Map<String, dynamic>;
|
||||
} else {
|
||||
throw Exception('Erreur lors de la récupération des statistiques: ${response.statusCode}');
|
||||
}
|
||||
} on DioException catch (e) {
|
||||
throw Exception('Erreur réseau lors de la récupération des statistiques: ${e.message}');
|
||||
} catch (e) {
|
||||
throw Exception('Erreur inattendue lors de la récupération des statistiques: $e');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
/// Interface du repository des événements (Clean Architecture)
|
||||
library evenement_repository_interface;
|
||||
|
||||
import '../../data/repositories/evenement_repository_impl.dart' show EvenementSearchResult;
|
||||
import '../../data/models/evenement_model.dart';
|
||||
|
||||
/// Interface définissant le contrat du repository des événements
|
||||
/// Implémentée par EvenementRepositoryImpl dans la couche data
|
||||
abstract class IEvenementRepository {
|
||||
/// Récupère la liste des événements avec pagination
|
||||
Future<EvenementSearchResult> getEvenements({
|
||||
int page = 0,
|
||||
int size = 20,
|
||||
String? recherche,
|
||||
});
|
||||
|
||||
/// Récupère un événement par son ID
|
||||
Future<EvenementModel?> getEvenementById(String id);
|
||||
|
||||
/// Crée un nouvel événement
|
||||
Future<EvenementModel> createEvenement(EvenementModel evenement);
|
||||
|
||||
/// Met à jour un événement
|
||||
Future<EvenementModel> updateEvenement(String id, EvenementModel evenement);
|
||||
|
||||
/// Supprime un événement
|
||||
Future<void> deleteEvenement(String id);
|
||||
|
||||
/// Récupère les événements à venir
|
||||
Future<EvenementSearchResult> getEvenementsAVenir({int page = 0, int size = 20});
|
||||
|
||||
/// Récupère les événements en cours
|
||||
Future<EvenementSearchResult> getEvenementsEnCours({int page = 0, int size = 20});
|
||||
|
||||
/// Récupère les événements passés
|
||||
Future<EvenementSearchResult> getEvenementsPasses({int page = 0, int size = 20});
|
||||
|
||||
/// S'inscrire à un événement
|
||||
Future<void> inscrireEvenement(String evenementId);
|
||||
|
||||
/// Se désinscrire d'un événement
|
||||
Future<void> desinscrireEvenement(String evenementId);
|
||||
|
||||
/// Indique si l'utilisateur connecté est inscrit à l'événement
|
||||
Future<bool> getInscriptionStatus(String evenementId);
|
||||
|
||||
/// Récupère les participants d'un événement
|
||||
Future<List<Map<String, dynamic>>> getParticipants(String evenementId);
|
||||
|
||||
/// Récupère les statistiques des événements
|
||||
Future<Map<String, dynamic>> getEvenementsStats();
|
||||
}
|
||||
26
lib/features/events/domain/usecases/cancel_registration.dart
Normal file
26
lib/features/events/domain/usecases/cancel_registration.dart
Normal file
@@ -0,0 +1,26 @@
|
||||
/// Use case: Annuler une inscription à un événement
|
||||
library cancel_registration;
|
||||
|
||||
import 'package:injectable/injectable.dart';
|
||||
import '../repositories/evenement_repository.dart';
|
||||
|
||||
/// Use case pour se désinscrire d'un événement
|
||||
@injectable
|
||||
class CancelRegistration {
|
||||
final IEvenementRepository _repository;
|
||||
|
||||
CancelRegistration(this._repository);
|
||||
|
||||
/// Exécute le use case
|
||||
///
|
||||
/// [evenementId] - UUID de l'événement
|
||||
///
|
||||
/// Annule l'inscription du membre connecté à l'événement
|
||||
/// Lève une exception si:
|
||||
/// - L'événement n'existe pas
|
||||
/// - Le membre n'est pas inscrit
|
||||
/// - L'événement a déjà commencé
|
||||
Future<void> call(String evenementId) async {
|
||||
return _repository.desinscrireEvenement(evenementId);
|
||||
}
|
||||
}
|
||||
25
lib/features/events/domain/usecases/create_event.dart
Normal file
25
lib/features/events/domain/usecases/create_event.dart
Normal file
@@ -0,0 +1,25 @@
|
||||
/// Use case: Créer un nouvel événement
|
||||
library create_event;
|
||||
|
||||
import 'package:injectable/injectable.dart';
|
||||
import '../../data/models/evenement_model.dart';
|
||||
import '../repositories/evenement_repository.dart';
|
||||
|
||||
/// Use case pour créer un événement
|
||||
/// Réservé aux utilisateurs avec le rôle ADMIN_ORGANISATION
|
||||
@injectable
|
||||
class CreateEvent {
|
||||
final IEvenementRepository _repository;
|
||||
|
||||
CreateEvent(this._repository);
|
||||
|
||||
/// Exécute le use case
|
||||
///
|
||||
/// [evenement] - Modèle de l'événement à créer
|
||||
///
|
||||
/// Retourne l'événement créé avec son ID généré
|
||||
/// Lève une exception en cas d'erreur de validation ou de création
|
||||
Future<EvenementModel> call(EvenementModel evenement) async {
|
||||
return _repository.createEvenement(evenement);
|
||||
}
|
||||
}
|
||||
24
lib/features/events/domain/usecases/delete_event.dart
Normal file
24
lib/features/events/domain/usecases/delete_event.dart
Normal file
@@ -0,0 +1,24 @@
|
||||
/// Use case: Supprimer un événement
|
||||
library delete_event;
|
||||
|
||||
import 'package:injectable/injectable.dart';
|
||||
import '../repositories/evenement_repository.dart';
|
||||
|
||||
/// Use case pour supprimer un événement
|
||||
/// Réservé à l'organisateur de l'événement ou ADMIN_ORGANISATION
|
||||
@injectable
|
||||
class DeleteEvent {
|
||||
final IEvenementRepository _repository;
|
||||
|
||||
DeleteEvent(this._repository);
|
||||
|
||||
/// Exécute le use case
|
||||
///
|
||||
/// [id] - UUID de l'événement à supprimer
|
||||
///
|
||||
/// Supprime l'événement de manière définitive
|
||||
/// Lève une exception si l'événement n'existe pas ou ne peut être supprimé
|
||||
Future<void> call(String id) async {
|
||||
return _repository.deleteEvenement(id);
|
||||
}
|
||||
}
|
||||
24
lib/features/events/domain/usecases/get_event_by_id.dart
Normal file
24
lib/features/events/domain/usecases/get_event_by_id.dart
Normal file
@@ -0,0 +1,24 @@
|
||||
/// Use case: Récupérer un événement par son ID
|
||||
library get_event_by_id;
|
||||
|
||||
import 'package:injectable/injectable.dart';
|
||||
import '../../data/models/evenement_model.dart';
|
||||
import '../repositories/evenement_repository.dart';
|
||||
|
||||
/// Use case pour récupérer le détail d'un événement
|
||||
@injectable
|
||||
class GetEventById {
|
||||
final IEvenementRepository _repository;
|
||||
|
||||
GetEventById(this._repository);
|
||||
|
||||
/// Exécute le use case
|
||||
///
|
||||
/// [id] - UUID de l'événement
|
||||
///
|
||||
/// Retourne le détail complet de l'événement
|
||||
/// Retourne null si l'événement n'existe pas
|
||||
Future<EvenementModel?> call(String id) async {
|
||||
return _repository.getEvenementById(id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/// Use case: Récupérer la liste des participants d'un événement
|
||||
library get_event_participants;
|
||||
|
||||
import 'package:injectable/injectable.dart';
|
||||
import '../repositories/evenement_repository.dart';
|
||||
|
||||
/// Use case pour récupérer les participants d'un événement
|
||||
/// Réservé à l'organisateur de l'événement ou ADMIN_ORGANISATION
|
||||
@injectable
|
||||
class GetEventParticipants {
|
||||
final IEvenementRepository _repository;
|
||||
|
||||
GetEventParticipants(this._repository);
|
||||
|
||||
/// Exécute le use case
|
||||
///
|
||||
/// [evenementId] - UUID de l'événement
|
||||
///
|
||||
/// Retourne la liste des participants avec leurs informations:
|
||||
/// - id: UUID du membre
|
||||
/// - nom: Nom complet
|
||||
/// - email: Email
|
||||
/// - dateInscription: Date d'inscription
|
||||
/// - statut: Statut de participation (CONFIRME, EN_ATTENTE, etc.)
|
||||
///
|
||||
/// Lève une exception si l'événement n'existe pas ou accès refusé
|
||||
Future<List<Map<String, dynamic>>> call(String evenementId) async {
|
||||
return _repository.getParticipants(evenementId);
|
||||
}
|
||||
}
|
||||
33
lib/features/events/domain/usecases/get_events.dart
Normal file
33
lib/features/events/domain/usecases/get_events.dart
Normal file
@@ -0,0 +1,33 @@
|
||||
/// Use case: Récupérer la liste des événements
|
||||
library get_events;
|
||||
|
||||
import 'package:injectable/injectable.dart';
|
||||
import '../../data/repositories/evenement_repository_impl.dart' show EvenementSearchResult;
|
||||
import '../repositories/evenement_repository.dart';
|
||||
|
||||
/// Use case pour récupérer la liste des événements avec pagination
|
||||
@injectable
|
||||
class GetEvents {
|
||||
final IEvenementRepository _repository;
|
||||
|
||||
GetEvents(this._repository);
|
||||
|
||||
/// Exécute le use case
|
||||
///
|
||||
/// [page] - Numéro de page (pagination)
|
||||
/// [size] - Taille de la page
|
||||
/// [recherche] - Terme de recherche (optionnel)
|
||||
///
|
||||
/// Retourne la liste paginée des événements
|
||||
Future<EvenementSearchResult> call({
|
||||
int page = 0,
|
||||
int size = 20,
|
||||
String? recherche,
|
||||
}) async {
|
||||
return _repository.getEvenements(
|
||||
page: page,
|
||||
size: size,
|
||||
recherche: recherche,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/// Use case: Récupérer mes inscriptions aux événements
|
||||
library get_my_registrations;
|
||||
|
||||
import 'package:injectable/injectable.dart';
|
||||
import '../../data/repositories/evenement_repository_impl.dart' show EvenementSearchResult;
|
||||
import '../repositories/evenement_repository.dart';
|
||||
|
||||
/// Use case pour récupérer les événements auxquels le membre est inscrit
|
||||
@injectable
|
||||
class GetMyRegistrations {
|
||||
final IEvenementRepository _repository;
|
||||
|
||||
GetMyRegistrations(this._repository);
|
||||
|
||||
/// Exécute le use case
|
||||
///
|
||||
/// [page] - Numéro de page (pagination)
|
||||
/// [size] - Taille de la page
|
||||
///
|
||||
/// Retourne la liste paginée des événements auxquels le membre est inscrit
|
||||
/// Note: Cette fonctionnalité utilise les événements à venir + filtre côté client
|
||||
/// pour déterminer les inscriptions (endpoint dédié à ajouter côté backend)
|
||||
Future<EvenementSearchResult> call({
|
||||
int page = 0,
|
||||
int size = 20,
|
||||
}) async {
|
||||
// Pour l'instant, on récupère les événements à venir
|
||||
// TODO: Ajouter endpoint backend GET /api/evenements/mes-inscriptions
|
||||
return _repository.getEvenementsAVenir(page: page, size: size);
|
||||
}
|
||||
}
|
||||
27
lib/features/events/domain/usecases/register_for_event.dart
Normal file
27
lib/features/events/domain/usecases/register_for_event.dart
Normal file
@@ -0,0 +1,27 @@
|
||||
/// Use case: S'inscrire à un événement
|
||||
library register_for_event;
|
||||
|
||||
import 'package:injectable/injectable.dart';
|
||||
import '../repositories/evenement_repository.dart';
|
||||
|
||||
/// Use case pour s'inscrire à un événement
|
||||
@injectable
|
||||
class RegisterForEvent {
|
||||
final IEvenementRepository _repository;
|
||||
|
||||
RegisterForEvent(this._repository);
|
||||
|
||||
/// Exécute le use case
|
||||
///
|
||||
/// [evenementId] - UUID de l'événement
|
||||
///
|
||||
/// Inscrit le membre connecté à l'événement
|
||||
/// Lève une exception si:
|
||||
/// - L'événement n'existe pas
|
||||
/// - Le membre est déjà inscrit
|
||||
/// - L'événement est complet
|
||||
/// - L'événement est passé
|
||||
Future<void> call(String evenementId) async {
|
||||
return _repository.inscrireEvenement(evenementId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/// Use case: Soumettre un feedback sur un événement
|
||||
library submit_event_feedback;
|
||||
|
||||
import 'package:injectable/injectable.dart';
|
||||
import '../repositories/evenement_repository.dart';
|
||||
|
||||
/// Use case pour soumettre un feedback après un événement
|
||||
/// Note: Cette fonctionnalité nécessite un endpoint backend dédié
|
||||
@injectable
|
||||
class SubmitEventFeedback {
|
||||
final IEvenementRepository _repository;
|
||||
|
||||
SubmitEventFeedback(this._repository);
|
||||
|
||||
/// Exécute le use case
|
||||
///
|
||||
/// [evenementId] - UUID de l'événement
|
||||
/// [note] - Note de 1 à 5
|
||||
/// [commentaire] - Commentaire (optionnel)
|
||||
///
|
||||
/// Soumet un feedback pour l'événement
|
||||
/// Réservé aux participants de l'événement
|
||||
///
|
||||
/// TODO: Ajouter endpoint backend POST /api/evenements/{id}/feedback
|
||||
/// Lève une exception si:
|
||||
/// - L'événement n'existe pas
|
||||
/// - Le membre n'a pas participé
|
||||
/// - L'événement n'est pas terminé
|
||||
Future<void> call({
|
||||
required String evenementId,
|
||||
required int note,
|
||||
String? commentaire,
|
||||
}) async {
|
||||
// TODO: Implémenter quand endpoint backend sera disponible
|
||||
throw UnimplementedError(
|
||||
'Endpoint POST /api/evenements/{id}/feedback non implémenté côté backend',
|
||||
);
|
||||
}
|
||||
}
|
||||
26
lib/features/events/domain/usecases/update_event.dart
Normal file
26
lib/features/events/domain/usecases/update_event.dart
Normal file
@@ -0,0 +1,26 @@
|
||||
/// Use case: Mettre à jour un événement existant
|
||||
library update_event;
|
||||
|
||||
import 'package:injectable/injectable.dart';
|
||||
import '../../data/models/evenement_model.dart';
|
||||
import '../repositories/evenement_repository.dart';
|
||||
|
||||
/// Use case pour modifier un événement
|
||||
/// Réservé à l'organisateur de l'événement ou ADMIN_ORGANISATION
|
||||
@injectable
|
||||
class UpdateEvent {
|
||||
final IEvenementRepository _repository;
|
||||
|
||||
UpdateEvent(this._repository);
|
||||
|
||||
/// Exécute le use case
|
||||
///
|
||||
/// [id] - UUID de l'événement à modifier
|
||||
/// [evenement] - Données mises à jour
|
||||
///
|
||||
/// Retourne l'événement modifié
|
||||
/// Lève une exception si l'événement n'existe pas ou erreur de validation
|
||||
Future<EvenementModel> call(String id, EvenementModel evenement) async {
|
||||
return _repository.updateEvenement(id, evenement);
|
||||
}
|
||||
}
|
||||
441
lib/features/events/presentation/pages/event_detail_page.dart
Normal file
441
lib/features/events/presentation/pages/event_detail_page.dart
Normal file
@@ -0,0 +1,441 @@
|
||||
/// Page de détails d'un événement
|
||||
library event_detail_page;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import '../../../../core/di/injection.dart';
|
||||
import '../../bloc/evenements_bloc.dart';
|
||||
import '../../bloc/evenements_state.dart';
|
||||
import '../../data/models/evenement_model.dart';
|
||||
import '../../domain/repositories/evenement_repository.dart';
|
||||
import '../widgets/inscription_event_dialog.dart';
|
||||
import '../widgets/edit_event_dialog.dart';
|
||||
|
||||
class EventDetailPage extends StatefulWidget {
|
||||
final EvenementModel evenement;
|
||||
|
||||
const EventDetailPage({
|
||||
super.key,
|
||||
required this.evenement,
|
||||
});
|
||||
|
||||
@override
|
||||
State<EventDetailPage> createState() => _EventDetailPageState();
|
||||
}
|
||||
|
||||
class _EventDetailPageState extends State<EventDetailPage> {
|
||||
bool? _isInscrit;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_loadInscriptionStatus();
|
||||
}
|
||||
|
||||
Future<void> _loadInscriptionStatus() async {
|
||||
final id = widget.evenement.id?.toString();
|
||||
if (id == null || id.isEmpty) {
|
||||
if (mounted) setState(() => _isInscrit = false);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
final repo = getIt<IEvenementRepository>();
|
||||
final value = await repo.getInscriptionStatus(id);
|
||||
if (mounted) setState(() => _isInscrit = value);
|
||||
} catch (_) {
|
||||
if (mounted) setState(() => _isInscrit = false);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Détails de l\'événement'),
|
||||
backgroundColor: const Color(0xFF3B82F6),
|
||||
foregroundColor: Colors.white,
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.edit),
|
||||
onPressed: () => _showEditDialog(context),
|
||||
),
|
||||
],
|
||||
),
|
||||
body: BlocBuilder<EvenementsBloc, EvenementsState>(
|
||||
builder: (context, state) {
|
||||
return SingleChildScrollView(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_buildHeader(),
|
||||
_buildInfoSection(),
|
||||
_buildDescriptionSection(),
|
||||
if (widget.evenement.lieu != null) _buildLocationSection(),
|
||||
_buildParticipantsSection(),
|
||||
const SizedBox(height: 80), // Espace pour le bouton flottant
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
floatingActionButton: _buildInscriptionButton(context),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildHeader() {
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.all(24),
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
colors: [
|
||||
const Color(0xFF3B82F6),
|
||||
const Color(0xFF3B82F6).withOpacity(0.8),
|
||||
],
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withOpacity(0.2),
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
),
|
||||
child: Text(
|
||||
_getTypeLabel(widget.evenement.type),
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
widget.evenement.titre,
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 24,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Row(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: _getStatutColor(widget.evenement.statut),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: Text(
|
||||
_getStatutLabel(widget.evenement.statut),
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildInfoSection() {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
children: [
|
||||
_buildInfoRow(
|
||||
Icons.calendar_today,
|
||||
'Date de début',
|
||||
_formatDate(widget.evenement.dateDebut),
|
||||
),
|
||||
const Divider(),
|
||||
_buildInfoRow(
|
||||
Icons.event,
|
||||
'Date de fin',
|
||||
_formatDate(widget.evenement.dateFin),
|
||||
),
|
||||
if (widget.evenement.maxParticipants != null) ...[
|
||||
const Divider(),
|
||||
_buildInfoRow(
|
||||
Icons.people,
|
||||
'Places',
|
||||
'${widget.evenement.participantsActuels} / ${widget.evenement.maxParticipants}',
|
||||
),
|
||||
],
|
||||
if (widget.evenement.organisateurNom != null) ...[
|
||||
const Divider(),
|
||||
_buildInfoRow(
|
||||
Icons.person,
|
||||
'Organisateur',
|
||||
widget.evenement.organisateurNom!,
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildInfoRow(IconData icon, String label, String value) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(icon, color: const Color(0xFF3B82F6), size: 20),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
label,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: Colors.grey[600],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
value,
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDescriptionSection() {
|
||||
if (widget.evenement.description == null) return const SizedBox.shrink();
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'Description',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
widget.evenement.description!,
|
||||
style: const TextStyle(fontSize: 14, height: 1.5),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildLocationSection() {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'Lieu',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Row(
|
||||
children: [
|
||||
const Icon(Icons.location_on, color: Color(0xFF3B82F6)),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
widget.evenement.lieu!,
|
||||
style: const TextStyle(fontSize: 14),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildParticipantsSection() {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
const Text(
|
||||
'Participants',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'${widget.evenement.participantsActuels} inscrits',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: Colors.grey[600],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Container(
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey[100],
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: const Row(
|
||||
children: [
|
||||
Icon(Icons.info_outline, size: 20),
|
||||
SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
'La liste des participants est visible uniquement pour les organisateurs',
|
||||
style: TextStyle(fontSize: 12),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildInscriptionButton(BuildContext context) {
|
||||
final isInscrit = _isInscrit ?? false;
|
||||
final placesRestantes = (widget.evenement.maxParticipants ?? 0) -
|
||||
widget.evenement.participantsActuels;
|
||||
final isComplet = placesRestantes <= 0 && widget.evenement.maxParticipants != null;
|
||||
|
||||
if (!isComplet) {
|
||||
return FloatingActionButton.extended(
|
||||
onPressed: () => _showInscriptionDialog(context, isInscrit),
|
||||
backgroundColor: const Color(0xFF3B82F6),
|
||||
icon: const Icon(Icons.check),
|
||||
label: const Text('S\'inscrire'),
|
||||
);
|
||||
} else {
|
||||
return const FloatingActionButton.extended(
|
||||
onPressed: null,
|
||||
backgroundColor: Colors.grey,
|
||||
icon: Icon(Icons.block),
|
||||
label: Text('Complet'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void _showInscriptionDialog(BuildContext context, bool isInscrit) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => BlocProvider.value(
|
||||
value: context.read<EvenementsBloc>(),
|
||||
child: InscriptionEventDialog(
|
||||
evenement: widget.evenement,
|
||||
isInscrit: isInscrit,
|
||||
),
|
||||
),
|
||||
).then((_) => _loadInscriptionStatus());
|
||||
}
|
||||
|
||||
void _showEditDialog(BuildContext context) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => BlocProvider.value(
|
||||
value: context.read<EvenementsBloc>(),
|
||||
child: EditEventDialog(evenement: widget.evenement),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
String _formatDate(DateTime date) {
|
||||
final months = [
|
||||
'janvier', 'février', 'mars', 'avril', 'mai', 'juin',
|
||||
'juillet', 'août', 'septembre', 'octobre', 'novembre', 'décembre'
|
||||
];
|
||||
return '${date.day} ${months[date.month - 1]} ${date.year} à ${date.hour}:${date.minute.toString().padLeft(2, '0')}';
|
||||
}
|
||||
|
||||
String _getTypeLabel(TypeEvenement type) {
|
||||
switch (type) {
|
||||
case TypeEvenement.assembleeGenerale:
|
||||
return 'Assemblée Générale';
|
||||
case TypeEvenement.reunion:
|
||||
return 'Réunion';
|
||||
case TypeEvenement.formation:
|
||||
return 'Formation';
|
||||
case TypeEvenement.conference:
|
||||
return 'Conférence';
|
||||
case TypeEvenement.atelier:
|
||||
return 'Atelier';
|
||||
case TypeEvenement.seminaire:
|
||||
return 'Séminaire';
|
||||
case TypeEvenement.evenementSocial:
|
||||
return 'Événement Social';
|
||||
case TypeEvenement.manifestation:
|
||||
return 'Manifestation';
|
||||
case TypeEvenement.celebration:
|
||||
return 'Célébration';
|
||||
case TypeEvenement.autre:
|
||||
return 'Autre';
|
||||
}
|
||||
}
|
||||
|
||||
String _getStatutLabel(StatutEvenement statut) {
|
||||
switch (statut) {
|
||||
case StatutEvenement.planifie:
|
||||
return 'Planifié';
|
||||
case StatutEvenement.confirme:
|
||||
return 'Confirmé';
|
||||
case StatutEvenement.enCours:
|
||||
return 'En cours';
|
||||
case StatutEvenement.termine:
|
||||
return 'Terminé';
|
||||
case StatutEvenement.annule:
|
||||
return 'Annulé';
|
||||
case StatutEvenement.reporte:
|
||||
return 'Reporté';
|
||||
}
|
||||
}
|
||||
|
||||
Color _getStatutColor(StatutEvenement statut) {
|
||||
switch (statut) {
|
||||
case StatutEvenement.planifie:
|
||||
return Colors.blue;
|
||||
case StatutEvenement.confirme:
|
||||
return Colors.green;
|
||||
case StatutEvenement.enCours:
|
||||
return Colors.orange;
|
||||
case StatutEvenement.termine:
|
||||
return Colors.grey;
|
||||
case StatutEvenement.annule:
|
||||
return Colors.red;
|
||||
case StatutEvenement.reporte:
|
||||
return Colors.purple;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,451 @@
|
||||
import 'dart:async';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import '../../../../core/constants/app_constants.dart';
|
||||
import '../../../../shared/design_system/unionflow_design_v2.dart';
|
||||
import '../../../../shared/design_system/components/uf_app_bar.dart';
|
||||
import '../../../authentication/data/models/user_role.dart';
|
||||
import '../../../authentication/presentation/bloc/auth_bloc.dart';
|
||||
import '../../bloc/evenements_bloc.dart';
|
||||
import '../../bloc/evenements_event.dart';
|
||||
import '../../data/models/evenement_model.dart';
|
||||
import 'event_detail_page.dart';
|
||||
|
||||
/// Page Événements - Design UnionFlow
|
||||
class EventsPageWithData extends StatefulWidget {
|
||||
final List<EvenementModel> events;
|
||||
final int totalCount;
|
||||
final int currentPage;
|
||||
final int totalPages;
|
||||
final void Function(String? query)? onSearch;
|
||||
final VoidCallback? onAddEvent;
|
||||
final void Function(int page, String? recherche)? onPageChanged;
|
||||
|
||||
const EventsPageWithData({
|
||||
super.key,
|
||||
required this.events,
|
||||
required this.totalCount,
|
||||
required this.currentPage,
|
||||
required this.totalPages,
|
||||
this.onSearch,
|
||||
this.onAddEvent,
|
||||
this.onPageChanged,
|
||||
});
|
||||
|
||||
@override
|
||||
State<EventsPageWithData> createState() => _EventsPageWithDataState();
|
||||
}
|
||||
|
||||
class _EventsPageWithDataState extends State<EventsPageWithData> with TickerProviderStateMixin {
|
||||
final TextEditingController _searchController = TextEditingController();
|
||||
late TabController _tabController;
|
||||
String _searchQuery = '';
|
||||
Timer? _searchDebounce;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_tabController = TabController(length: 4, vsync: this);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_searchDebounce?.cancel();
|
||||
_searchController.dispose();
|
||||
_tabController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<AuthBloc, AuthState>(
|
||||
builder: (context, state) {
|
||||
if (state is! AuthAuthenticated) {
|
||||
return const Scaffold(body: Center(child: CircularProgressIndicator()));
|
||||
}
|
||||
|
||||
final canManageEvents = state.effectiveRole.level >= UserRole.moderator.level;
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: UnionFlowColors.background,
|
||||
appBar: UFAppBar(
|
||||
title: 'Événements',
|
||||
backgroundColor: UnionFlowColors.surface,
|
||||
foregroundColor: UnionFlowColors.textPrimary,
|
||||
actions: [
|
||||
if (canManageEvents && widget.onAddEvent != null)
|
||||
IconButton(
|
||||
icon: const Icon(Icons.add_circle_outline),
|
||||
color: UnionFlowColors.unionGreen,
|
||||
onPressed: widget.onAddEvent,
|
||||
tooltip: 'Créer un événement',
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
],
|
||||
),
|
||||
body: Column(
|
||||
children: [
|
||||
_buildHeader(),
|
||||
_buildSearchBar(),
|
||||
_buildTabs(),
|
||||
Expanded(
|
||||
child: TabBarView(
|
||||
controller: _tabController,
|
||||
children: [
|
||||
_buildEventsList(widget.events, 'tous'),
|
||||
_buildEventsList(widget.events.where((e) => e.estAVenir).toList(), 'à venir'),
|
||||
_buildEventsList(widget.events.where((e) => e.estEnCours).toList(), 'en cours'),
|
||||
_buildEventsList(widget.events.where((e) => e.estPasse).toList(), 'passés'),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (widget.totalPages > 1) _buildPagination(),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildHeader() {
|
||||
final upcoming = widget.events.where((e) => e.estAVenir).length;
|
||||
final ongoing = widget.events.where((e) => e.estEnCours).length;
|
||||
final total = widget.totalCount;
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(20),
|
||||
decoration: BoxDecoration(
|
||||
color: UnionFlowColors.surface,
|
||||
border: Border(bottom: BorderSide(color: UnionFlowColors.border.withOpacity(0.5), width: 1)),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(child: _buildStatCard(Icons.event_available, 'À venir', upcoming.toString(), UnionFlowColors.success)),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(child: _buildStatCard(Icons.play_circle_outline, 'En cours', ongoing.toString(), UnionFlowColors.amber)),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(child: _buildStatCard(Icons.calendar_today, 'Total', total.toString(), UnionFlowColors.unionGreen)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildStatCard(IconData icon, String label, String value, Color color) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
color: color.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(color: color.withOpacity(0.3), width: 1),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
Icon(icon, size: 20, color: color),
|
||||
const SizedBox(height: 6),
|
||||
Text(value, style: TextStyle(fontSize: 18, fontWeight: FontWeight.w700, color: color)),
|
||||
const SizedBox(height: 2),
|
||||
Text(label, style: TextStyle(fontSize: 10, fontWeight: FontWeight.w600, color: color), textAlign: TextAlign.center),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSearchBar() {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
||||
decoration: BoxDecoration(
|
||||
color: UnionFlowColors.surface,
|
||||
border: Border(bottom: BorderSide(color: UnionFlowColors.border.withOpacity(0.5), width: 1)),
|
||||
),
|
||||
child: TextField(
|
||||
controller: _searchController,
|
||||
onChanged: (v) {
|
||||
setState(() => _searchQuery = v);
|
||||
_searchDebounce?.cancel();
|
||||
_searchDebounce = Timer(AppConstants.searchDebounce, () {
|
||||
widget.onSearch?.call(v.isEmpty ? null : v);
|
||||
});
|
||||
},
|
||||
style: const TextStyle(fontSize: 14, color: UnionFlowColors.textPrimary),
|
||||
decoration: InputDecoration(
|
||||
hintText: 'Rechercher un événement...',
|
||||
hintStyle: const TextStyle(fontSize: 13, color: UnionFlowColors.textTertiary),
|
||||
prefixIcon: const Icon(Icons.search, size: 20, color: UnionFlowColors.textSecondary),
|
||||
suffixIcon: _searchQuery.isNotEmpty
|
||||
? IconButton(
|
||||
icon: const Icon(Icons.clear, size: 18, color: UnionFlowColors.textSecondary),
|
||||
onPressed: () {
|
||||
_searchDebounce?.cancel();
|
||||
_searchController.clear();
|
||||
setState(() => _searchQuery = '');
|
||||
widget.onSearch?.call(null);
|
||||
},
|
||||
)
|
||||
: null,
|
||||
contentPadding: const EdgeInsets.symmetric(vertical: 12, horizontal: 16),
|
||||
border: OutlineInputBorder(borderRadius: BorderRadius.circular(12), borderSide: BorderSide(color: UnionFlowColors.border.withOpacity(0.3))),
|
||||
enabledBorder: OutlineInputBorder(borderRadius: BorderRadius.circular(12), borderSide: BorderSide(color: UnionFlowColors.border.withOpacity(0.3))),
|
||||
focusedBorder: OutlineInputBorder(borderRadius: BorderRadius.circular(12), borderSide: const BorderSide(color: UnionFlowColors.unionGreen, width: 1.5)),
|
||||
filled: true,
|
||||
fillColor: UnionFlowColors.surfaceVariant.withOpacity(0.3),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTabs() {
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
color: UnionFlowColors.surface,
|
||||
border: Border(bottom: BorderSide(color: UnionFlowColors.border.withOpacity(0.5), width: 1)),
|
||||
),
|
||||
child: TabBar(
|
||||
controller: _tabController,
|
||||
labelColor: UnionFlowColors.unionGreen,
|
||||
unselectedLabelColor: UnionFlowColors.textSecondary,
|
||||
indicatorColor: UnionFlowColors.unionGreen,
|
||||
indicatorWeight: 3,
|
||||
labelStyle: const TextStyle(fontSize: 13, fontWeight: FontWeight.w700),
|
||||
unselectedLabelStyle: const TextStyle(fontSize: 13, fontWeight: FontWeight.w600),
|
||||
tabs: const [Tab(text: 'Tous'), Tab(text: 'À venir'), Tab(text: 'En cours'), Tab(text: 'Passés')],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildEventsList(List<EvenementModel> events, String type) {
|
||||
final filtered = _searchQuery.isEmpty
|
||||
? events
|
||||
: events.where((e) => e.titre.toLowerCase().contains(_searchQuery.toLowerCase()) || (e.lieu?.toLowerCase().contains(_searchQuery.toLowerCase()) ?? false)).toList();
|
||||
|
||||
if (filtered.isEmpty) return _buildEmptyState(type);
|
||||
|
||||
return RefreshIndicator(
|
||||
onRefresh: () async => context.read<EvenementsBloc>().add(const LoadEvenements()),
|
||||
color: UnionFlowColors.unionGreen,
|
||||
child: ListView.separated(
|
||||
padding: const EdgeInsets.all(16),
|
||||
itemCount: filtered.length,
|
||||
separatorBuilder: (_, __) => const SizedBox(height: 12),
|
||||
itemBuilder: (context, index) => _buildEventCard(filtered[index]),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildEventCard(EvenementModel event) {
|
||||
final df = DateFormat('dd MMM yyyy, HH:mm');
|
||||
|
||||
return GestureDetector(
|
||||
onTap: () => _showEventDetails(event),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: UnionFlowColors.surface,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
boxShadow: UnionFlowColors.softShadow,
|
||||
border: Border(left: BorderSide(color: _getStatutColor(event.statut), width: 4)),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
_buildBadge(_mapStatut(event.statut), _getStatutColor(event.statut)),
|
||||
const SizedBox(width: 8),
|
||||
_buildBadge(_mapType(event.type), UnionFlowColors.textSecondary),
|
||||
const Spacer(),
|
||||
const Icon(Icons.chevron_right, size: 18, color: UnionFlowColors.textTertiary),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Text(event.titre, style: const TextStyle(fontSize: 15, fontWeight: FontWeight.w700, color: UnionFlowColors.textPrimary), maxLines: 2, overflow: TextOverflow.ellipsis),
|
||||
const SizedBox(height: 12),
|
||||
Row(
|
||||
children: [
|
||||
const Icon(Icons.access_time, size: 14, color: UnionFlowColors.textSecondary),
|
||||
const SizedBox(width: 6),
|
||||
Text(df.format(event.dateDebut), style: const TextStyle(fontSize: 12, color: UnionFlowColors.textSecondary)),
|
||||
],
|
||||
),
|
||||
if (event.lieu != null) ...[
|
||||
const SizedBox(height: 6),
|
||||
Row(
|
||||
children: [
|
||||
const Icon(Icons.location_on_outlined, size: 14, color: UnionFlowColors.textSecondary),
|
||||
const SizedBox(width: 6),
|
||||
Expanded(child: Text(event.lieu!, style: const TextStyle(fontSize: 12, color: UnionFlowColors.textSecondary), maxLines: 1, overflow: TextOverflow.ellipsis)),
|
||||
],
|
||||
),
|
||||
],
|
||||
const SizedBox(height: 12),
|
||||
Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 24,
|
||||
height: 24,
|
||||
decoration: const BoxDecoration(gradient: UnionFlowColors.primaryGradient, shape: BoxShape.circle),
|
||||
alignment: Alignment.center,
|
||||
child: Text(event.organisateurNom?[0] ?? 'O', style: const TextStyle(color: Colors.white, fontWeight: FontWeight.w700, fontSize: 12)),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(child: Text(event.organisateurNom ?? 'Organisateur', style: const TextStyle(fontSize: 11, color: UnionFlowColors.textSecondary), maxLines: 1, overflow: TextOverflow.ellipsis)),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: UnionFlowColors.goldPale,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(color: UnionFlowColors.gold.withOpacity(0.3), width: 1),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Icon(Icons.people_outline, size: 12, color: UnionFlowColors.gold),
|
||||
const SizedBox(width: 4),
|
||||
Text('${event.participantsActuels}/${event.maxParticipants ?? "∞"}', style: const TextStyle(fontSize: 11, fontWeight: FontWeight.w600, color: UnionFlowColors.gold)),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildBadge(String text, Color color) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: color.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(color: color.withOpacity(0.3), width: 1),
|
||||
),
|
||||
child: Text(text, style: TextStyle(fontSize: 10, fontWeight: FontWeight.w600, color: color)),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildEmptyState(String type) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(24),
|
||||
decoration: const BoxDecoration(color: UnionFlowColors.goldPale, shape: BoxShape.circle),
|
||||
child: const Icon(Icons.event_busy, size: 64, color: UnionFlowColors.gold),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
Text('Aucun événement $type', style: const TextStyle(fontSize: 16, fontWeight: FontWeight.w700, color: UnionFlowColors.textPrimary)),
|
||||
const SizedBox(height: 8),
|
||||
Text(_searchQuery.isEmpty ? 'La liste est vide pour le moment' : 'Essayez une autre recherche', style: const TextStyle(fontSize: 13, color: UnionFlowColors.textSecondary)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPagination() {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(vertical: 12),
|
||||
decoration: BoxDecoration(
|
||||
color: UnionFlowColors.surface,
|
||||
border: Border(top: BorderSide(color: UnionFlowColors.border.withOpacity(0.5), width: 1)),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.chevron_left, size: 24),
|
||||
color: widget.currentPage > 0 ? UnionFlowColors.unionGreen : UnionFlowColors.textTertiary,
|
||||
onPressed: widget.currentPage > 0 && widget.onPageChanged != null
|
||||
? () => widget.onPageChanged!(widget.currentPage - 1, _searchQuery.isEmpty ? null : _searchQuery)
|
||||
: null,
|
||||
),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
decoration: BoxDecoration(gradient: UnionFlowColors.primaryGradient, borderRadius: BorderRadius.circular(20)),
|
||||
child: Text('Page ${widget.currentPage + 1} / ${widget.totalPages}', style: const TextStyle(fontSize: 13, fontWeight: FontWeight.w600, color: Colors.white)),
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.chevron_right, size: 24),
|
||||
color: widget.currentPage < widget.totalPages - 1 ? UnionFlowColors.unionGreen : UnionFlowColors.textTertiary,
|
||||
onPressed: widget.currentPage < widget.totalPages - 1 && widget.onPageChanged != null
|
||||
? () => widget.onPageChanged!(widget.currentPage + 1, _searchQuery.isEmpty ? null : _searchQuery)
|
||||
: null,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
String _mapStatut(StatutEvenement s) {
|
||||
switch (s) {
|
||||
case StatutEvenement.planifie:
|
||||
return 'Planifié';
|
||||
case StatutEvenement.confirme:
|
||||
return 'Confirmé';
|
||||
case StatutEvenement.enCours:
|
||||
return 'En cours';
|
||||
case StatutEvenement.termine:
|
||||
return 'Terminé';
|
||||
case StatutEvenement.annule:
|
||||
return 'Annulé';
|
||||
case StatutEvenement.reporte:
|
||||
return 'Reporté';
|
||||
}
|
||||
}
|
||||
|
||||
Color _getStatutColor(StatutEvenement s) {
|
||||
switch (s) {
|
||||
case StatutEvenement.planifie:
|
||||
return UnionFlowColors.info;
|
||||
case StatutEvenement.confirme:
|
||||
return UnionFlowColors.success;
|
||||
case StatutEvenement.enCours:
|
||||
return UnionFlowColors.amber;
|
||||
case StatutEvenement.termine:
|
||||
return UnionFlowColors.textSecondary;
|
||||
case StatutEvenement.annule:
|
||||
return UnionFlowColors.error;
|
||||
case StatutEvenement.reporte:
|
||||
return UnionFlowColors.warning;
|
||||
}
|
||||
}
|
||||
|
||||
String _mapType(TypeEvenement t) {
|
||||
switch (t) {
|
||||
case TypeEvenement.assembleeGenerale:
|
||||
return 'AG';
|
||||
case TypeEvenement.reunion:
|
||||
return 'Réunion';
|
||||
case TypeEvenement.formation:
|
||||
return 'Formation';
|
||||
case TypeEvenement.conference:
|
||||
return 'Conférence';
|
||||
case TypeEvenement.atelier:
|
||||
return 'Atelier';
|
||||
case TypeEvenement.seminaire:
|
||||
return 'Séminaire';
|
||||
case TypeEvenement.evenementSocial:
|
||||
return 'Social';
|
||||
case TypeEvenement.manifestation:
|
||||
return 'Manif.';
|
||||
case TypeEvenement.celebration:
|
||||
return 'Célébr.';
|
||||
case TypeEvenement.autre:
|
||||
return 'Autre';
|
||||
}
|
||||
}
|
||||
|
||||
void _showEventDetails(EvenementModel event) {
|
||||
final bloc = context.read<EvenementsBloc>();
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute<void>(
|
||||
builder: (_) => BlocProvider.value(
|
||||
value: bloc,
|
||||
child: EventDetailPage(evenement: event),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,830 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import '../../../../core/utils/logger.dart';
|
||||
import '../../../../shared/widgets/info_badge.dart';
|
||||
import '../../../../shared/widgets/mini_avatar.dart';
|
||||
import '../../../../shared/design_system/unionflow_design_system.dart';
|
||||
import '../../../../shared/design_system/tokens/app_typography.dart';
|
||||
import '../../../authentication/data/models/user_role.dart';
|
||||
import '../../../authentication/presentation/bloc/auth_bloc.dart';
|
||||
import '../../bloc/evenements_bloc.dart';
|
||||
import '../../bloc/evenements_event.dart';
|
||||
import '../../data/models/evenement_model.dart';
|
||||
|
||||
/// Page de gestion des événements - UI/UX Premium
|
||||
class EventsPageWithData extends StatefulWidget {
|
||||
final List<EvenementModel> events;
|
||||
final int totalCount;
|
||||
final int currentPage;
|
||||
final int totalPages;
|
||||
|
||||
const EventsPageWithData({
|
||||
super.key,
|
||||
required this.events,
|
||||
required this.totalCount,
|
||||
required this.currentPage,
|
||||
required this.totalPages,
|
||||
});
|
||||
|
||||
@override
|
||||
State<EventsPageWithData> createState() => _EventsPageWithDataState();
|
||||
}
|
||||
|
||||
class _EventsPageWithDataState extends State<EventsPageWithData>
|
||||
with TickerProviderStateMixin {
|
||||
final TextEditingController _searchController = TextEditingController();
|
||||
late TabController _tabController;
|
||||
String _searchQuery = '';
|
||||
bool _isSearchExpanded = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_tabController = TabController(length: 5, vsync: this);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_searchController.dispose();
|
||||
_tabController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<AuthBloc, AuthState>(
|
||||
builder: (context, state) {
|
||||
if (state is! AuthAuthenticated) {
|
||||
return const Scaffold(body: Center(child: CircularProgressIndicator()));
|
||||
}
|
||||
|
||||
final canManageEvents = state.effectiveRole.level >= UserRole.moderator.level;
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: ColorTokens.background,
|
||||
appBar: UFAppBar(
|
||||
title: 'ÉVÉNEMENTS',
|
||||
automaticallyImplyLeading: false,
|
||||
actions: [
|
||||
// Search toggle button
|
||||
IconButton(
|
||||
icon: Icon(
|
||||
_isSearchExpanded ? Icons.close : Icons.search,
|
||||
color: ColorTokens.onSurface,
|
||||
size: 20,
|
||||
),
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
_isSearchExpanded = !_isSearchExpanded;
|
||||
if (!_isSearchExpanded) {
|
||||
_searchController.clear();
|
||||
_searchQuery = '';
|
||||
}
|
||||
});
|
||||
},
|
||||
),
|
||||
if (canManageEvents)
|
||||
IconButton(
|
||||
icon: const Icon(
|
||||
Icons.add_circle_outline,
|
||||
color: ColorTokens.primary,
|
||||
size: 22,
|
||||
),
|
||||
onPressed: () => AppLogger.info('Add Event clicked'),
|
||||
),
|
||||
const SizedBox(width: SpacingTokens.xs),
|
||||
],
|
||||
),
|
||||
body: Column(
|
||||
children: [
|
||||
// Header avec stats compactes
|
||||
_buildCompactHeader(),
|
||||
|
||||
// Search bar (expandable)
|
||||
if (_isSearchExpanded) _buildSearchBar(),
|
||||
|
||||
// Tabs avec badges
|
||||
_buildEnhancedTabBar(),
|
||||
|
||||
// Liste d'événements
|
||||
Expanded(
|
||||
child: TabBarView(
|
||||
controller: _tabController,
|
||||
children: [
|
||||
_buildEventsList(widget.events, 'tous'),
|
||||
_buildEventsList(widget.events.where((e) => e.estAVenir).toList(), 'à venir'),
|
||||
_buildEventsList(widget.events.where((e) => e.estEnCours).toList(), 'en cours'),
|
||||
_buildEventsList(widget.events.where((e) => e.estPasse).toList(), 'passés'),
|
||||
_buildCalendarView(),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
// Pagination
|
||||
if (widget.totalPages > 1) _buildEnhancedPagination(),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/// Header compact avec 3 métriques en ligne
|
||||
Widget _buildCompactHeader() {
|
||||
final upcoming = widget.events.where((e) => e.estAVenir).length;
|
||||
final ongoing = widget.events.where((e) => e.estEnCours).length;
|
||||
final total = widget.totalCount;
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: SpacingTokens.md,
|
||||
vertical: SpacingTokens.sm,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: ColorTokens.surface,
|
||||
border: Border(
|
||||
bottom: BorderSide(
|
||||
color: ColorTokens.outlineVariant.withOpacity(0.5),
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
_buildCompactMetric(
|
||||
icon: Icons.event_available,
|
||||
label: 'À venir',
|
||||
value: upcoming.toString(),
|
||||
color: ColorTokens.success,
|
||||
),
|
||||
const SizedBox(width: SpacingTokens.md),
|
||||
_buildCompactMetric(
|
||||
icon: Icons.play_circle_outline,
|
||||
label: 'En cours',
|
||||
value: ongoing.toString(),
|
||||
color: ColorTokens.primary,
|
||||
),
|
||||
const Spacer(),
|
||||
_buildTotalBadge(total),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildCompactMetric({
|
||||
required IconData icon,
|
||||
required String label,
|
||||
required String value,
|
||||
required Color color,
|
||||
}) {
|
||||
return Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(6),
|
||||
decoration: BoxDecoration(
|
||||
color: color.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(RadiusTokens.sm),
|
||||
),
|
||||
child: Icon(icon, size: 14, color: color),
|
||||
),
|
||||
const SizedBox(width: SpacingTokens.xs),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
value,
|
||||
style: AppTypography.headerSmall.copyWith(
|
||||
fontSize: 16,
|
||||
height: 1.2,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
label,
|
||||
style: TypographyTokens.labelSmall.copyWith(
|
||||
fontSize: 10,
|
||||
color: ColorTokens.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTotalBadge(int total) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: SpacingTokens.sm,
|
||||
vertical: SpacingTokens.xs,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: ColorTokens.secondaryContainer,
|
||||
borderRadius: BorderRadius.circular(RadiusTokens.round),
|
||||
border: Border.all(
|
||||
color: ColorTokens.secondary.withOpacity(0.3),
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
total.toString(),
|
||||
style: AppTypography.actionText.copyWith(
|
||||
color: ColorTokens.secondary,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 14,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
'TOTAL',
|
||||
style: TypographyTokens.labelSmall.copyWith(
|
||||
color: ColorTokens.secondary,
|
||||
fontSize: 10,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Search bar avec animation
|
||||
Widget _buildSearchBar() {
|
||||
return AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 200),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: SpacingTokens.md,
|
||||
vertical: SpacingTokens.sm,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: ColorTokens.surface,
|
||||
border: Border(
|
||||
bottom: BorderSide(
|
||||
color: ColorTokens.outlineVariant.withOpacity(0.5),
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
),
|
||||
child: TextField(
|
||||
controller: _searchController,
|
||||
autofocus: true,
|
||||
onChanged: (v) => setState(() => _searchQuery = v),
|
||||
style: TypographyTokens.bodyMedium,
|
||||
decoration: InputDecoration(
|
||||
hintText: 'Rechercher un événement...',
|
||||
hintStyle: TypographyTokens.bodySmall.copyWith(
|
||||
color: ColorTokens.onSurfaceVariant,
|
||||
),
|
||||
prefixIcon: const Icon(
|
||||
Icons.search,
|
||||
size: 18,
|
||||
color: ColorTokens.onSurfaceVariant,
|
||||
),
|
||||
suffixIcon: _searchQuery.isNotEmpty
|
||||
? IconButton(
|
||||
icon: const Icon(
|
||||
Icons.clear,
|
||||
size: 18,
|
||||
color: ColorTokens.onSurfaceVariant,
|
||||
),
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
_searchController.clear();
|
||||
_searchQuery = '';
|
||||
});
|
||||
},
|
||||
)
|
||||
: null,
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
vertical: SpacingTokens.sm,
|
||||
horizontal: SpacingTokens.xs,
|
||||
),
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(RadiusTokens.md),
|
||||
borderSide: BorderSide(
|
||||
color: ColorTokens.outline.withOpacity(0.3),
|
||||
),
|
||||
),
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(RadiusTokens.md),
|
||||
borderSide: BorderSide(
|
||||
color: ColorTokens.outline.withOpacity(0.3),
|
||||
),
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(RadiusTokens.md),
|
||||
borderSide: const BorderSide(
|
||||
color: ColorTokens.primary,
|
||||
width: 1.5,
|
||||
),
|
||||
),
|
||||
filled: true,
|
||||
fillColor: ColorTokens.surfaceVariant.withOpacity(0.3),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// TabBar amélioré avec badges de comptage
|
||||
Widget _buildEnhancedTabBar() {
|
||||
final allCount = widget.events.length;
|
||||
final upcomingCount = widget.events.where((e) => e.estAVenir).length;
|
||||
final ongoingCount = widget.events.where((e) => e.estEnCours).length;
|
||||
final pastCount = widget.events.where((e) => e.estPasse).length;
|
||||
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
color: ColorTokens.surface,
|
||||
border: Border(
|
||||
bottom: BorderSide(
|
||||
color: ColorTokens.outlineVariant.withOpacity(0.5),
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
),
|
||||
child: TabBar(
|
||||
controller: _tabController,
|
||||
labelColor: ColorTokens.primary,
|
||||
unselectedLabelColor: ColorTokens.onSurfaceVariant,
|
||||
indicatorColor: ColorTokens.primary,
|
||||
indicatorWeight: 2.5,
|
||||
labelStyle: TypographyTokens.labelMedium.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
unselectedLabelStyle: TypographyTokens.labelMedium,
|
||||
tabs: [
|
||||
_buildTabWithBadge('Tous', allCount),
|
||||
_buildTabWithBadge('À venir', upcomingCount),
|
||||
_buildTabWithBadge('En cours', ongoingCount),
|
||||
_buildTabWithBadge('Passés', pastCount),
|
||||
const Tab(
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(Icons.calendar_month, size: 14),
|
||||
SizedBox(width: 4),
|
||||
Text('Calendrier'),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTabWithBadge(String label, int count) {
|
||||
return Tab(
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(label),
|
||||
if (count > 0) ...[
|
||||
const SizedBox(width: 4),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2),
|
||||
decoration: BoxDecoration(
|
||||
color: ColorTokens.primary.withOpacity(0.15),
|
||||
borderRadius: BorderRadius.circular(RadiusTokens.round),
|
||||
),
|
||||
child: Text(
|
||||
count.toString(),
|
||||
style: TypographyTokens.labelSmall.copyWith(
|
||||
fontSize: 9,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: ColorTokens.primary,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Liste d'événements optimisée
|
||||
Widget _buildEventsList(List<EvenementModel> events, String type) {
|
||||
final filtered = _searchQuery.isEmpty
|
||||
? events
|
||||
: events.where((e) =>
|
||||
e.titre.toLowerCase().contains(_searchQuery.toLowerCase()) ||
|
||||
(e.lieu?.toLowerCase().contains(_searchQuery.toLowerCase()) ?? false)
|
||||
).toList();
|
||||
|
||||
if (filtered.isEmpty) {
|
||||
return _buildEmptyState(type);
|
||||
}
|
||||
|
||||
return RefreshIndicator(
|
||||
onRefresh: () async => context.read<EvenementsBloc>().add(const LoadEvenements()),
|
||||
color: ColorTokens.primary,
|
||||
child: ListView.separated(
|
||||
padding: const EdgeInsets.all(SpacingTokens.md),
|
||||
itemCount: filtered.length,
|
||||
separatorBuilder: (_, __) => const SizedBox(height: SpacingTokens.sm),
|
||||
itemBuilder: (context, index) => _buildEnhancedEventCard(filtered[index]),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Empty state élégant
|
||||
Widget _buildEmptyState(String type) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(SpacingTokens.lg),
|
||||
decoration: BoxDecoration(
|
||||
color: ColorTokens.surfaceVariant.withOpacity(0.3),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: Icon(
|
||||
Icons.event_busy,
|
||||
size: 48,
|
||||
color: ColorTokens.onSurfaceVariant.withOpacity(0.5),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: SpacingTokens.md),
|
||||
Text(
|
||||
'Aucun événement $type',
|
||||
style: AppTypography.headerSmall.copyWith(
|
||||
color: ColorTokens.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: SpacingTokens.xs),
|
||||
Text(
|
||||
_searchQuery.isEmpty
|
||||
? 'La liste est vide pour le moment'
|
||||
: 'Aucun résultat pour "$_searchQuery"',
|
||||
style: TypographyTokens.bodySmall.copyWith(
|
||||
color: ColorTokens.onSurfaceVariant.withOpacity(0.7),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Card événement améliorée
|
||||
Widget _buildEnhancedEventCard(EvenementModel event) {
|
||||
final df = DateFormat('dd MMM yyyy, HH:mm');
|
||||
final isUrgent = event.estAVenir &&
|
||||
event.dateDebut.difference(DateTime.now()).inDays <= 2;
|
||||
|
||||
return UFCard(
|
||||
margin: EdgeInsets.zero,
|
||||
onTap: () => _showEventDetails(event),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// Header avec badges
|
||||
Row(
|
||||
children: [
|
||||
InfoBadge(
|
||||
text: _mapStatut(event.statut),
|
||||
backgroundColor: _getStatutColor(event.statut).withOpacity(0.12),
|
||||
textColor: _getStatutColor(event.statut),
|
||||
),
|
||||
const SizedBox(width: SpacingTokens.xs),
|
||||
InfoBadge.neutral(_mapType(event.type)),
|
||||
if (isUrgent) ...[
|
||||
const SizedBox(width: SpacingTokens.xs),
|
||||
InfoBadge(
|
||||
text: 'URGENT',
|
||||
backgroundColor: ColorTokens.error.withOpacity(0.12),
|
||||
textColor: ColorTokens.error,
|
||||
),
|
||||
],
|
||||
const Spacer(),
|
||||
Icon(
|
||||
Icons.chevron_right,
|
||||
size: 16,
|
||||
color: ColorTokens.onSurfaceVariant.withOpacity(0.5),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: SpacingTokens.sm),
|
||||
|
||||
// Titre
|
||||
Text(
|
||||
event.titre,
|
||||
style: AppTypography.headerSmall.copyWith(fontSize: 15),
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
|
||||
// Date et lieu
|
||||
const SizedBox(height: SpacingTokens.sm),
|
||||
Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.access_time,
|
||||
size: 12,
|
||||
color: ColorTokens.onSurfaceVariant,
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Expanded(
|
||||
child: Text(
|
||||
df.format(event.dateDebut),
|
||||
style: AppTypography.subtitleSmall,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
if (event.lieu != null) ...[
|
||||
const SizedBox(height: 4),
|
||||
Row(
|
||||
children: [
|
||||
const Icon(
|
||||
Icons.location_on_outlined,
|
||||
size: 12,
|
||||
color: ColorTokens.onSurfaceVariant,
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Expanded(
|
||||
child: Text(
|
||||
event.lieu!,
|
||||
style: AppTypography.subtitleSmall,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
|
||||
// Footer avec organisateur et participants
|
||||
const SizedBox(height: SpacingTokens.md),
|
||||
Row(
|
||||
children: [
|
||||
MiniAvatar(
|
||||
fallbackText: event.organisateurNom?[0] ?? 'O',
|
||||
size: 20,
|
||||
),
|
||||
const SizedBox(width: SpacingTokens.xs),
|
||||
Expanded(
|
||||
child: Text(
|
||||
event.organisateurNom ?? 'Organisateur',
|
||||
style: TypographyTokens.labelSmall.copyWith(fontSize: 11),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: SpacingTokens.xs,
|
||||
vertical: 2,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: ColorTokens.surfaceVariant,
|
||||
borderRadius: BorderRadius.circular(RadiusTokens.sm),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Icon(
|
||||
Icons.people_outline,
|
||||
size: 11,
|
||||
color: ColorTokens.onSurfaceVariant,
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
'${event.participantsActuels}/${event.maxParticipants ?? "∞"}',
|
||||
style: AppTypography.badgeText.copyWith(fontSize: 10),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Vue calendrier placeholder
|
||||
Widget _buildCalendarView() {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(SpacingTokens.xl),
|
||||
decoration: BoxDecoration(
|
||||
color: ColorTokens.surfaceVariant.withOpacity(0.3),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: Icon(
|
||||
Icons.calendar_month,
|
||||
size: 64,
|
||||
color: ColorTokens.onSurfaceVariant.withOpacity(0.5),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: SpacingTokens.lg),
|
||||
Text(
|
||||
'Vue Calendrier',
|
||||
style: AppTypography.headerSmall.copyWith(fontSize: 16),
|
||||
),
|
||||
const SizedBox(height: SpacingTokens.xs),
|
||||
Text(
|
||||
'Bientôt disponible',
|
||||
style: TypographyTokens.bodySmall.copyWith(
|
||||
color: ColorTokens.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Pagination améliorée
|
||||
Widget _buildEnhancedPagination() {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(vertical: SpacingTokens.sm),
|
||||
decoration: BoxDecoration(
|
||||
color: ColorTokens.surface,
|
||||
border: Border(
|
||||
top: BorderSide(
|
||||
color: ColorTokens.outlineVariant.withOpacity(0.5),
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.chevron_left, size: 20),
|
||||
color: widget.currentPage > 0
|
||||
? ColorTokens.primary
|
||||
: ColorTokens.onSurfaceVariant.withOpacity(0.3),
|
||||
onPressed: widget.currentPage > 0
|
||||
? () => context.read<EvenementsBloc>().add(
|
||||
LoadEvenements(page: widget.currentPage - 1),
|
||||
)
|
||||
: null,
|
||||
),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: SpacingTokens.md,
|
||||
vertical: SpacingTokens.xs,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: ColorTokens.primaryContainer.withOpacity(0.3),
|
||||
borderRadius: BorderRadius.circular(RadiusTokens.md),
|
||||
),
|
||||
child: Text(
|
||||
'Page ${widget.currentPage + 1} / ${widget.totalPages}',
|
||||
style: TypographyTokens.labelMedium.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: ColorTokens.primary,
|
||||
),
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.chevron_right, size: 20),
|
||||
color: widget.currentPage < widget.totalPages - 1
|
||||
? ColorTokens.primary
|
||||
: ColorTokens.onSurfaceVariant.withOpacity(0.3),
|
||||
onPressed: widget.currentPage < widget.totalPages - 1
|
||||
? () => context.read<EvenementsBloc>().add(
|
||||
LoadEvenements(page: widget.currentPage + 1),
|
||||
)
|
||||
: null,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
String _mapStatut(StatutEvenement s) {
|
||||
switch(s) {
|
||||
case StatutEvenement.planifie: return 'Planifié';
|
||||
case StatutEvenement.confirme: return 'Confirmé';
|
||||
case StatutEvenement.enCours: return 'En cours';
|
||||
case StatutEvenement.termine: return 'Terminé';
|
||||
case StatutEvenement.annule: return 'Annulé';
|
||||
case StatutEvenement.reporte: return 'Reporté';
|
||||
}
|
||||
}
|
||||
|
||||
Color _getStatutColor(StatutEvenement s) {
|
||||
switch(s) {
|
||||
case StatutEvenement.planifie: return ColorTokens.info;
|
||||
case StatutEvenement.confirme: return ColorTokens.success;
|
||||
case StatutEvenement.enCours: return ColorTokens.primary;
|
||||
case StatutEvenement.termine: return ColorTokens.secondary;
|
||||
case StatutEvenement.annule: return ColorTokens.error;
|
||||
case StatutEvenement.reporte: return ColorTokens.warning;
|
||||
}
|
||||
}
|
||||
|
||||
String _mapType(TypeEvenement t) {
|
||||
switch(t) {
|
||||
case TypeEvenement.assembleeGenerale: return 'AG';
|
||||
case TypeEvenement.reunion: return 'Réunion';
|
||||
case TypeEvenement.formation: return 'Formation';
|
||||
case TypeEvenement.conference: return 'Conférence';
|
||||
case TypeEvenement.atelier: return 'Atelier';
|
||||
case TypeEvenement.seminaire: return 'Séminaire';
|
||||
case TypeEvenement.evenementSocial: return 'Social';
|
||||
case TypeEvenement.manifestation: return 'Manifestation';
|
||||
case TypeEvenement.celebration: return 'Célébration';
|
||||
case TypeEvenement.autre: return 'Autre';
|
||||
}
|
||||
}
|
||||
|
||||
void _showEventDetails(EvenementModel event) {
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
backgroundColor: ColorTokens.surface,
|
||||
shape: const RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.vertical(top: Radius.circular(RadiusTokens.lg)),
|
||||
),
|
||||
builder: (context) => Container(
|
||||
padding: const EdgeInsets.all(SpacingTokens.xl),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// Header
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
event.titre,
|
||||
style: AppTypography.headerSmall.copyWith(fontSize: 16),
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.close, size: 20),
|
||||
onPressed: () => Navigator.pop(context),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: SpacingTokens.md),
|
||||
|
||||
// Badges
|
||||
Wrap(
|
||||
spacing: SpacingTokens.xs,
|
||||
runSpacing: SpacingTokens.xs,
|
||||
children: [
|
||||
InfoBadge(
|
||||
text: _mapStatut(event.statut),
|
||||
backgroundColor: _getStatutColor(event.statut).withOpacity(0.12),
|
||||
textColor: _getStatutColor(event.statut),
|
||||
),
|
||||
InfoBadge.neutral(_mapType(event.type)),
|
||||
],
|
||||
),
|
||||
|
||||
const SizedBox(height: SpacingTokens.lg),
|
||||
|
||||
// Description
|
||||
if (event.description != null && event.description!.isNotEmpty) ...[
|
||||
Text(
|
||||
'Description',
|
||||
style: AppTypography.actionText.copyWith(fontSize: 12),
|
||||
),
|
||||
const SizedBox(height: SpacingTokens.xs),
|
||||
Text(
|
||||
event.description!,
|
||||
style: TypographyTokens.bodySmall,
|
||||
),
|
||||
const SizedBox(height: SpacingTokens.lg),
|
||||
],
|
||||
|
||||
// Actions
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: UFSecondaryButton(
|
||||
label: 'Partager',
|
||||
onPressed: () => AppLogger.info('Share event'),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: SpacingTokens.sm),
|
||||
Expanded(
|
||||
child: UFPrimaryButton(
|
||||
label: 'Détails',
|
||||
onPressed: () => AppLogger.info('View details'),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
182
lib/features/events/presentation/pages/events_page_wrapper.dart
Normal file
182
lib/features/events/presentation/pages/events_page_wrapper.dart
Normal file
@@ -0,0 +1,182 @@
|
||||
/// Wrapper BLoC pour la page des événements
|
||||
///
|
||||
/// Ce fichier enveloppe la EventsPage existante avec le EvenementsBloc
|
||||
/// pour connecter l'UI riche existante à l'API backend réelle.
|
||||
library events_page_wrapper;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
|
||||
import '../../../../shared/widgets/error_widget.dart';
|
||||
import '../../../../shared/widgets/loading_widget.dart';
|
||||
import '../../../../core/utils/logger.dart';
|
||||
import '../../bloc/evenements_bloc.dart';
|
||||
import '../../bloc/evenements_event.dart';
|
||||
import '../../bloc/evenements_state.dart';
|
||||
import '../widgets/create_event_dialog.dart';
|
||||
import 'events_page_connected.dart';
|
||||
|
||||
final _getIt = GetIt.instance;
|
||||
|
||||
/// Wrapper qui fournit le BLoC à la page des événements
|
||||
class EventsPageWrapper extends StatelessWidget {
|
||||
const EventsPageWrapper({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
AppLogger.info('EventsPageWrapper: Création du BlocProvider');
|
||||
|
||||
return BlocProvider<EvenementsBloc>(
|
||||
create: (context) {
|
||||
AppLogger.info('EventsPageWrapper: Initialisation du EvenementsBloc');
|
||||
final bloc = _getIt<EvenementsBloc>();
|
||||
// Charger les événements au démarrage
|
||||
bloc.add(const LoadEvenements());
|
||||
return bloc;
|
||||
},
|
||||
child: const EventsPageConnected(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Page des événements connectée au BLoC
|
||||
///
|
||||
/// Cette page gère les états du BLoC et affiche l'UI appropriée
|
||||
class EventsPageConnected extends StatelessWidget {
|
||||
const EventsPageConnected({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocListener<EvenementsBloc, EvenementsState>(
|
||||
listener: (context, state) {
|
||||
if (state is EvenementCreated) {
|
||||
context.read<EvenementsBloc>().add(const LoadEvenements(refresh: true));
|
||||
}
|
||||
if (state is EvenementsError) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(state.message),
|
||||
backgroundColor: Colors.red,
|
||||
duration: const Duration(seconds: 4),
|
||||
action: SnackBarAction(
|
||||
label: 'Réessayer',
|
||||
textColor: Colors.white,
|
||||
onPressed: () {
|
||||
context.read<EvenementsBloc>().add(const LoadEvenements());
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
child: BlocBuilder<EvenementsBloc, EvenementsState>(
|
||||
builder: (context, state) {
|
||||
AppLogger.blocState('EvenementsBloc', state.runtimeType.toString());
|
||||
|
||||
// État initial
|
||||
if (state is EvenementsInitial) {
|
||||
return Container(
|
||||
color: const Color(0xFFF8F9FA),
|
||||
child: const Center(
|
||||
child: AppLoadingWidget(message: 'Initialisation...'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// État de chargement
|
||||
if (state is EvenementsLoading) {
|
||||
return Container(
|
||||
color: const Color(0xFFF8F9FA),
|
||||
child: const Center(
|
||||
child: AppLoadingWidget(message: 'Chargement des événements...'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// État de rafraîchissement
|
||||
if (state is EvenementsRefreshing) {
|
||||
return Container(
|
||||
color: const Color(0xFFF8F9FA),
|
||||
child: const Center(
|
||||
child: AppLoadingWidget(message: 'Actualisation...'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (state is EvenementCreated) {
|
||||
return Container(
|
||||
color: const Color(0xFFF8F9FA),
|
||||
child: const Center(
|
||||
child: AppLoadingWidget(message: 'Actualisation...'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (state is EvenementsLoaded) {
|
||||
final evenements = state.evenements;
|
||||
AppLogger.info('EventsPageConnected: ${evenements.length} événements chargés');
|
||||
|
||||
return EventsPageWithData(
|
||||
events: evenements,
|
||||
totalCount: state.total,
|
||||
currentPage: state.page,
|
||||
totalPages: state.totalPages,
|
||||
onSearch: (query) {
|
||||
context.read<EvenementsBloc>().add(LoadEvenements(page: 0, recherche: query));
|
||||
},
|
||||
onAddEvent: () async {
|
||||
await showDialog<void>(
|
||||
context: context,
|
||||
builder: (_) => const CreateEventDialog(),
|
||||
);
|
||||
},
|
||||
onPageChanged: (page, recherche) {
|
||||
context.read<EvenementsBloc>().add(LoadEvenements(page: page, recherche: recherche));
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
// État d'erreur réseau
|
||||
if (state is EvenementsNetworkError) {
|
||||
AppLogger.error('EventsPageConnected: Erreur réseau', error: state.message);
|
||||
return Container(
|
||||
color: const Color(0xFFF8F9FA),
|
||||
child: NetworkErrorWidget(
|
||||
onRetry: () {
|
||||
AppLogger.userAction('Retry load evenements after network error');
|
||||
context.read<EvenementsBloc>().add(const LoadEvenements());
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// État d'erreur générale
|
||||
if (state is EvenementsError) {
|
||||
AppLogger.error('EventsPageConnected: Erreur', error: state.message);
|
||||
return Container(
|
||||
color: const Color(0xFFF8F9FA),
|
||||
child: AppErrorWidget(
|
||||
message: state.message,
|
||||
onRetry: () {
|
||||
AppLogger.userAction('Retry load evenements after error');
|
||||
context.read<EvenementsBloc>().add(const LoadEvenements());
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// État par défaut
|
||||
AppLogger.warning('EventsPageConnected: État non géré: ${state.runtimeType}');
|
||||
return Container(
|
||||
color: const Color(0xFFF8F9FA),
|
||||
child: const Center(
|
||||
child: AppLoadingWidget(message: 'Chargement...'),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,442 @@
|
||||
/// Dialogue de création d'événement
|
||||
/// Formulaire complet pour créer un nouvel événement
|
||||
library create_event_dialog;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import '../../bloc/evenements_bloc.dart';
|
||||
import '../../bloc/evenements_event.dart';
|
||||
import '../../bloc/evenements_state.dart';
|
||||
import '../../data/models/evenement_model.dart';
|
||||
|
||||
/// Dialogue de création d'événement
|
||||
class CreateEventDialog extends StatefulWidget {
|
||||
const CreateEventDialog({super.key});
|
||||
|
||||
@override
|
||||
State<CreateEventDialog> createState() => _CreateEventDialogState();
|
||||
}
|
||||
|
||||
class _CreateEventDialogState extends State<CreateEventDialog> {
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
bool _createSent = false;
|
||||
|
||||
// Contrôleurs de texte
|
||||
final _titreController = TextEditingController();
|
||||
final _descriptionController = TextEditingController();
|
||||
final _lieuController = TextEditingController();
|
||||
final _adresseController = TextEditingController();
|
||||
final _capaciteController = TextEditingController();
|
||||
|
||||
// Valeurs sélectionnées
|
||||
DateTime _dateDebut = DateTime.now().add(const Duration(days: 7));
|
||||
DateTime? _dateFin;
|
||||
TypeEvenement _selectedType = TypeEvenement.autre;
|
||||
bool _inscriptionRequise = true;
|
||||
bool _visiblePublic = true;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_titreController.dispose();
|
||||
_descriptionController.dispose();
|
||||
_lieuController.dispose();
|
||||
_adresseController.dispose();
|
||||
_capaciteController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocListener<EvenementsBloc, EvenementsState>(
|
||||
listenWhen: (_, state) => _createSent && (state is EvenementCreated || state is EvenementsError),
|
||||
listener: (context, state) {
|
||||
if (!_createSent || !mounted) return;
|
||||
if (state is EvenementsError) {
|
||||
setState(() => _createSent = false);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(state.message), backgroundColor: Colors.red),
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (state is EvenementCreated) {
|
||||
setState(() => _createSent = false);
|
||||
Navigator.pop(context);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('Événement créé avec succès'),
|
||||
backgroundColor: Colors.green,
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
child: Dialog(
|
||||
child: Container(
|
||||
width: MediaQuery.of(context).size.width * 0.9,
|
||||
constraints: const BoxConstraints(maxHeight: 600),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
// En-tête
|
||||
Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: const BoxDecoration(
|
||||
color: Color(0xFF3B82F6),
|
||||
borderRadius: BorderRadius.only(
|
||||
topLeft: Radius.circular(4),
|
||||
topRight: Radius.circular(4),
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.event, color: Colors.white),
|
||||
const SizedBox(width: 12),
|
||||
const Text(
|
||||
'Créer un événement',
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.close, color: Colors.white),
|
||||
onPressed: () => Navigator.pop(context),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
// Formulaire
|
||||
Expanded(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Form(
|
||||
key: _formKey,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// Informations de base
|
||||
_buildSectionTitle('Informations de base'),
|
||||
const SizedBox(height: 12),
|
||||
|
||||
TextFormField(
|
||||
controller: _titreController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Titre *',
|
||||
border: OutlineInputBorder(),
|
||||
prefixIcon: Icon(Icons.title),
|
||||
),
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return 'Le titre est obligatoire';
|
||||
}
|
||||
if (value.length < 3) {
|
||||
return 'Le titre doit contenir au moins 3 caractères';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
|
||||
TextFormField(
|
||||
controller: _descriptionController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Description',
|
||||
border: OutlineInputBorder(),
|
||||
prefixIcon: Icon(Icons.description),
|
||||
),
|
||||
maxLines: 3,
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
|
||||
// Type d'événement
|
||||
DropdownButtonFormField<TypeEvenement>(
|
||||
value: _selectedType,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Type d\'événement *',
|
||||
border: OutlineInputBorder(),
|
||||
prefixIcon: Icon(Icons.category),
|
||||
),
|
||||
items: TypeEvenement.values.map((type) {
|
||||
return DropdownMenuItem(
|
||||
value: type,
|
||||
child: Text(_getTypeLabel(type)),
|
||||
);
|
||||
}).toList(),
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
_selectedType = value!;
|
||||
});
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// Dates
|
||||
_buildSectionTitle('Dates et horaires'),
|
||||
const SizedBox(height: 12),
|
||||
|
||||
InkWell(
|
||||
onTap: () => _selectDateDebut(context),
|
||||
child: InputDecorator(
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Date de début *',
|
||||
border: OutlineInputBorder(),
|
||||
prefixIcon: Icon(Icons.calendar_today),
|
||||
),
|
||||
child: Text(
|
||||
DateFormat('dd/MM/yyyy HH:mm').format(_dateDebut),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
|
||||
InkWell(
|
||||
onTap: () => _selectDateFin(context),
|
||||
child: InputDecorator(
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Date de fin (optionnel)',
|
||||
border: OutlineInputBorder(),
|
||||
prefixIcon: Icon(Icons.event_available),
|
||||
),
|
||||
child: Text(
|
||||
_dateFin != null
|
||||
? DateFormat('dd/MM/yyyy HH:mm').format(_dateFin!)
|
||||
: 'Sélectionner une date',
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// Lieu
|
||||
_buildSectionTitle('Lieu'),
|
||||
const SizedBox(height: 12),
|
||||
|
||||
TextFormField(
|
||||
controller: _lieuController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Lieu *',
|
||||
border: OutlineInputBorder(),
|
||||
prefixIcon: Icon(Icons.place),
|
||||
),
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return 'Le lieu est obligatoire';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
|
||||
TextFormField(
|
||||
controller: _adresseController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Adresse complète',
|
||||
border: OutlineInputBorder(),
|
||||
prefixIcon: Icon(Icons.location_on),
|
||||
),
|
||||
maxLines: 2,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// Paramètres
|
||||
_buildSectionTitle('Paramètres'),
|
||||
const SizedBox(height: 12),
|
||||
|
||||
TextFormField(
|
||||
controller: _capaciteController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Capacité maximale',
|
||||
border: OutlineInputBorder(),
|
||||
prefixIcon: Icon(Icons.people),
|
||||
hintText: 'Nombre de places disponibles',
|
||||
),
|
||||
keyboardType: TextInputType.number,
|
||||
validator: (value) {
|
||||
if (value != null && value.isNotEmpty) {
|
||||
final capacite = int.tryParse(value);
|
||||
if (capacite == null || capacite <= 0) {
|
||||
return 'Capacité invalide';
|
||||
}
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
|
||||
SwitchListTile(
|
||||
title: const Text('Inscription requise'),
|
||||
subtitle: const Text('Les participants doivent s\'inscrire'),
|
||||
value: _inscriptionRequise,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
_inscriptionRequise = value;
|
||||
});
|
||||
},
|
||||
),
|
||||
|
||||
SwitchListTile(
|
||||
title: const Text('Visible publiquement'),
|
||||
subtitle: const Text('L\'événement est visible par tous'),
|
||||
value: _visiblePublic,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
_visiblePublic = value;
|
||||
});
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// Boutons d'action
|
||||
Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey[100],
|
||||
border: Border(top: BorderSide(color: Colors.grey[300]!)),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('Annuler'),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
ElevatedButton(
|
||||
onPressed: _submitForm,
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: const Color(0xFF3B82F6),
|
||||
foregroundColor: Colors.white,
|
||||
),
|
||||
child: const Text('Créer l\'événement'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSectionTitle(String title) {
|
||||
return Text(
|
||||
title,
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Color(0xFF3B82F6),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
String _getTypeLabel(TypeEvenement type) {
|
||||
switch (type) {
|
||||
case TypeEvenement.assembleeGenerale:
|
||||
return 'Assemblée Générale';
|
||||
case TypeEvenement.reunion:
|
||||
return 'Réunion';
|
||||
case TypeEvenement.formation:
|
||||
return 'Formation';
|
||||
case TypeEvenement.conference:
|
||||
return 'Conférence';
|
||||
case TypeEvenement.atelier:
|
||||
return 'Atelier';
|
||||
case TypeEvenement.seminaire:
|
||||
return 'Séminaire';
|
||||
case TypeEvenement.evenementSocial:
|
||||
return 'Événement Social';
|
||||
case TypeEvenement.manifestation:
|
||||
return 'Manifestation';
|
||||
case TypeEvenement.celebration:
|
||||
return 'Célébration';
|
||||
case TypeEvenement.autre:
|
||||
return 'Autre';
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _selectDateDebut(BuildContext context) async {
|
||||
final DateTime? pickedDate = await showDatePicker(
|
||||
context: context,
|
||||
initialDate: _dateDebut,
|
||||
firstDate: DateTime.now(),
|
||||
lastDate: DateTime.now().add(const Duration(days: 365 * 2)),
|
||||
);
|
||||
|
||||
if (pickedDate != null) {
|
||||
final TimeOfDay? pickedTime = await showTimePicker(
|
||||
context: context,
|
||||
initialTime: TimeOfDay.fromDateTime(_dateDebut),
|
||||
);
|
||||
|
||||
if (pickedTime != null) {
|
||||
setState(() {
|
||||
_dateDebut = DateTime(
|
||||
pickedDate.year,
|
||||
pickedDate.month,
|
||||
pickedDate.day,
|
||||
pickedTime.hour,
|
||||
pickedTime.minute,
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _selectDateFin(BuildContext context) async {
|
||||
final DateTime? pickedDate = await showDatePicker(
|
||||
context: context,
|
||||
initialDate: _dateFin ?? _dateDebut.add(const Duration(hours: 2)),
|
||||
firstDate: _dateDebut,
|
||||
lastDate: DateTime.now().add(const Duration(days: 365 * 2)),
|
||||
);
|
||||
|
||||
if (pickedDate != null) {
|
||||
final TimeOfDay? pickedTime = await showTimePicker(
|
||||
context: context,
|
||||
initialTime: TimeOfDay.fromDateTime(_dateFin ?? _dateDebut.add(const Duration(hours: 2))),
|
||||
);
|
||||
|
||||
if (pickedTime != null) {
|
||||
setState(() {
|
||||
_dateFin = DateTime(
|
||||
pickedDate.year,
|
||||
pickedDate.month,
|
||||
pickedDate.day,
|
||||
pickedTime.hour,
|
||||
pickedTime.minute,
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void _submitForm() {
|
||||
if (_formKey.currentState!.validate()) {
|
||||
// Créer le modèle d'événement
|
||||
final evenement = EvenementModel(
|
||||
titre: _titreController.text,
|
||||
description: _descriptionController.text.isNotEmpty ? _descriptionController.text : null,
|
||||
dateDebut: _dateDebut,
|
||||
dateFin: _dateFin ?? _dateDebut.add(const Duration(hours: 2)),
|
||||
lieu: _lieuController.text,
|
||||
adresse: _adresseController.text.isNotEmpty ? _adresseController.text : null,
|
||||
type: _selectedType,
|
||||
maxParticipants: _capaciteController.text.isNotEmpty ? int.parse(_capaciteController.text) : null,
|
||||
inscriptionRequise: _inscriptionRequise,
|
||||
estPublic: _visiblePublic,
|
||||
statut: StatutEvenement.planifie,
|
||||
);
|
||||
|
||||
setState(() => _createSent = true);
|
||||
context.read<EvenementsBloc>().add(CreateEvenement(evenement));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
525
lib/features/events/presentation/widgets/edit_event_dialog.dart
Normal file
525
lib/features/events/presentation/widgets/edit_event_dialog.dart
Normal file
@@ -0,0 +1,525 @@
|
||||
/// Dialogue de modification d'événement
|
||||
/// Formulaire pré-rempli pour modifier un événement existant
|
||||
library edit_event_dialog;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import '../../bloc/evenements_bloc.dart';
|
||||
import '../../bloc/evenements_event.dart';
|
||||
import '../../bloc/evenements_state.dart';
|
||||
import '../../data/models/evenement_model.dart';
|
||||
|
||||
/// Dialogue de modification d'événement
|
||||
class EditEventDialog extends StatefulWidget {
|
||||
final EvenementModel evenement;
|
||||
|
||||
const EditEventDialog({
|
||||
super.key,
|
||||
required this.evenement,
|
||||
});
|
||||
|
||||
@override
|
||||
State<EditEventDialog> createState() => _EditEventDialogState();
|
||||
}
|
||||
|
||||
class _EditEventDialogState extends State<EditEventDialog> {
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
bool _updateSent = false;
|
||||
|
||||
// Contrôleurs de texte
|
||||
late final TextEditingController _titreController;
|
||||
late final TextEditingController _descriptionController;
|
||||
late final TextEditingController _lieuController;
|
||||
late final TextEditingController _adresseController;
|
||||
late final TextEditingController _capaciteController;
|
||||
|
||||
// Valeurs sélectionnées
|
||||
late DateTime _dateDebut;
|
||||
late DateTime _dateFin;
|
||||
late TypeEvenement _selectedType;
|
||||
late StatutEvenement _selectedStatut;
|
||||
late bool _inscriptionRequise;
|
||||
late bool _estPublic;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
// Initialiser les contrôleurs avec les valeurs existantes
|
||||
_titreController = TextEditingController(text: widget.evenement.titre);
|
||||
_descriptionController = TextEditingController(text: widget.evenement.description ?? '');
|
||||
_lieuController = TextEditingController(text: widget.evenement.lieu ?? '');
|
||||
_adresseController = TextEditingController(text: widget.evenement.adresse ?? '');
|
||||
_capaciteController = TextEditingController(
|
||||
text: widget.evenement.maxParticipants?.toString() ?? '',
|
||||
);
|
||||
|
||||
// Initialiser les valeurs
|
||||
_dateDebut = widget.evenement.dateDebut;
|
||||
_dateFin = widget.evenement.dateFin;
|
||||
_selectedType = widget.evenement.type;
|
||||
_selectedStatut = widget.evenement.statut;
|
||||
_inscriptionRequise = widget.evenement.inscriptionRequise;
|
||||
_estPublic = widget.evenement.estPublic;
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_titreController.dispose();
|
||||
_descriptionController.dispose();
|
||||
_lieuController.dispose();
|
||||
_adresseController.dispose();
|
||||
_capaciteController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocListener<EvenementsBloc, EvenementsState>(
|
||||
listenWhen: (_, state) => _updateSent && (state is EvenementUpdated || state is EvenementsError),
|
||||
listener: (context, state) {
|
||||
if (!_updateSent || !mounted) return;
|
||||
if (state is EvenementsError) {
|
||||
setState(() => _updateSent = false);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(state.message), backgroundColor: Colors.red),
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (state is EvenementUpdated) {
|
||||
setState(() => _updateSent = false);
|
||||
Navigator.pop(context);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('Événement modifié avec succès'),
|
||||
backgroundColor: Colors.green,
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
child: Dialog(
|
||||
child: Container(
|
||||
width: MediaQuery.of(context).size.width * 0.9,
|
||||
constraints: const BoxConstraints(maxHeight: 600),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
// En-tête
|
||||
Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: const BoxDecoration(
|
||||
color: Color(0xFF3B82F6),
|
||||
borderRadius: BorderRadius.only(
|
||||
topLeft: Radius.circular(4),
|
||||
topRight: Radius.circular(4),
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.edit, color: Colors.white),
|
||||
const SizedBox(width: 12),
|
||||
const Text(
|
||||
'Modifier l\'événement',
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.close, color: Colors.white),
|
||||
onPressed: () => Navigator.pop(context),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
// Formulaire
|
||||
Expanded(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Form(
|
||||
key: _formKey,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// Informations de base
|
||||
_buildSectionTitle('Informations de base'),
|
||||
const SizedBox(height: 12),
|
||||
|
||||
TextFormField(
|
||||
controller: _titreController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Titre *',
|
||||
border: OutlineInputBorder(),
|
||||
prefixIcon: Icon(Icons.title),
|
||||
),
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return 'Le titre est obligatoire';
|
||||
}
|
||||
if (value.length < 3) {
|
||||
return 'Le titre doit contenir au moins 3 caractères';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
|
||||
TextFormField(
|
||||
controller: _descriptionController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Description',
|
||||
border: OutlineInputBorder(),
|
||||
prefixIcon: Icon(Icons.description),
|
||||
),
|
||||
maxLines: 3,
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
|
||||
// Type et statut
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: DropdownButtonFormField<TypeEvenement>(
|
||||
value: _selectedType,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Type *',
|
||||
border: OutlineInputBorder(),
|
||||
prefixIcon: Icon(Icons.category),
|
||||
),
|
||||
items: TypeEvenement.values.map((type) {
|
||||
return DropdownMenuItem(
|
||||
value: type,
|
||||
child: Text(_getTypeLabel(type)),
|
||||
);
|
||||
}).toList(),
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
_selectedType = value!;
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: DropdownButtonFormField<StatutEvenement>(
|
||||
value: _selectedStatut,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Statut *',
|
||||
border: OutlineInputBorder(),
|
||||
prefixIcon: Icon(Icons.flag),
|
||||
),
|
||||
items: StatutEvenement.values.map((statut) {
|
||||
return DropdownMenuItem(
|
||||
value: statut,
|
||||
child: Text(_getStatutLabel(statut)),
|
||||
);
|
||||
}).toList(),
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
_selectedStatut = value!;
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// Dates
|
||||
_buildSectionTitle('Dates et horaires'),
|
||||
const SizedBox(height: 12),
|
||||
|
||||
InkWell(
|
||||
onTap: () => _selectDateDebut(context),
|
||||
child: InputDecorator(
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Date de début *',
|
||||
border: OutlineInputBorder(),
|
||||
prefixIcon: Icon(Icons.calendar_today),
|
||||
),
|
||||
child: Text(
|
||||
DateFormat('dd/MM/yyyy HH:mm').format(_dateDebut),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
|
||||
InkWell(
|
||||
onTap: () => _selectDateFin(context),
|
||||
child: InputDecorator(
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Date de fin *',
|
||||
border: OutlineInputBorder(),
|
||||
prefixIcon: Icon(Icons.event_available),
|
||||
),
|
||||
child: Text(
|
||||
DateFormat('dd/MM/yyyy HH:mm').format(_dateFin),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// Lieu
|
||||
_buildSectionTitle('Lieu'),
|
||||
const SizedBox(height: 12),
|
||||
|
||||
TextFormField(
|
||||
controller: _lieuController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Lieu *',
|
||||
border: OutlineInputBorder(),
|
||||
prefixIcon: Icon(Icons.place),
|
||||
),
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return 'Le lieu est obligatoire';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
|
||||
TextFormField(
|
||||
controller: _adresseController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Adresse complète',
|
||||
border: OutlineInputBorder(),
|
||||
prefixIcon: Icon(Icons.location_on),
|
||||
),
|
||||
maxLines: 2,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// Capacité
|
||||
_buildSectionTitle('Paramètres'),
|
||||
const SizedBox(height: 12),
|
||||
|
||||
TextFormField(
|
||||
controller: _capaciteController,
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Capacité maximale',
|
||||
border: const OutlineInputBorder(),
|
||||
prefixIcon: const Icon(Icons.people),
|
||||
suffixText: widget.evenement.participantsActuels > 0
|
||||
? '${widget.evenement.participantsActuels} inscrits'
|
||||
: null,
|
||||
),
|
||||
keyboardType: TextInputType.number,
|
||||
validator: (value) {
|
||||
if (value != null && value.isNotEmpty) {
|
||||
final capacite = int.tryParse(value);
|
||||
if (capacite == null || capacite <= 0) {
|
||||
return 'La capacité doit être un nombre positif';
|
||||
}
|
||||
if (capacite < widget.evenement.participantsActuels) {
|
||||
return 'La capacité ne peut pas être inférieure au nombre d\'inscrits (${widget.evenement.participantsActuels})';
|
||||
}
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
|
||||
SwitchListTile(
|
||||
title: const Text('Inscription requise'),
|
||||
subtitle: const Text('Les participants doivent s\'inscrire'),
|
||||
value: _inscriptionRequise,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
_inscriptionRequise = value;
|
||||
});
|
||||
},
|
||||
),
|
||||
|
||||
SwitchListTile(
|
||||
title: const Text('Événement public'),
|
||||
subtitle: const Text('Visible par tous les membres'),
|
||||
value: _estPublic,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
_estPublic = value;
|
||||
});
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// Boutons d'action
|
||||
Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey[100],
|
||||
border: Border(top: BorderSide(color: Colors.grey[300]!)),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('Annuler'),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
ElevatedButton(
|
||||
onPressed: _submitForm,
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: const Color(0xFF3B82F6),
|
||||
foregroundColor: Colors.white,
|
||||
),
|
||||
child: const Text('Enregistrer'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSectionTitle(String title) {
|
||||
return Text(
|
||||
title,
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Color(0xFF3B82F6),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
String _getTypeLabel(TypeEvenement type) {
|
||||
switch (type) {
|
||||
case TypeEvenement.assembleeGenerale:
|
||||
return 'Assemblée Générale';
|
||||
case TypeEvenement.reunion:
|
||||
return 'Réunion';
|
||||
case TypeEvenement.formation:
|
||||
return 'Formation';
|
||||
case TypeEvenement.conference:
|
||||
return 'Conférence';
|
||||
case TypeEvenement.atelier:
|
||||
return 'Atelier';
|
||||
case TypeEvenement.seminaire:
|
||||
return 'Séminaire';
|
||||
case TypeEvenement.evenementSocial:
|
||||
return 'Événement Social';
|
||||
case TypeEvenement.manifestation:
|
||||
return 'Manifestation';
|
||||
case TypeEvenement.celebration:
|
||||
return 'Célébration';
|
||||
case TypeEvenement.autre:
|
||||
return 'Autre';
|
||||
}
|
||||
}
|
||||
|
||||
String _getStatutLabel(StatutEvenement statut) {
|
||||
switch (statut) {
|
||||
case StatutEvenement.planifie:
|
||||
return 'Planifié';
|
||||
case StatutEvenement.confirme:
|
||||
return 'Confirmé';
|
||||
case StatutEvenement.enCours:
|
||||
return 'En cours';
|
||||
case StatutEvenement.termine:
|
||||
return 'Terminé';
|
||||
case StatutEvenement.annule:
|
||||
return 'Annulé';
|
||||
case StatutEvenement.reporte:
|
||||
return 'Reporté';
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _selectDateDebut(BuildContext context) async {
|
||||
final DateTime? pickedDate = await showDatePicker(
|
||||
context: context,
|
||||
initialDate: _dateDebut,
|
||||
firstDate: DateTime.now().subtract(const Duration(days: 365)),
|
||||
lastDate: DateTime.now().add(const Duration(days: 365 * 2)),
|
||||
);
|
||||
|
||||
if (pickedDate != null) {
|
||||
final TimeOfDay? pickedTime = await showTimePicker(
|
||||
context: context,
|
||||
initialTime: TimeOfDay.fromDateTime(_dateDebut),
|
||||
);
|
||||
|
||||
if (pickedTime != null) {
|
||||
setState(() {
|
||||
_dateDebut = DateTime(
|
||||
pickedDate.year,
|
||||
pickedDate.month,
|
||||
pickedDate.day,
|
||||
pickedTime.hour,
|
||||
pickedTime.minute,
|
||||
);
|
||||
|
||||
// Ajuster la date de fin si elle est avant la date de début
|
||||
if (_dateFin.isBefore(_dateDebut)) {
|
||||
_dateFin = _dateDebut.add(const Duration(hours: 2));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _selectDateFin(BuildContext context) async {
|
||||
final DateTime? pickedDate = await showDatePicker(
|
||||
context: context,
|
||||
initialDate: _dateFin,
|
||||
firstDate: _dateDebut,
|
||||
lastDate: DateTime.now().add(const Duration(days: 365 * 2)),
|
||||
);
|
||||
|
||||
if (pickedDate != null) {
|
||||
final TimeOfDay? pickedTime = await showTimePicker(
|
||||
context: context,
|
||||
initialTime: TimeOfDay.fromDateTime(_dateFin),
|
||||
);
|
||||
|
||||
if (pickedTime != null) {
|
||||
setState(() {
|
||||
_dateFin = DateTime(
|
||||
pickedDate.year,
|
||||
pickedDate.month,
|
||||
pickedDate.day,
|
||||
pickedTime.hour,
|
||||
pickedTime.minute,
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void _submitForm() {
|
||||
if (_formKey.currentState!.validate()) {
|
||||
// Créer le modèle d'événement mis à jour
|
||||
final evenementUpdated = widget.evenement.copyWith(
|
||||
titre: _titreController.text,
|
||||
description: _descriptionController.text.isNotEmpty ? _descriptionController.text : null,
|
||||
dateDebut: _dateDebut,
|
||||
dateFin: _dateFin,
|
||||
lieu: _lieuController.text,
|
||||
adresse: _adresseController.text.isNotEmpty ? _adresseController.text : null,
|
||||
type: _selectedType,
|
||||
statut: _selectedStatut,
|
||||
maxParticipants: _capaciteController.text.isNotEmpty ? int.parse(_capaciteController.text) : null,
|
||||
inscriptionRequise: _inscriptionRequise,
|
||||
estPublic: _estPublic,
|
||||
);
|
||||
|
||||
setState(() => _updateSent = true);
|
||||
context.read<EvenementsBloc>().add(UpdateEvenement(widget.evenement.id!.toString(), evenementUpdated));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,337 @@
|
||||
/// Dialogue d'inscription à un événement
|
||||
library inscription_event_dialog;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import '../../bloc/evenements_bloc.dart';
|
||||
import '../../bloc/evenements_event.dart';
|
||||
import '../../bloc/evenements_state.dart';
|
||||
import '../../data/models/evenement_model.dart';
|
||||
|
||||
class InscriptionEventDialog extends StatefulWidget {
|
||||
final EvenementModel evenement;
|
||||
final bool isInscrit;
|
||||
|
||||
const InscriptionEventDialog({
|
||||
super.key,
|
||||
required this.evenement,
|
||||
this.isInscrit = false,
|
||||
});
|
||||
|
||||
@override
|
||||
State<InscriptionEventDialog> createState() => _InscriptionEventDialogState();
|
||||
}
|
||||
|
||||
class _InscriptionEventDialogState extends State<InscriptionEventDialog> {
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
final _commentaireController = TextEditingController();
|
||||
bool _actionSent = false;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_commentaireController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocListener<EvenementsBloc, EvenementsState>(
|
||||
listenWhen: (_, state) =>
|
||||
_actionSent &&
|
||||
(state is EvenementInscrit ||
|
||||
state is EvenementDesinscrit ||
|
||||
state is EvenementsError),
|
||||
listener: (context, state) {
|
||||
if (!_actionSent || !mounted) return;
|
||||
if (state is EvenementsError) {
|
||||
setState(() => _actionSent = false);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(state.message), backgroundColor: Colors.red),
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (state is EvenementInscrit || state is EvenementDesinscrit) {
|
||||
setState(() => _actionSent = false);
|
||||
Navigator.pop(context);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
state is EvenementInscrit
|
||||
? 'Inscription réussie'
|
||||
: 'Désinscription réussie',
|
||||
),
|
||||
backgroundColor:
|
||||
state is EvenementInscrit ? Colors.green : Colors.orange,
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
child: Dialog(
|
||||
child: Container(
|
||||
width: MediaQuery.of(context).size.width * 0.9,
|
||||
constraints: const BoxConstraints(maxHeight: 500),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
_buildHeader(),
|
||||
Expanded(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Form(
|
||||
key: _formKey,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_buildEventInfo(),
|
||||
const SizedBox(height: 16),
|
||||
if (!widget.isInscrit) ...[
|
||||
_buildPlacesInfo(),
|
||||
const SizedBox(height: 16),
|
||||
_buildCommentaireField(),
|
||||
] else ...[
|
||||
_buildDesinscriptionWarning(),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
_buildActionButtons(),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildHeader() {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: widget.isInscrit ? Colors.red : const Color(0xFF3B82F6),
|
||||
borderRadius: const BorderRadius.only(
|
||||
topLeft: Radius.circular(4),
|
||||
topRight: Radius.circular(4),
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
widget.isInscrit ? Icons.cancel : Icons.event_available,
|
||||
color: Colors.white,
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Text(
|
||||
widget.isInscrit ? 'Se désinscrire' : 'S\'inscrire à l\'événement',
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.close, color: Colors.white),
|
||||
onPressed: () => Navigator.pop(context),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildEventInfo() {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.blue[50],
|
||||
border: Border.all(color: Colors.blue[200]!),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
const Icon(Icons.event, color: Color(0xFF3B82F6)),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
widget.evenement.titre,
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Row(
|
||||
children: [
|
||||
const Icon(Icons.calendar_today, size: 16, color: Colors.grey),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
_formatDate(widget.evenement.dateDebut),
|
||||
style: const TextStyle(fontSize: 14),
|
||||
),
|
||||
],
|
||||
),
|
||||
if (widget.evenement.lieu != null) ...[
|
||||
const SizedBox(height: 4),
|
||||
Row(
|
||||
children: [
|
||||
const Icon(Icons.location_on, size: 16, color: Colors.grey),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
widget.evenement.lieu!,
|
||||
style: const TextStyle(fontSize: 14),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPlacesInfo() {
|
||||
final placesRestantes = (widget.evenement.maxParticipants ?? 0) -
|
||||
widget.evenement.participantsActuels;
|
||||
final isComplet = placesRestantes <= 0 && widget.evenement.maxParticipants != null;
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
color: isComplet ? Colors.red[50] : Colors.green[50],
|
||||
border: Border.all(
|
||||
color: isComplet ? Colors.red[200]! : Colors.green[200]!,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
isComplet ? Icons.warning : Icons.check_circle,
|
||||
color: isComplet ? Colors.red : Colors.green,
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
isComplet ? 'Événement complet' : 'Places disponibles',
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: isComplet ? Colors.red[900] : Colors.green[900],
|
||||
),
|
||||
),
|
||||
if (widget.evenement.maxParticipants != null)
|
||||
Text(
|
||||
'$placesRestantes places restantes sur ${widget.evenement.maxParticipants}',
|
||||
style: const TextStyle(fontSize: 12),
|
||||
)
|
||||
else
|
||||
const Text(
|
||||
'Nombre de places illimité',
|
||||
style: TextStyle(fontSize: 12),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildCommentaireField() {
|
||||
return TextFormField(
|
||||
controller: _commentaireController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Commentaire (optionnel)',
|
||||
border: OutlineInputBorder(),
|
||||
prefixIcon: Icon(Icons.comment),
|
||||
hintText: 'Ajoutez un commentaire...',
|
||||
),
|
||||
maxLines: 3,
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDesinscriptionWarning() {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.orange[50],
|
||||
border: Border.all(color: Colors.orange[200]!),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: const Row(
|
||||
children: [
|
||||
Icon(Icons.warning, color: Colors.orange),
|
||||
SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Text(
|
||||
'Êtes-vous sûr de vouloir vous désinscrire de cet événement ?',
|
||||
style: TextStyle(fontSize: 14),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildActionButtons() {
|
||||
final placesRestantes = (widget.evenement.maxParticipants ?? 0) -
|
||||
widget.evenement.participantsActuels;
|
||||
final isComplet = placesRestantes <= 0 && widget.evenement.maxParticipants != null;
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey[100],
|
||||
border: Border(top: BorderSide(color: Colors.grey[300]!)),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('Annuler'),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
ElevatedButton(
|
||||
onPressed: (widget.isInscrit || !isComplet) ? _submitForm : null,
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: widget.isInscrit ? Colors.red : const Color(0xFF3B82F6),
|
||||
foregroundColor: Colors.white,
|
||||
),
|
||||
child: Text(widget.isInscrit ? 'Se désinscrire' : 'S\'inscrire'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
String _formatDate(DateTime date) {
|
||||
final months = [
|
||||
'janvier', 'février', 'mars', 'avril', 'mai', 'juin',
|
||||
'juillet', 'août', 'septembre', 'octobre', 'novembre', 'décembre'
|
||||
];
|
||||
return '${date.day} ${months[date.month - 1]} ${date.year} à ${date.hour}:${date.minute.toString().padLeft(2, '0')}';
|
||||
}
|
||||
|
||||
void _submitForm() {
|
||||
setState(() => _actionSent = true);
|
||||
if (widget.isInscrit) {
|
||||
context.read<EvenementsBloc>().add(DesinscrireEvenement(widget.evenement.id!.toString()));
|
||||
} else {
|
||||
context.read<EvenementsBloc>().add(
|
||||
InscrireEvenement(widget.evenement.id!.toString()),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user