Initial commit: unionflow-mobile-apps

Application Flutter complète (sans build artifacts).

Signed-off-by: lions dev Team
This commit is contained in:
dahoud
2026-03-15 16:30:08 +00:00
commit d094d6db9c
1790 changed files with 507435 additions and 0 deletions

View File

@@ -0,0 +1,143 @@
/// BLoC pour la gestion des adhésions (demandes d'adhésion)
library adhesions_bloc;
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:equatable/equatable.dart';
import 'package:injectable/injectable.dart';
import '../../../core/utils/logger.dart';
import '../data/models/adhesion_model.dart';
import '../data/repositories/adhesion_repository.dart';
part 'adhesions_event.dart';
part 'adhesions_state.dart';
@injectable
class AdhesionsBloc extends Bloc<AdhesionsEvent, AdhesionsState> {
final AdhesionRepository _repository;
AdhesionsBloc(this._repository) : super(const AdhesionsState()) {
on<LoadAdhesions>(_onLoadAdhesions);
on<LoadAdhesionsByMembre>(_onLoadAdhesionsByMembre);
on<LoadAdhesionsEnAttente>(_onLoadAdhesionsEnAttente);
on<LoadAdhesionsByStatut>(_onLoadAdhesionsByStatut);
on<LoadAdhesionById>(_onLoadAdhesionById);
on<CreateAdhesion>(_onCreateAdhesion);
on<ApprouverAdhesion>(_onApprouverAdhesion);
on<RejeterAdhesion>(_onRejeterAdhesion);
on<EnregistrerPaiementAdhesion>(_onEnregistrerPaiementAdhesion);
on<LoadAdhesionsStats>(_onLoadAdhesionsStats);
}
Future<void> _onLoadAdhesions(LoadAdhesions event, Emitter<AdhesionsState> emit) async {
emit(state.copyWith(status: AdhesionsStatus.loading, message: 'Chargement...'));
try {
final list = await _repository.getAll(page: event.page, size: event.size);
emit(state.copyWith(status: AdhesionsStatus.loaded, adhesions: list));
} catch (e) {
emit(state.copyWith(status: AdhesionsStatus.error, message: e.toString(), error: e));
}
}
Future<void> _onLoadAdhesionsByMembre(LoadAdhesionsByMembre event, Emitter<AdhesionsState> emit) async {
emit(state.copyWith(status: AdhesionsStatus.loading, message: 'Chargement...'));
try {
final list = await _repository.getByMembre(event.membreId, page: event.page, size: event.size);
emit(state.copyWith(status: AdhesionsStatus.loaded, adhesions: list));
} catch (e) {
emit(state.copyWith(status: AdhesionsStatus.error, message: e.toString(), error: e));
}
}
Future<void> _onLoadAdhesionsEnAttente(LoadAdhesionsEnAttente event, Emitter<AdhesionsState> emit) async {
emit(state.copyWith(status: AdhesionsStatus.loading, message: 'Chargement...'));
try {
final list = await _repository.getEnAttente(page: event.page, size: event.size);
emit(state.copyWith(status: AdhesionsStatus.loaded, adhesions: list));
} catch (e) {
emit(state.copyWith(status: AdhesionsStatus.error, message: e.toString(), error: e));
}
}
Future<void> _onLoadAdhesionsByStatut(LoadAdhesionsByStatut event, Emitter<AdhesionsState> emit) async {
emit(state.copyWith(status: AdhesionsStatus.loading, message: 'Chargement...'));
try {
final list = await _repository.getByStatut(event.statut, page: event.page, size: event.size);
emit(state.copyWith(status: AdhesionsStatus.loaded, adhesions: list));
} catch (e) {
emit(state.copyWith(status: AdhesionsStatus.error, message: e.toString(), error: e));
}
}
Future<void> _onLoadAdhesionById(LoadAdhesionById event, Emitter<AdhesionsState> emit) async {
emit(state.copyWith(status: AdhesionsStatus.loading));
try {
final adhesion = await _repository.getById(event.id);
emit(state.copyWith(status: AdhesionsStatus.loaded, adhesionDetail: adhesion));
} catch (e) {
emit(state.copyWith(status: AdhesionsStatus.error, message: e.toString(), error: e));
}
}
Future<void> _onCreateAdhesion(CreateAdhesion event, Emitter<AdhesionsState> emit) async {
emit(state.copyWith(status: AdhesionsStatus.loading, message: 'Création...'));
try {
await _repository.create(event.adhesion);
add(const LoadAdhesions());
} catch (e) {
emit(state.copyWith(status: AdhesionsStatus.error, message: e.toString(), error: e));
}
}
Future<void> _onApprouverAdhesion(ApprouverAdhesion event, Emitter<AdhesionsState> emit) async {
emit(state.copyWith(status: AdhesionsStatus.loading));
try {
final updated = await _repository.approuver(event.id, approuvePar: event.approuvePar);
emit(state.copyWith(status: AdhesionsStatus.loaded, adhesionDetail: updated));
add(const LoadAdhesions());
} catch (e) {
emit(state.copyWith(status: AdhesionsStatus.error, message: e.toString(), error: e));
}
}
Future<void> _onRejeterAdhesion(RejeterAdhesion event, Emitter<AdhesionsState> emit) async {
emit(state.copyWith(status: AdhesionsStatus.loading));
try {
final updated = await _repository.rejeter(event.id, event.motifRejet);
emit(state.copyWith(status: AdhesionsStatus.loaded, adhesionDetail: updated));
add(const LoadAdhesions());
} catch (e) {
emit(state.copyWith(status: AdhesionsStatus.error, message: e.toString(), error: e));
}
}
Future<void> _onEnregistrerPaiementAdhesion(EnregistrerPaiementAdhesion event, Emitter<AdhesionsState> emit) async {
emit(state.copyWith(status: AdhesionsStatus.loading));
try {
final updated = await _repository.enregistrerPaiement(
event.id,
montantPaye: event.montantPaye,
methodePaiement: event.methodePaiement,
referencePaiement: event.referencePaiement,
);
emit(state.copyWith(status: AdhesionsStatus.loaded, adhesionDetail: updated));
add(const LoadAdhesions());
} catch (e) {
emit(state.copyWith(status: AdhesionsStatus.error, message: e.toString(), error: e));
}
}
Future<void> _onLoadAdhesionsStats(LoadAdhesionsStats event, Emitter<AdhesionsState> emit) async {
try {
final stats = await _repository.getStats();
emit(state.copyWith(stats: stats));
} catch (e, st) {
AppLogger.error('AdhesionsBloc: chargement stats échoué', error: e, stackTrace: st);
emit(state.copyWith(
status: AdhesionsStatus.error,
message: e.toString(),
error: e,
));
}
}
}

View File

@@ -0,0 +1,90 @@
part of 'adhesions_bloc.dart';
abstract class AdhesionsEvent extends Equatable {
const AdhesionsEvent();
@override
List<Object?> get props => [];
}
class LoadAdhesions extends AdhesionsEvent {
final int page;
final int size;
const LoadAdhesions({this.page = 0, this.size = 20});
@override
List<Object?> get props => [page, size];
}
class LoadAdhesionsByMembre extends AdhesionsEvent {
final String membreId;
final int page;
final int size;
const LoadAdhesionsByMembre(this.membreId, {this.page = 0, this.size = 20});
@override
List<Object?> get props => [membreId, page, size];
}
class LoadAdhesionsEnAttente extends AdhesionsEvent {
final int page;
final int size;
const LoadAdhesionsEnAttente({this.page = 0, this.size = 20});
@override
List<Object?> get props => [page, size];
}
class LoadAdhesionsByStatut extends AdhesionsEvent {
final String statut;
final int page;
final int size;
const LoadAdhesionsByStatut(this.statut, {this.page = 0, this.size = 20});
@override
List<Object?> get props => [statut, page, size];
}
class LoadAdhesionById extends AdhesionsEvent {
final String id;
const LoadAdhesionById(this.id);
@override
List<Object?> get props => [id];
}
class CreateAdhesion extends AdhesionsEvent {
final AdhesionModel adhesion;
const CreateAdhesion(this.adhesion);
@override
List<Object?> get props => [adhesion];
}
class ApprouverAdhesion extends AdhesionsEvent {
final String id;
final String? approuvePar;
const ApprouverAdhesion(this.id, {this.approuvePar});
@override
List<Object?> get props => [id, approuvePar];
}
class RejeterAdhesion extends AdhesionsEvent {
final String id;
final String motifRejet;
const RejeterAdhesion(this.id, this.motifRejet);
@override
List<Object?> get props => [id, motifRejet];
}
class EnregistrerPaiementAdhesion extends AdhesionsEvent {
final String id;
final double montantPaye;
final String? methodePaiement;
final String? referencePaiement;
const EnregistrerPaiementAdhesion(
this.id, {
required this.montantPaye,
this.methodePaiement,
this.referencePaiement,
});
@override
List<Object?> get props => [id, montantPaye, methodePaiement, referencePaiement];
}
class LoadAdhesionsStats extends AdhesionsEvent {
const LoadAdhesionsStats();
}

View File

@@ -0,0 +1,42 @@
part of 'adhesions_bloc.dart';
enum AdhesionsStatus { initial, loading, loaded, error }
class AdhesionsState extends Equatable {
final AdhesionsStatus status;
final List<AdhesionModel> adhesions;
final AdhesionModel? adhesionDetail;
final Map<String, dynamic>? stats;
final String? message;
final Object? error;
const AdhesionsState({
this.status = AdhesionsStatus.initial,
this.adhesions = const [],
this.adhesionDetail,
this.stats,
this.message,
this.error,
});
AdhesionsState copyWith({
AdhesionsStatus? status,
List<AdhesionModel>? adhesions,
AdhesionModel? adhesionDetail,
Map<String, dynamic>? stats,
String? message,
Object? error,
}) {
return AdhesionsState(
status: status ?? this.status,
adhesions: adhesions ?? this.adhesions,
adhesionDetail: adhesionDetail ?? this.adhesionDetail,
stats: stats ?? this.stats,
message: message ?? this.message,
error: error ?? this.error,
);
}
@override
List<Object?> get props => [status, adhesions, adhesionDetail, stats, message, error];
}