Versione OK Pour l'onglet événements.
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
import '../../../../core/models/cotisation_model.dart';
|
||||
import '../../../../core/models/payment_model.dart';
|
||||
import '../../../../core/services/payment_service.dart';
|
||||
import '../../../../core/services/notification_service.dart';
|
||||
import '../../domain/repositories/cotisation_repository.dart';
|
||||
import 'cotisations_event.dart';
|
||||
import 'cotisations_state.dart';
|
||||
@@ -10,8 +13,14 @@ import 'cotisations_state.dart';
|
||||
@injectable
|
||||
class CotisationsBloc extends Bloc<CotisationsEvent, CotisationsState> {
|
||||
final CotisationRepository _cotisationRepository;
|
||||
final PaymentService _paymentService;
|
||||
final NotificationService _notificationService;
|
||||
|
||||
CotisationsBloc(this._cotisationRepository) : super(const CotisationsInitial()) {
|
||||
CotisationsBloc(
|
||||
this._cotisationRepository,
|
||||
this._paymentService,
|
||||
this._notificationService,
|
||||
) : super(const CotisationsInitial()) {
|
||||
// Enregistrement des handlers d'événements
|
||||
on<LoadCotisations>(_onLoadCotisations);
|
||||
on<LoadCotisationById>(_onLoadCotisationById);
|
||||
@@ -28,6 +37,15 @@ class CotisationsBloc extends Bloc<CotisationsEvent, CotisationsState> {
|
||||
on<ResetCotisationsState>(_onResetCotisationsState);
|
||||
on<FilterCotisations>(_onFilterCotisations);
|
||||
on<SortCotisations>(_onSortCotisations);
|
||||
|
||||
// Nouveaux handlers pour les paiements et fonctionnalités avancées
|
||||
on<InitiatePayment>(_onInitiatePayment);
|
||||
on<CheckPaymentStatus>(_onCheckPaymentStatus);
|
||||
on<CancelPayment>(_onCancelPayment);
|
||||
on<ScheduleNotifications>(_onScheduleNotifications);
|
||||
on<SyncWithServer>(_onSyncWithServer);
|
||||
on<ApplyAdvancedFilters>(_onApplyAdvancedFilters);
|
||||
on<ExportCotisations>(_onExportCotisations);
|
||||
}
|
||||
|
||||
/// Handler pour charger la liste des cotisations
|
||||
@@ -506,4 +524,207 @@ class CotisationsBloc extends Bloc<CotisationsEvent, CotisationsState> {
|
||||
emit(currentState.copyWith(filteredCotisations: sortedList));
|
||||
}
|
||||
}
|
||||
|
||||
/// Handler pour initier un paiement
|
||||
Future<void> _onInitiatePayment(
|
||||
InitiatePayment event,
|
||||
Emitter<CotisationsState> emit,
|
||||
) async {
|
||||
try {
|
||||
// Valider les données de paiement
|
||||
if (!_paymentService.validatePaymentData(
|
||||
cotisationId: event.cotisationId,
|
||||
montant: event.montant,
|
||||
methodePaiement: event.methodePaiement,
|
||||
numeroTelephone: event.numeroTelephone,
|
||||
)) {
|
||||
emit(PaymentFailure(
|
||||
cotisationId: event.cotisationId,
|
||||
paymentId: '',
|
||||
errorMessage: 'Données de paiement invalides',
|
||||
errorCode: 'INVALID_DATA',
|
||||
));
|
||||
return;
|
||||
}
|
||||
|
||||
// Initier le paiement
|
||||
final payment = await _paymentService.initiatePayment(
|
||||
cotisationId: event.cotisationId,
|
||||
montant: event.montant,
|
||||
methodePaiement: event.methodePaiement,
|
||||
numeroTelephone: event.numeroTelephone,
|
||||
nomPayeur: event.nomPayeur,
|
||||
emailPayeur: event.emailPayeur,
|
||||
);
|
||||
|
||||
emit(PaymentInProgress(
|
||||
cotisationId: event.cotisationId,
|
||||
paymentId: payment.id,
|
||||
methodePaiement: event.methodePaiement,
|
||||
montant: event.montant,
|
||||
));
|
||||
|
||||
} catch (e) {
|
||||
emit(PaymentFailure(
|
||||
cotisationId: event.cotisationId,
|
||||
paymentId: '',
|
||||
errorMessage: e.toString(),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/// Handler pour vérifier le statut d'un paiement
|
||||
Future<void> _onCheckPaymentStatus(
|
||||
CheckPaymentStatus event,
|
||||
Emitter<CotisationsState> emit,
|
||||
) async {
|
||||
try {
|
||||
final payment = await _paymentService.checkPaymentStatus(event.paymentId);
|
||||
|
||||
if (payment.isSuccessful) {
|
||||
// Récupérer la cotisation mise à jour
|
||||
final cotisation = await _cotisationRepository.getCotisationById(payment.cotisationId);
|
||||
|
||||
emit(PaymentSuccess(
|
||||
cotisationId: payment.cotisationId,
|
||||
payment: payment,
|
||||
updatedCotisation: cotisation,
|
||||
));
|
||||
|
||||
// Envoyer notification de succès
|
||||
await _notificationService.showPaymentConfirmation(cotisation, payment.montant);
|
||||
|
||||
} else if (payment.isFailed) {
|
||||
emit(PaymentFailure(
|
||||
cotisationId: payment.cotisationId,
|
||||
paymentId: payment.id,
|
||||
errorMessage: payment.messageErreur ?? 'Paiement échoué',
|
||||
));
|
||||
|
||||
// Envoyer notification d'échec
|
||||
final cotisation = await _cotisationRepository.getCotisationById(payment.cotisationId);
|
||||
await _notificationService.showPaymentFailure(cotisation, payment.messageErreur ?? 'Erreur inconnue');
|
||||
}
|
||||
} catch (e) {
|
||||
emit(CotisationsError('Erreur lors de la vérification du paiement: ${e.toString()}'));
|
||||
}
|
||||
}
|
||||
|
||||
/// Handler pour annuler un paiement
|
||||
Future<void> _onCancelPayment(
|
||||
CancelPayment event,
|
||||
Emitter<CotisationsState> emit,
|
||||
) async {
|
||||
try {
|
||||
final cancelled = await _paymentService.cancelPayment(event.paymentId);
|
||||
|
||||
if (cancelled) {
|
||||
emit(PaymentCancelled(
|
||||
cotisationId: event.cotisationId,
|
||||
paymentId: event.paymentId,
|
||||
));
|
||||
} else {
|
||||
emit(const CotisationsError('Impossible d\'annuler le paiement'));
|
||||
}
|
||||
} catch (e) {
|
||||
emit(CotisationsError('Erreur lors de l\'annulation du paiement: ${e.toString()}'));
|
||||
}
|
||||
}
|
||||
|
||||
/// Handler pour programmer les notifications
|
||||
Future<void> _onScheduleNotifications(
|
||||
ScheduleNotifications event,
|
||||
Emitter<CotisationsState> emit,
|
||||
) async {
|
||||
try {
|
||||
await _notificationService.scheduleAllCotisationsNotifications(event.cotisations);
|
||||
|
||||
emit(NotificationsScheduled(
|
||||
notificationsCount: event.cotisations.length * 2,
|
||||
cotisationIds: event.cotisations.map((c) => c.id).toList(),
|
||||
));
|
||||
} catch (e) {
|
||||
emit(CotisationsError('Erreur lors de la programmation des notifications: ${e.toString()}'));
|
||||
}
|
||||
}
|
||||
|
||||
/// Handler pour synchroniser avec le serveur
|
||||
Future<void> _onSyncWithServer(
|
||||
SyncWithServer event,
|
||||
Emitter<CotisationsState> emit,
|
||||
) async {
|
||||
try {
|
||||
emit(const SyncInProgress('Synchronisation en cours...'));
|
||||
|
||||
// Recharger les données
|
||||
final cotisations = await _cotisationRepository.getCotisations();
|
||||
|
||||
emit(SyncCompleted(
|
||||
itemsSynced: cotisations.length,
|
||||
syncTime: DateTime.now(),
|
||||
));
|
||||
|
||||
// Émettre l'état chargé avec les nouvelles données
|
||||
emit(CotisationsLoaded(
|
||||
cotisations: cotisations,
|
||||
filteredCotisations: cotisations,
|
||||
));
|
||||
|
||||
} catch (e) {
|
||||
emit(CotisationsError('Erreur lors de la synchronisation: ${e.toString()}'));
|
||||
}
|
||||
}
|
||||
|
||||
/// Handler pour appliquer des filtres avancés
|
||||
Future<void> _onApplyAdvancedFilters(
|
||||
ApplyAdvancedFilters event,
|
||||
Emitter<CotisationsState> emit,
|
||||
) async {
|
||||
try {
|
||||
emit(const CotisationsLoading());
|
||||
|
||||
final cotisations = await _cotisationRepository.rechercherCotisations(
|
||||
membreId: event.filters['membreId'],
|
||||
statut: event.filters['statut'],
|
||||
typeCotisation: event.filters['typeCotisation'],
|
||||
annee: event.filters['annee'],
|
||||
mois: event.filters['mois'],
|
||||
);
|
||||
|
||||
emit(CotisationsSearchResults(
|
||||
cotisations: cotisations,
|
||||
searchCriteria: event.filters,
|
||||
));
|
||||
|
||||
} catch (e) {
|
||||
emit(CotisationsError('Erreur lors de l\'application des filtres: ${e.toString()}'));
|
||||
}
|
||||
}
|
||||
|
||||
/// Handler pour exporter les cotisations
|
||||
Future<void> _onExportCotisations(
|
||||
ExportCotisations event,
|
||||
Emitter<CotisationsState> emit,
|
||||
) async {
|
||||
try {
|
||||
final cotisations = event.cotisations ?? [];
|
||||
|
||||
emit(ExportInProgress(
|
||||
format: event.format,
|
||||
totalItems: cotisations.length,
|
||||
));
|
||||
|
||||
// TODO: Implémenter l'export réel selon le format
|
||||
await Future.delayed(const Duration(seconds: 2)); // Simulation
|
||||
|
||||
emit(ExportCompleted(
|
||||
format: event.format,
|
||||
filePath: '/storage/emulated/0/Download/cotisations.${event.format}',
|
||||
itemsExported: cotisations.length,
|
||||
));
|
||||
|
||||
} catch (e) {
|
||||
emit(CotisationsError('Erreur lors de l\'export: ${e.toString()}'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -204,3 +204,97 @@ class SortCotisations extends CotisationsEvent {
|
||||
@override
|
||||
List<Object?> get props => [sortBy, ascending];
|
||||
}
|
||||
|
||||
/// Événement pour initier un paiement
|
||||
class InitiatePayment extends CotisationsEvent {
|
||||
final String cotisationId;
|
||||
final double montant;
|
||||
final String methodePaiement;
|
||||
final String numeroTelephone;
|
||||
final String? nomPayeur;
|
||||
final String? emailPayeur;
|
||||
|
||||
const InitiatePayment({
|
||||
required this.cotisationId,
|
||||
required this.montant,
|
||||
required this.methodePaiement,
|
||||
required this.numeroTelephone,
|
||||
this.nomPayeur,
|
||||
this.emailPayeur,
|
||||
});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [
|
||||
cotisationId,
|
||||
montant,
|
||||
methodePaiement,
|
||||
numeroTelephone,
|
||||
nomPayeur,
|
||||
emailPayeur,
|
||||
];
|
||||
}
|
||||
|
||||
/// Événement pour vérifier le statut d'un paiement
|
||||
class CheckPaymentStatus extends CotisationsEvent {
|
||||
final String paymentId;
|
||||
|
||||
const CheckPaymentStatus(this.paymentId);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [paymentId];
|
||||
}
|
||||
|
||||
/// Événement pour annuler un paiement
|
||||
class CancelPayment extends CotisationsEvent {
|
||||
final String paymentId;
|
||||
final String cotisationId;
|
||||
|
||||
const CancelPayment({
|
||||
required this.paymentId,
|
||||
required this.cotisationId,
|
||||
});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [paymentId, cotisationId];
|
||||
}
|
||||
|
||||
/// Événement pour programmer des notifications
|
||||
class ScheduleNotifications extends CotisationsEvent {
|
||||
final List<CotisationModel> cotisations;
|
||||
|
||||
const ScheduleNotifications(this.cotisations);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [cotisations];
|
||||
}
|
||||
|
||||
/// Événement pour synchroniser avec le serveur
|
||||
class SyncWithServer extends CotisationsEvent {
|
||||
final bool forceSync;
|
||||
|
||||
const SyncWithServer({this.forceSync = false});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [forceSync];
|
||||
}
|
||||
|
||||
/// Événement pour appliquer des filtres avancés
|
||||
class ApplyAdvancedFilters extends CotisationsEvent {
|
||||
final Map<String, dynamic> filters;
|
||||
|
||||
const ApplyAdvancedFilters(this.filters);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [filters];
|
||||
}
|
||||
|
||||
/// Événement pour exporter des données
|
||||
class ExportCotisations extends CotisationsEvent {
|
||||
final String format; // 'pdf', 'excel', 'csv'
|
||||
final List<CotisationModel>? cotisations;
|
||||
|
||||
const ExportCotisations(this.format, {this.cotisations});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [format, cotisations];
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import '../../../../core/models/cotisation_model.dart';
|
||||
import '../../../../core/models/payment_model.dart';
|
||||
|
||||
/// États du BLoC des cotisations
|
||||
abstract class CotisationsState extends Equatable {
|
||||
@@ -245,3 +246,137 @@ class CotisationsSearchResults extends CotisationsState {
|
||||
@override
|
||||
List<Object?> get props => [cotisations, searchCriteria, hasReachedMax, currentPage];
|
||||
}
|
||||
|
||||
/// État pour un paiement en cours
|
||||
class PaymentInProgress extends CotisationsState {
|
||||
final String cotisationId;
|
||||
final String paymentId;
|
||||
final String methodePaiement;
|
||||
final double montant;
|
||||
|
||||
const PaymentInProgress({
|
||||
required this.cotisationId,
|
||||
required this.paymentId,
|
||||
required this.methodePaiement,
|
||||
required this.montant,
|
||||
});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [cotisationId, paymentId, methodePaiement, montant];
|
||||
}
|
||||
|
||||
/// État pour un paiement réussi
|
||||
class PaymentSuccess extends CotisationsState {
|
||||
final String cotisationId;
|
||||
final PaymentModel payment;
|
||||
final CotisationModel updatedCotisation;
|
||||
|
||||
const PaymentSuccess({
|
||||
required this.cotisationId,
|
||||
required this.payment,
|
||||
required this.updatedCotisation,
|
||||
});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [cotisationId, payment, updatedCotisation];
|
||||
}
|
||||
|
||||
/// État pour un paiement échoué
|
||||
class PaymentFailure extends CotisationsState {
|
||||
final String cotisationId;
|
||||
final String paymentId;
|
||||
final String errorMessage;
|
||||
final String? errorCode;
|
||||
|
||||
const PaymentFailure({
|
||||
required this.cotisationId,
|
||||
required this.paymentId,
|
||||
required this.errorMessage,
|
||||
this.errorCode,
|
||||
});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [cotisationId, paymentId, errorMessage, errorCode];
|
||||
}
|
||||
|
||||
/// État pour un paiement annulé
|
||||
class PaymentCancelled extends CotisationsState {
|
||||
final String cotisationId;
|
||||
final String paymentId;
|
||||
|
||||
const PaymentCancelled({
|
||||
required this.cotisationId,
|
||||
required this.paymentId,
|
||||
});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [cotisationId, paymentId];
|
||||
}
|
||||
|
||||
/// État pour la synchronisation en cours
|
||||
class SyncInProgress extends CotisationsState {
|
||||
final String message;
|
||||
|
||||
const SyncInProgress(this.message);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [message];
|
||||
}
|
||||
|
||||
/// État pour la synchronisation terminée
|
||||
class SyncCompleted extends CotisationsState {
|
||||
final int itemsSynced;
|
||||
final DateTime syncTime;
|
||||
|
||||
const SyncCompleted({
|
||||
required this.itemsSynced,
|
||||
required this.syncTime,
|
||||
});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [itemsSynced, syncTime];
|
||||
}
|
||||
|
||||
/// État pour l'export en cours
|
||||
class ExportInProgress extends CotisationsState {
|
||||
final String format;
|
||||
final int totalItems;
|
||||
|
||||
const ExportInProgress({
|
||||
required this.format,
|
||||
required this.totalItems,
|
||||
});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [format, totalItems];
|
||||
}
|
||||
|
||||
/// État pour l'export terminé
|
||||
class ExportCompleted extends CotisationsState {
|
||||
final String format;
|
||||
final String filePath;
|
||||
final int itemsExported;
|
||||
|
||||
const ExportCompleted({
|
||||
required this.format,
|
||||
required this.filePath,
|
||||
required this.itemsExported,
|
||||
});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [format, filePath, itemsExported];
|
||||
}
|
||||
|
||||
/// État pour les notifications programmées
|
||||
class NotificationsScheduled extends CotisationsState {
|
||||
final int notificationsCount;
|
||||
final List<String> cotisationIds;
|
||||
|
||||
const NotificationsScheduled({
|
||||
required this.notificationsCount,
|
||||
required this.cotisationIds,
|
||||
});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [notificationsCount, cotisationIds];
|
||||
}
|
||||
|
||||
@@ -0,0 +1,708 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import '../../../../core/di/injection.dart';
|
||||
import '../../../../core/models/cotisation_model.dart';
|
||||
import '../../../../core/models/payment_model.dart';
|
||||
import '../../../../shared/theme/app_theme.dart';
|
||||
import '../../../../shared/widgets/buttons/buttons.dart';
|
||||
import '../../../../shared/widgets/buttons/primary_button.dart';
|
||||
import '../bloc/cotisations_bloc.dart';
|
||||
import '../bloc/cotisations_event.dart';
|
||||
import '../bloc/cotisations_state.dart';
|
||||
import '../widgets/payment_method_selector.dart';
|
||||
import '../widgets/payment_form_widget.dart';
|
||||
import '../widgets/cotisation_timeline_widget.dart';
|
||||
|
||||
/// Page de détail d'une cotisation
|
||||
class CotisationDetailPage extends StatefulWidget {
|
||||
final CotisationModel cotisation;
|
||||
|
||||
const CotisationDetailPage({
|
||||
super.key,
|
||||
required this.cotisation,
|
||||
});
|
||||
|
||||
@override
|
||||
State<CotisationDetailPage> createState() => _CotisationDetailPageState();
|
||||
}
|
||||
|
||||
class _CotisationDetailPageState extends State<CotisationDetailPage>
|
||||
with TickerProviderStateMixin {
|
||||
late final CotisationsBloc _cotisationsBloc;
|
||||
late final TabController _tabController;
|
||||
late final AnimationController _animationController;
|
||||
late final Animation<double> _fadeAnimation;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_cotisationsBloc = getIt<CotisationsBloc>();
|
||||
_tabController = TabController(length: 3, vsync: this);
|
||||
_animationController = AnimationController(
|
||||
duration: const Duration(milliseconds: 800),
|
||||
vsync: this,
|
||||
);
|
||||
_fadeAnimation = Tween<double>(begin: 0.0, end: 1.0).animate(
|
||||
CurvedAnimation(parent: _animationController, curve: Curves.easeInOut),
|
||||
);
|
||||
|
||||
_animationController.forward();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_tabController.dispose();
|
||||
_animationController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider.value(
|
||||
value: _cotisationsBloc,
|
||||
child: Scaffold(
|
||||
backgroundColor: AppTheme.backgroundLight,
|
||||
body: BlocListener<CotisationsBloc, CotisationsState>(
|
||||
listener: (context, state) {
|
||||
if (state is PaymentSuccess) {
|
||||
_showPaymentSuccessDialog(state);
|
||||
} else if (state is PaymentFailure) {
|
||||
_showPaymentErrorDialog(state);
|
||||
} else if (state is PaymentInProgress) {
|
||||
_showPaymentProgressDialog(state);
|
||||
}
|
||||
},
|
||||
child: FadeTransition(
|
||||
opacity: _fadeAnimation,
|
||||
child: CustomScrollView(
|
||||
slivers: [
|
||||
_buildAppBar(),
|
||||
SliverToBoxAdapter(
|
||||
child: Column(
|
||||
children: [
|
||||
_buildStatusCard(),
|
||||
const SizedBox(height: 16),
|
||||
_buildTabSection(),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
bottomNavigationBar: _buildBottomActions(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildAppBar() {
|
||||
return SliverAppBar(
|
||||
expandedHeight: 200,
|
||||
pinned: true,
|
||||
backgroundColor: _getStatusColor(),
|
||||
flexibleSpace: FlexibleSpaceBar(
|
||||
title: Text(
|
||||
widget.cotisation.typeCotisation,
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
background: Container(
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
colors: [
|
||||
_getStatusColor(),
|
||||
_getStatusColor().withOpacity(0.8),
|
||||
],
|
||||
),
|
||||
),
|
||||
child: Stack(
|
||||
children: [
|
||||
Positioned(
|
||||
right: -50,
|
||||
top: -50,
|
||||
child: Container(
|
||||
width: 200,
|
||||
height: 200,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: Colors.white.withOpacity(0.1),
|
||||
),
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
right: 20,
|
||||
bottom: 20,
|
||||
child: Icon(
|
||||
_getStatusIcon(),
|
||||
size: 80,
|
||||
color: Colors.white.withOpacity(0.3),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.share, color: Colors.white),
|
||||
onPressed: _shareReceipt,
|
||||
),
|
||||
PopupMenuButton<String>(
|
||||
icon: const Icon(Icons.more_vert, color: Colors.white),
|
||||
onSelected: _handleMenuAction,
|
||||
itemBuilder: (context) => [
|
||||
const PopupMenuItem(
|
||||
value: 'export',
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(Icons.download),
|
||||
SizedBox(width: 8),
|
||||
Text('Exporter'),
|
||||
],
|
||||
),
|
||||
),
|
||||
const PopupMenuItem(
|
||||
value: 'print',
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(Icons.print),
|
||||
SizedBox(width: 8),
|
||||
Text('Imprimer'),
|
||||
],
|
||||
),
|
||||
),
|
||||
const PopupMenuItem(
|
||||
value: 'history',
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(Icons.history),
|
||||
SizedBox(width: 8),
|
||||
Text('Historique'),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildStatusCard() {
|
||||
return Container(
|
||||
margin: const EdgeInsets.all(16),
|
||||
padding: const EdgeInsets.all(20),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.08),
|
||||
blurRadius: 20,
|
||||
offset: const Offset(0, 4),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'Montant à payer',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: AppTheme.textSecondary,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'${widget.cotisation.montantDu.toStringAsFixed(0)} XOF',
|
||||
style: const TextStyle(
|
||||
fontSize: 28,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppTheme.textPrimary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
|
||||
decoration: BoxDecoration(
|
||||
color: _getStatusColor().withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(
|
||||
_getStatusIcon(),
|
||||
size: 16,
|
||||
color: _getStatusColor(),
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
widget.cotisation.statut,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: _getStatusColor(),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
_buildInfoRow('Membre', widget.cotisation.nomMembre ?? 'N/A'),
|
||||
_buildInfoRow('Période', _formatPeriode()),
|
||||
_buildInfoRow('Échéance', _formatDate(widget.cotisation.dateEcheance)),
|
||||
if (widget.cotisation.montantPaye > 0)
|
||||
_buildInfoRow('Montant payé', '${widget.cotisation.montantPaye.toStringAsFixed(0)} XOF'),
|
||||
if (widget.cotisation.isEnRetard)
|
||||
_buildInfoRow('Retard', '${widget.cotisation.joursRetard} jours', isWarning: true),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildInfoRow(String label, String value, {bool isWarning = false}) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 4),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
label,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: AppTheme.textSecondary,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
value,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: isWarning ? AppTheme.warningColor : AppTheme.textPrimary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTabSection() {
|
||||
return Container(
|
||||
margin: const EdgeInsets.symmetric(horizontal: 16),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.08),
|
||||
blurRadius: 20,
|
||||
offset: const Offset(0, 4),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
TabBar(
|
||||
controller: _tabController,
|
||||
labelColor: AppTheme.primaryColor,
|
||||
unselectedLabelColor: AppTheme.textSecondary,
|
||||
indicatorColor: AppTheme.primaryColor,
|
||||
tabs: const [
|
||||
Tab(text: 'Détails', icon: Icon(Icons.info_outline)),
|
||||
Tab(text: 'Paiement', icon: Icon(Icons.payment)),
|
||||
Tab(text: 'Historique', icon: Icon(Icons.history)),
|
||||
],
|
||||
),
|
||||
SizedBox(
|
||||
height: 400,
|
||||
child: TabBarView(
|
||||
controller: _tabController,
|
||||
children: [
|
||||
_buildDetailsTab(),
|
||||
_buildPaymentTab(),
|
||||
_buildHistoryTab(),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDetailsTab() {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_buildDetailSection('Informations générales', [
|
||||
_buildDetailItem('Type', widget.cotisation.typeCotisation),
|
||||
_buildDetailItem('Référence', widget.cotisation.numeroReference),
|
||||
_buildDetailItem('Date création', _formatDate(widget.cotisation.dateCreation)),
|
||||
_buildDetailItem('Statut', widget.cotisation.statut),
|
||||
]),
|
||||
const SizedBox(height: 20),
|
||||
_buildDetailSection('Montants', [
|
||||
_buildDetailItem('Montant dû', '${widget.cotisation.montantDu.toStringAsFixed(0)} XOF'),
|
||||
_buildDetailItem('Montant payé', '${widget.cotisation.montantPaye.toStringAsFixed(0)} XOF'),
|
||||
_buildDetailItem('Reste à payer', '${(widget.cotisation.montantDu - widget.cotisation.montantPaye).toStringAsFixed(0)} XOF'),
|
||||
]),
|
||||
if (widget.cotisation.description?.isNotEmpty == true) ...[
|
||||
const SizedBox(height: 20),
|
||||
_buildDetailSection('Description', [
|
||||
Text(
|
||||
widget.cotisation.description!,
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
color: AppTheme.textSecondary,
|
||||
),
|
||||
),
|
||||
]),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPaymentTab() {
|
||||
if (widget.cotisation.isEntierementPayee) {
|
||||
return const Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.check_circle,
|
||||
size: 64,
|
||||
color: AppTheme.successColor,
|
||||
),
|
||||
SizedBox(height: 16),
|
||||
Text(
|
||||
'Cotisation entièrement payée',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppTheme.successColor,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return BlocBuilder<CotisationsBloc, CotisationsState>(
|
||||
builder: (context, state) {
|
||||
if (state is PaymentInProgress) {
|
||||
return const Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
CircularProgressIndicator(),
|
||||
SizedBox(height: 16),
|
||||
Text('Traitement du paiement en cours...'),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return PaymentFormWidget(
|
||||
cotisation: widget.cotisation,
|
||||
onPaymentInitiated: (paymentData) {
|
||||
_cotisationsBloc.add(InitiatePayment(
|
||||
cotisationId: widget.cotisation.id,
|
||||
montant: paymentData['montant'],
|
||||
methodePaiement: paymentData['methodePaiement'],
|
||||
numeroTelephone: paymentData['numeroTelephone'],
|
||||
nomPayeur: paymentData['nomPayeur'],
|
||||
emailPayeur: paymentData['emailPayeur'],
|
||||
));
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildHistoryTab() {
|
||||
return CotisationTimelineWidget(cotisation: widget.cotisation);
|
||||
}
|
||||
|
||||
Widget _buildDetailSection(String title, List<Widget> children) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
title,
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppTheme.textPrimary,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
...children,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDetailItem(String label, String value) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 4),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
label,
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
color: AppTheme.textSecondary,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
value,
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: AppTheme.textPrimary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildBottomActions() {
|
||||
if (widget.cotisation.isEntierementPayee) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: const BoxDecoration(
|
||||
color: Colors.white,
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black12,
|
||||
blurRadius: 10,
|
||||
offset: Offset(0, -2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: PrimaryButton(
|
||||
text: 'Télécharger le reçu',
|
||||
icon: Icons.download,
|
||||
onPressed: _downloadReceipt,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: const BoxDecoration(
|
||||
color: Colors.white,
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black12,
|
||||
blurRadius: 10,
|
||||
offset: Offset(0, -2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: OutlinedButton.icon(
|
||||
onPressed: _scheduleReminder,
|
||||
icon: const Icon(Icons.notifications),
|
||||
label: const Text('Rappel'),
|
||||
style: OutlinedButton.styleFrom(
|
||||
padding: const EdgeInsets.symmetric(vertical: 12),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: PrimaryButton(
|
||||
text: 'Payer maintenant',
|
||||
icon: Icons.payment,
|
||||
onPressed: () {
|
||||
_tabController.animateTo(1); // Aller à l'onglet paiement
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Méthodes utilitaires
|
||||
Color _getStatusColor() {
|
||||
switch (widget.cotisation.statut.toLowerCase()) {
|
||||
case 'payee':
|
||||
return AppTheme.successColor;
|
||||
case 'en_retard':
|
||||
return AppTheme.errorColor;
|
||||
case 'en_attente':
|
||||
return AppTheme.warningColor;
|
||||
default:
|
||||
return AppTheme.primaryColor;
|
||||
}
|
||||
}
|
||||
|
||||
IconData _getStatusIcon() {
|
||||
switch (widget.cotisation.statut.toLowerCase()) {
|
||||
case 'payee':
|
||||
return Icons.check_circle;
|
||||
case 'en_retard':
|
||||
return Icons.warning;
|
||||
case 'en_attente':
|
||||
return Icons.schedule;
|
||||
default:
|
||||
return Icons.payment;
|
||||
}
|
||||
}
|
||||
|
||||
String _formatDate(DateTime date) {
|
||||
return '${date.day.toString().padLeft(2, '0')}/${date.month.toString().padLeft(2, '0')}/${date.year}';
|
||||
}
|
||||
|
||||
String _formatPeriode() {
|
||||
return '${widget.cotisation.mois}/${widget.cotisation.annee}';
|
||||
}
|
||||
|
||||
// Actions
|
||||
void _shareReceipt() {
|
||||
// TODO: Implémenter le partage
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Partage - En cours de développement')),
|
||||
);
|
||||
}
|
||||
|
||||
void _handleMenuAction(String action) {
|
||||
switch (action) {
|
||||
case 'export':
|
||||
_exportReceipt();
|
||||
break;
|
||||
case 'print':
|
||||
_printReceipt();
|
||||
break;
|
||||
case 'history':
|
||||
_showFullHistory();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void _exportReceipt() {
|
||||
_cotisationsBloc.add(ExportCotisations('pdf', cotisations: [widget.cotisation]));
|
||||
}
|
||||
|
||||
void _printReceipt() {
|
||||
// TODO: Implémenter l'impression
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Impression - En cours de développement')),
|
||||
);
|
||||
}
|
||||
|
||||
void _showFullHistory() {
|
||||
// TODO: Naviguer vers l'historique complet
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Historique complet - En cours de développement')),
|
||||
);
|
||||
}
|
||||
|
||||
void _downloadReceipt() {
|
||||
_exportReceipt();
|
||||
}
|
||||
|
||||
void _scheduleReminder() {
|
||||
_cotisationsBloc.add(ScheduleNotifications([widget.cotisation]));
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('Rappel programmé avec succès'),
|
||||
backgroundColor: AppTheme.successColor,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Dialogs
|
||||
void _showPaymentSuccessDialog(PaymentSuccess state) {
|
||||
showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Row(
|
||||
children: [
|
||||
Icon(Icons.check_circle, color: AppTheme.successColor),
|
||||
SizedBox(width: 8),
|
||||
Text('Paiement réussi'),
|
||||
],
|
||||
),
|
||||
content: Text('Votre paiement de ${state.payment.montant.toStringAsFixed(0)} XOF a été confirmé.'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
Navigator.of(context).pop(); // Retour à la liste
|
||||
},
|
||||
child: const Text('OK'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showPaymentErrorDialog(PaymentFailure state) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Row(
|
||||
children: [
|
||||
Icon(Icons.error, color: AppTheme.errorColor),
|
||||
SizedBox(width: 8),
|
||||
Text('Échec du paiement'),
|
||||
],
|
||||
),
|
||||
content: Text(state.errorMessage),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
child: const Text('OK'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showPaymentProgressDialog(PaymentInProgress state) {
|
||||
showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (context) => AlertDialog(
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const CircularProgressIndicator(),
|
||||
const SizedBox(height: 16),
|
||||
Text('Traitement du paiement de ${state.montant.toStringAsFixed(0)} XOF...'),
|
||||
const SizedBox(height: 8),
|
||||
Text('Méthode: ${state.methodePaiement}'),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,8 @@ import '../bloc/cotisations_event.dart';
|
||||
import '../bloc/cotisations_state.dart';
|
||||
import '../widgets/cotisation_card.dart';
|
||||
import '../widgets/cotisations_stats_card.dart';
|
||||
import 'cotisation_detail_page.dart';
|
||||
import 'cotisations_search_page.dart';
|
||||
|
||||
/// Page principale pour la liste des cotisations
|
||||
class CotisationsListPage extends StatefulWidget {
|
||||
@@ -155,13 +157,23 @@ class _CotisationsListPageState extends State<CotisationsListPage> {
|
||||
IconButton(
|
||||
icon: const Icon(Icons.search, color: Colors.white),
|
||||
onPressed: () {
|
||||
// TODO: Implémenter la recherche
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => const CotisationsSearchPage(),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.filter_list, color: Colors.white),
|
||||
onPressed: () {
|
||||
// TODO: Implémenter les filtres
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => const CotisationsSearchPage(),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
@@ -264,14 +276,22 @@ class _CotisationsListPageState extends State<CotisationsListPage> {
|
||||
child: CotisationCard(
|
||||
cotisation: cotisation,
|
||||
onTap: () {
|
||||
// TODO: Naviguer vers le détail
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => CotisationDetailPage(
|
||||
cotisation: cotisation,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
onPay: () {
|
||||
// TODO: Implémenter le paiement
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('Paiement - En cours de développement'),
|
||||
backgroundColor: AppTheme.successColor,
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => CotisationDetailPage(
|
||||
cotisation: cotisation,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
|
||||
@@ -0,0 +1,498 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import '../../../../core/di/injection.dart';
|
||||
import '../../../../core/models/cotisation_model.dart';
|
||||
import '../../../../shared/theme/app_theme.dart';
|
||||
import '../../../../shared/widgets/buttons/buttons.dart';
|
||||
import '../../../../shared/widgets/buttons/primary_button.dart';
|
||||
import '../bloc/cotisations_bloc.dart';
|
||||
import '../bloc/cotisations_event.dart';
|
||||
import '../bloc/cotisations_state.dart';
|
||||
import '../widgets/cotisation_card.dart';
|
||||
import 'cotisation_detail_page.dart';
|
||||
|
||||
/// Page de recherche et filtrage des cotisations
|
||||
class CotisationsSearchPage extends StatefulWidget {
|
||||
const CotisationsSearchPage({super.key});
|
||||
|
||||
@override
|
||||
State<CotisationsSearchPage> createState() => _CotisationsSearchPageState();
|
||||
}
|
||||
|
||||
class _CotisationsSearchPageState extends State<CotisationsSearchPage>
|
||||
with TickerProviderStateMixin {
|
||||
late final CotisationsBloc _cotisationsBloc;
|
||||
late final TabController _tabController;
|
||||
late final AnimationController _animationController;
|
||||
|
||||
final _searchController = TextEditingController();
|
||||
final _scrollController = ScrollController();
|
||||
|
||||
String? _selectedStatut;
|
||||
String? _selectedType;
|
||||
int? _selectedAnnee;
|
||||
int? _selectedMois;
|
||||
bool _showAdvancedFilters = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_cotisationsBloc = getIt<CotisationsBloc>();
|
||||
_tabController = TabController(length: 4, vsync: this);
|
||||
_animationController = AnimationController(
|
||||
duration: const Duration(milliseconds: 300),
|
||||
vsync: this,
|
||||
);
|
||||
|
||||
_scrollController.addListener(_onScroll);
|
||||
_animationController.forward();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_searchController.dispose();
|
||||
_scrollController.dispose();
|
||||
_tabController.dispose();
|
||||
_animationController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _onScroll() {
|
||||
if (_isBottom) {
|
||||
final currentState = _cotisationsBloc.state;
|
||||
if (currentState is CotisationsSearchResults && !currentState.hasReachedMax) {
|
||||
_performSearch(page: currentState.currentPage + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool get _isBottom {
|
||||
if (!_scrollController.hasClients) return false;
|
||||
final maxScroll = _scrollController.position.maxScrollExtent;
|
||||
final currentScroll = _scrollController.offset;
|
||||
return currentScroll >= (maxScroll * 0.9);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider.value(
|
||||
value: _cotisationsBloc,
|
||||
child: Scaffold(
|
||||
backgroundColor: AppTheme.backgroundLight,
|
||||
appBar: AppBar(
|
||||
title: const Text('Recherche'),
|
||||
backgroundColor: AppTheme.primaryColor,
|
||||
foregroundColor: Colors.white,
|
||||
bottom: TabBar(
|
||||
controller: _tabController,
|
||||
labelColor: Colors.white,
|
||||
unselectedLabelColor: Colors.white70,
|
||||
indicatorColor: Colors.white,
|
||||
tabs: const [
|
||||
Tab(text: 'Toutes', icon: Icon(Icons.list)),
|
||||
Tab(text: 'En attente', icon: Icon(Icons.schedule)),
|
||||
Tab(text: 'En retard', icon: Icon(Icons.warning)),
|
||||
Tab(text: 'Payées', icon: Icon(Icons.check_circle)),
|
||||
],
|
||||
onTap: (index) => _onTabChanged(index),
|
||||
),
|
||||
),
|
||||
body: Column(
|
||||
children: [
|
||||
_buildSearchHeader(),
|
||||
if (_showAdvancedFilters) _buildAdvancedFilters(),
|
||||
Expanded(
|
||||
child: TabBarView(
|
||||
controller: _tabController,
|
||||
children: [
|
||||
_buildSearchResults(),
|
||||
_buildSearchResults(statut: 'EN_ATTENTE'),
|
||||
_buildSearchResults(statut: 'EN_RETARD'),
|
||||
_buildSearchResults(statut: 'PAYEE'),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSearchHeader() {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: const BoxDecoration(
|
||||
color: Colors.white,
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black12,
|
||||
blurRadius: 4,
|
||||
offset: Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
// Barre de recherche
|
||||
TextField(
|
||||
controller: _searchController,
|
||||
decoration: InputDecoration(
|
||||
hintText: 'Rechercher par nom, référence...',
|
||||
prefixIcon: const Icon(Icons.search),
|
||||
suffixIcon: _searchController.text.isNotEmpty
|
||||
? IconButton(
|
||||
icon: const Icon(Icons.clear),
|
||||
onPressed: () {
|
||||
_searchController.clear();
|
||||
_performSearch();
|
||||
},
|
||||
)
|
||||
: null,
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: BorderSide.none,
|
||||
),
|
||||
filled: true,
|
||||
fillColor: AppTheme.backgroundLight,
|
||||
),
|
||||
onChanged: (value) {
|
||||
setState(() {});
|
||||
_performSearch();
|
||||
},
|
||||
),
|
||||
|
||||
const SizedBox(height: 12),
|
||||
|
||||
// Boutons d'action
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: OutlinedButton.icon(
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
_showAdvancedFilters = !_showAdvancedFilters;
|
||||
});
|
||||
if (_showAdvancedFilters) {
|
||||
_animationController.forward();
|
||||
} else {
|
||||
_animationController.reverse();
|
||||
}
|
||||
},
|
||||
icon: Icon(_showAdvancedFilters ? Icons.expand_less : Icons.tune),
|
||||
label: Text(_showAdvancedFilters ? 'Masquer filtres' : 'Filtres avancés'),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
OutlinedButton.icon(
|
||||
onPressed: _clearAllFilters,
|
||||
icon: const Icon(Icons.clear_all),
|
||||
label: const Text('Effacer'),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildAdvancedFilters() {
|
||||
return AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 300),
|
||||
height: _showAdvancedFilters ? null : 0,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: const BoxDecoration(
|
||||
color: Colors.white,
|
||||
border: Border(
|
||||
bottom: BorderSide(color: AppTheme.borderLight),
|
||||
),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'Filtres avancés',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppTheme.textPrimary,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// Grille de filtres
|
||||
GridView.count(
|
||||
shrinkWrap: true,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
crossAxisCount: 2,
|
||||
crossAxisSpacing: 12,
|
||||
mainAxisSpacing: 12,
|
||||
childAspectRatio: 3,
|
||||
children: [
|
||||
_buildFilterDropdown(
|
||||
'Type',
|
||||
_selectedType,
|
||||
['Mensuelle', 'Annuelle', 'Exceptionnelle', 'Adhésion'],
|
||||
(value) => setState(() => _selectedType = value),
|
||||
),
|
||||
_buildFilterDropdown(
|
||||
'Année',
|
||||
_selectedAnnee?.toString(),
|
||||
List.generate(5, (i) => (DateTime.now().year - i).toString()),
|
||||
(value) => setState(() => _selectedAnnee = int.tryParse(value ?? '')),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// Bouton d'application des filtres
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
child: PrimaryButton(
|
||||
text: 'Appliquer les filtres',
|
||||
onPressed: _applyAdvancedFilters,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildFilterDropdown(
|
||||
String label,
|
||||
String? value,
|
||||
List<String> items,
|
||||
Function(String?) onChanged,
|
||||
) {
|
||||
return DropdownButtonFormField<String>(
|
||||
value: value,
|
||||
decoration: InputDecoration(
|
||||
labelText: label,
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||
),
|
||||
items: [
|
||||
DropdownMenuItem<String>(
|
||||
value: null,
|
||||
child: Text('Tous les ${label.toLowerCase()}s'),
|
||||
),
|
||||
...items.map((item) => DropdownMenuItem<String>(
|
||||
value: item,
|
||||
child: Text(item),
|
||||
)),
|
||||
],
|
||||
onChanged: onChanged,
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSearchResults({String? statut}) {
|
||||
return BlocBuilder<CotisationsBloc, CotisationsState>(
|
||||
builder: (context, state) {
|
||||
if (state is CotisationsLoading) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
|
||||
if (state is CotisationsError) {
|
||||
return _buildErrorState(state);
|
||||
}
|
||||
|
||||
if (state is CotisationsSearchResults) {
|
||||
final filteredResults = statut != null
|
||||
? state.cotisations.where((c) => c.statut == statut).toList()
|
||||
: state.cotisations;
|
||||
|
||||
if (filteredResults.isEmpty) {
|
||||
return _buildEmptyState();
|
||||
}
|
||||
|
||||
return RefreshIndicator(
|
||||
onRefresh: () async => _performSearch(refresh: true),
|
||||
child: ListView.builder(
|
||||
controller: _scrollController,
|
||||
padding: const EdgeInsets.all(16),
|
||||
itemCount: filteredResults.length + (state.hasReachedMax ? 0 : 1),
|
||||
itemBuilder: (context, index) {
|
||||
if (index >= filteredResults.length) {
|
||||
return const Padding(
|
||||
padding: EdgeInsets.all(16),
|
||||
child: Center(child: CircularProgressIndicator()),
|
||||
);
|
||||
}
|
||||
|
||||
final cotisation = filteredResults[index];
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 12),
|
||||
child: CotisationCard(
|
||||
cotisation: cotisation,
|
||||
onTap: () => _navigateToDetail(cotisation),
|
||||
onPay: () => _navigateToDetail(cotisation),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return _buildInitialState();
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildInitialState() {
|
||||
return const Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.search,
|
||||
size: 64,
|
||||
color: AppTheme.textHint,
|
||||
),
|
||||
SizedBox(height: 16),
|
||||
Text(
|
||||
'Recherchez des cotisations',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
color: AppTheme.textSecondary,
|
||||
),
|
||||
),
|
||||
SizedBox(height: 8),
|
||||
Text(
|
||||
'Utilisez la barre de recherche ou les filtres',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: AppTheme.textHint,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildEmptyState() {
|
||||
return const Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.search_off,
|
||||
size: 64,
|
||||
color: AppTheme.textHint,
|
||||
),
|
||||
SizedBox(height: 16),
|
||||
Text(
|
||||
'Aucun résultat trouvé',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
color: AppTheme.textSecondary,
|
||||
),
|
||||
),
|
||||
SizedBox(height: 8),
|
||||
Text(
|
||||
'Essayez de modifier vos critères de recherche',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: AppTheme.textHint,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildErrorState(CotisationsError state) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Icon(
|
||||
Icons.error_outline,
|
||||
size: 64,
|
||||
color: AppTheme.errorColor,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'Erreur de recherche',
|
||||
style: const TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppTheme.textPrimary,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
state.message,
|
||||
textAlign: TextAlign.center,
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
color: AppTheme.textSecondary,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
PrimaryButton(
|
||||
text: 'Réessayer',
|
||||
onPressed: () => _performSearch(refresh: true),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Actions
|
||||
void _onTabChanged(int index) {
|
||||
_performSearch(refresh: true);
|
||||
}
|
||||
|
||||
void _performSearch({int page = 0, bool refresh = false}) {
|
||||
final query = _searchController.text.trim();
|
||||
|
||||
if (query.isEmpty && !_hasActiveFilters()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final filters = <String, dynamic>{
|
||||
if (query.isNotEmpty) 'query': query,
|
||||
if (_selectedStatut != null) 'statut': _selectedStatut,
|
||||
if (_selectedType != null) 'typeCotisation': _selectedType,
|
||||
if (_selectedAnnee != null) 'annee': _selectedAnnee,
|
||||
if (_selectedMois != null) 'mois': _selectedMois,
|
||||
};
|
||||
|
||||
_cotisationsBloc.add(ApplyAdvancedFilters(filters));
|
||||
}
|
||||
|
||||
void _applyAdvancedFilters() {
|
||||
_performSearch(refresh: true);
|
||||
}
|
||||
|
||||
void _clearAllFilters() {
|
||||
setState(() {
|
||||
_searchController.clear();
|
||||
_selectedStatut = null;
|
||||
_selectedType = null;
|
||||
_selectedAnnee = null;
|
||||
_selectedMois = null;
|
||||
});
|
||||
_cotisationsBloc.add(const ResetCotisationsState());
|
||||
}
|
||||
|
||||
bool _hasActiveFilters() {
|
||||
return _selectedStatut != null ||
|
||||
_selectedType != null ||
|
||||
_selectedAnnee != null ||
|
||||
_selectedMois != null;
|
||||
}
|
||||
|
||||
void _navigateToDetail(CotisationModel cotisation) {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => CotisationDetailPage(cotisation: cotisation),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,244 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../../../../core/models/cotisation_model.dart';
|
||||
import '../../../../core/animations/loading_animations.dart';
|
||||
import 'cotisation_card.dart';
|
||||
|
||||
/// Widget animé pour afficher une liste de cotisations avec animations d'apparition
|
||||
class AnimatedCotisationList extends StatefulWidget {
|
||||
final List<CotisationModel> cotisations;
|
||||
final Function(CotisationModel)? onCotisationTap;
|
||||
final bool isLoading;
|
||||
final VoidCallback? onRefresh;
|
||||
final ScrollController? scrollController;
|
||||
|
||||
const AnimatedCotisationList({
|
||||
super.key,
|
||||
required this.cotisations,
|
||||
this.onCotisationTap,
|
||||
this.isLoading = false,
|
||||
this.onRefresh,
|
||||
this.scrollController,
|
||||
});
|
||||
|
||||
@override
|
||||
State<AnimatedCotisationList> createState() => _AnimatedCotisationListState();
|
||||
}
|
||||
|
||||
class _AnimatedCotisationListState extends State<AnimatedCotisationList>
|
||||
with TickerProviderStateMixin {
|
||||
late AnimationController _listController;
|
||||
List<AnimationController> _itemControllers = [];
|
||||
List<Animation<double>> _itemAnimations = [];
|
||||
List<Animation<Offset>> _slideAnimations = [];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_initializeAnimations();
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(AnimatedCotisationList oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (widget.cotisations.length != oldWidget.cotisations.length) {
|
||||
_updateAnimations();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_listController.dispose();
|
||||
for (final controller in _itemControllers) {
|
||||
controller.dispose();
|
||||
}
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _initializeAnimations() {
|
||||
_listController = AnimationController(
|
||||
duration: const Duration(milliseconds: 600),
|
||||
vsync: this,
|
||||
);
|
||||
|
||||
_updateAnimations();
|
||||
_listController.forward();
|
||||
}
|
||||
|
||||
void _updateAnimations() {
|
||||
// Dispose des anciens controllers s'ils existent
|
||||
if (_itemControllers.isNotEmpty) {
|
||||
for (final controller in _itemControllers) {
|
||||
controller.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
// Créer de nouveaux controllers pour chaque élément
|
||||
_itemControllers = List.generate(
|
||||
widget.cotisations.length,
|
||||
(index) => AnimationController(
|
||||
duration: Duration(milliseconds: 400 + (index * 80)),
|
||||
vsync: this,
|
||||
),
|
||||
);
|
||||
|
||||
// Animations de fade et scale
|
||||
_itemAnimations = _itemControllers.map((controller) {
|
||||
return Tween<double>(begin: 0.0, end: 1.0).animate(
|
||||
CurvedAnimation(
|
||||
parent: controller,
|
||||
curve: Curves.easeOutCubic,
|
||||
),
|
||||
);
|
||||
}).toList();
|
||||
|
||||
// Animations de slide depuis la gauche
|
||||
_slideAnimations = _itemControllers.map((controller) {
|
||||
return Tween<Offset>(
|
||||
begin: const Offset(-0.3, 0),
|
||||
end: Offset.zero,
|
||||
).animate(
|
||||
CurvedAnimation(
|
||||
parent: controller,
|
||||
curve: Curves.easeOutCubic,
|
||||
),
|
||||
);
|
||||
}).toList();
|
||||
|
||||
// Démarrer les animations avec un délai progressif
|
||||
for (int i = 0; i < _itemControllers.length; i++) {
|
||||
Future.delayed(Duration(milliseconds: i * 120), () {
|
||||
if (mounted) {
|
||||
_itemControllers[i].forward();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (widget.isLoading && widget.cotisations.isEmpty) {
|
||||
return _buildLoadingState();
|
||||
}
|
||||
|
||||
if (widget.cotisations.isEmpty) {
|
||||
return _buildEmptyState();
|
||||
}
|
||||
|
||||
return RefreshIndicator(
|
||||
onRefresh: () async {
|
||||
widget.onRefresh?.call();
|
||||
await Future.delayed(const Duration(milliseconds: 500));
|
||||
},
|
||||
child: ListView.builder(
|
||||
controller: widget.scrollController,
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
padding: const EdgeInsets.all(16),
|
||||
itemCount: widget.cotisations.length + (widget.isLoading ? 1 : 0),
|
||||
itemBuilder: (context, index) {
|
||||
if (index >= widget.cotisations.length) {
|
||||
return _buildLoadingIndicator();
|
||||
}
|
||||
|
||||
return _buildAnimatedItem(index);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildAnimatedItem(int index) {
|
||||
final cotisation = widget.cotisations[index];
|
||||
|
||||
if (index >= _itemAnimations.length) {
|
||||
// Fallback pour les nouveaux éléments
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 16),
|
||||
child: CotisationCard(
|
||||
cotisation: cotisation,
|
||||
onTap: () => widget.onCotisationTap?.call(cotisation),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return AnimatedBuilder(
|
||||
animation: _itemAnimations[index],
|
||||
builder: (context, child) {
|
||||
return SlideTransition(
|
||||
position: _slideAnimations[index],
|
||||
child: FadeTransition(
|
||||
opacity: _itemAnimations[index],
|
||||
child: Transform.scale(
|
||||
scale: 0.9 + (0.1 * _itemAnimations[index].value),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(bottom: 16),
|
||||
child: CotisationCard(
|
||||
cotisation: cotisation,
|
||||
onTap: () => widget.onCotisationTap?.call(cotisation),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildLoadingState() {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
LoadingAnimations.pulse(),
|
||||
const SizedBox(height: 24),
|
||||
const Text(
|
||||
'Chargement des cotisations...',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
color: Colors.grey,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildEmptyState() {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.payment_outlined,
|
||||
size: 80,
|
||||
color: Colors.grey[400],
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
Text(
|
||||
'Aucune cotisation trouvée',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Colors.grey[600],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
'Les cotisations apparaîtront ici',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: Colors.grey[500],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildLoadingIndicator() {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Center(
|
||||
child: LoadingAnimations.spinner(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import '../../../../core/models/cotisation_model.dart';
|
||||
import '../../../../shared/theme/app_theme.dart';
|
||||
@@ -41,7 +42,10 @@ class CotisationCard extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
child: InkWell(
|
||||
onTap: onTap,
|
||||
onTap: () {
|
||||
HapticFeedback.lightImpact();
|
||||
onTap?.call();
|
||||
},
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
@@ -71,7 +75,10 @@ class CotisationCard extends StatelessWidget {
|
||||
// Actions
|
||||
if (cotisation.statut == 'EN_ATTENTE' || cotisation.statut == 'EN_RETARD')
|
||||
IconButton(
|
||||
onPressed: onPay,
|
||||
onPressed: () {
|
||||
HapticFeedback.lightImpact();
|
||||
onPay?.call();
|
||||
},
|
||||
icon: const Icon(Icons.payment, size: 20),
|
||||
color: AppTheme.successColor,
|
||||
tooltip: 'Payer',
|
||||
|
||||
@@ -0,0 +1,417 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../../../../core/models/cotisation_model.dart';
|
||||
import '../../../../shared/theme/app_theme.dart';
|
||||
|
||||
/// Widget d'affichage de la timeline d'une cotisation
|
||||
class CotisationTimelineWidget extends StatefulWidget {
|
||||
final CotisationModel cotisation;
|
||||
|
||||
const CotisationTimelineWidget({
|
||||
super.key,
|
||||
required this.cotisation,
|
||||
});
|
||||
|
||||
@override
|
||||
State<CotisationTimelineWidget> createState() => _CotisationTimelineWidgetState();
|
||||
}
|
||||
|
||||
class _CotisationTimelineWidgetState extends State<CotisationTimelineWidget>
|
||||
with TickerProviderStateMixin {
|
||||
late final AnimationController _animationController;
|
||||
late final List<Animation<double>> _itemAnimations;
|
||||
|
||||
List<TimelineEvent> _timelineEvents = [];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_generateTimelineEvents();
|
||||
|
||||
_animationController = AnimationController(
|
||||
duration: Duration(milliseconds: 300 * _timelineEvents.length),
|
||||
vsync: this,
|
||||
);
|
||||
|
||||
_itemAnimations = List.generate(
|
||||
_timelineEvents.length,
|
||||
(index) => Tween<double>(begin: 0.0, end: 1.0).animate(
|
||||
CurvedAnimation(
|
||||
parent: _animationController,
|
||||
curve: Interval(
|
||||
index / _timelineEvents.length,
|
||||
(index + 1) / _timelineEvents.length,
|
||||
curve: Curves.easeOutCubic,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
_animationController.forward();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_animationController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _generateTimelineEvents() {
|
||||
_timelineEvents = [
|
||||
TimelineEvent(
|
||||
title: 'Cotisation créée',
|
||||
description: 'Cotisation ${widget.cotisation.typeCotisation} créée pour ${widget.cotisation.nomMembre}',
|
||||
date: widget.cotisation.dateCreation,
|
||||
icon: Icons.add_circle,
|
||||
color: AppTheme.primaryColor,
|
||||
isCompleted: true,
|
||||
),
|
||||
];
|
||||
|
||||
// Ajouter l'événement d'échéance
|
||||
final now = DateTime.now();
|
||||
final isOverdue = widget.cotisation.dateEcheance.isBefore(now);
|
||||
|
||||
_timelineEvents.add(
|
||||
TimelineEvent(
|
||||
title: isOverdue ? 'Échéance dépassée' : 'Échéance prévue',
|
||||
description: 'Date limite de paiement: ${_formatDate(widget.cotisation.dateEcheance)}',
|
||||
date: widget.cotisation.dateEcheance,
|
||||
icon: isOverdue ? Icons.warning : Icons.schedule,
|
||||
color: isOverdue ? AppTheme.errorColor : AppTheme.warningColor,
|
||||
isCompleted: isOverdue,
|
||||
isWarning: isOverdue,
|
||||
),
|
||||
);
|
||||
|
||||
// Ajouter les événements de paiement (simulés)
|
||||
if (widget.cotisation.montantPaye > 0) {
|
||||
_timelineEvents.add(
|
||||
TimelineEvent(
|
||||
title: 'Paiement partiel reçu',
|
||||
description: 'Montant: ${widget.cotisation.montantPaye.toStringAsFixed(0)} XOF',
|
||||
date: widget.cotisation.dateCreation.add(const Duration(days: 5)), // Simulé
|
||||
icon: Icons.payment,
|
||||
color: AppTheme.successColor,
|
||||
isCompleted: true,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (widget.cotisation.isEntierementPayee) {
|
||||
_timelineEvents.add(
|
||||
TimelineEvent(
|
||||
title: 'Paiement complet',
|
||||
description: 'Cotisation entièrement payée',
|
||||
date: widget.cotisation.dateCreation.add(const Duration(days: 10)), // Simulé
|
||||
icon: Icons.check_circle,
|
||||
color: AppTheme.successColor,
|
||||
isCompleted: true,
|
||||
isSuccess: true,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
// Ajouter les événements futurs
|
||||
if (!isOverdue) {
|
||||
_timelineEvents.add(
|
||||
TimelineEvent(
|
||||
title: 'Rappel automatique',
|
||||
description: 'Rappel envoyé 3 jours avant l\'échéance',
|
||||
date: widget.cotisation.dateEcheance.subtract(const Duration(days: 3)),
|
||||
icon: Icons.notifications,
|
||||
color: AppTheme.infoColor,
|
||||
isCompleted: false,
|
||||
isFuture: true,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
_timelineEvents.add(
|
||||
TimelineEvent(
|
||||
title: 'Paiement en attente',
|
||||
description: 'En attente du paiement complet',
|
||||
date: DateTime.now(),
|
||||
icon: Icons.hourglass_empty,
|
||||
color: AppTheme.textSecondary,
|
||||
isCompleted: false,
|
||||
isFuture: true,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Trier par date
|
||||
_timelineEvents.sort((a, b) => a.date.compareTo(b.date));
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (_timelineEvents.isEmpty) {
|
||||
return const Center(
|
||||
child: Text(
|
||||
'Aucun historique disponible',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
color: AppTheme.textSecondary,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'Historique de la cotisation',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppTheme.textPrimary,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
|
||||
Expanded(
|
||||
child: ListView.builder(
|
||||
itemCount: _timelineEvents.length,
|
||||
itemBuilder: (context, index) {
|
||||
return AnimatedBuilder(
|
||||
animation: _itemAnimations[index],
|
||||
builder: (context, child) {
|
||||
return Transform.translate(
|
||||
offset: Offset(
|
||||
0,
|
||||
50 * (1 - _itemAnimations[index].value),
|
||||
),
|
||||
child: Opacity(
|
||||
opacity: _itemAnimations[index].value,
|
||||
child: _buildTimelineItem(
|
||||
_timelineEvents[index],
|
||||
index,
|
||||
index == _timelineEvents.length - 1,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTimelineItem(TimelineEvent event, int index, bool isLast) {
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// Timeline indicator
|
||||
Column(
|
||||
children: [
|
||||
Container(
|
||||
width: 40,
|
||||
height: 40,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: event.isCompleted
|
||||
? event.color
|
||||
: event.color.withOpacity(0.2),
|
||||
border: Border.all(
|
||||
color: event.color,
|
||||
width: event.isCompleted ? 0 : 2,
|
||||
),
|
||||
),
|
||||
child: Icon(
|
||||
event.icon,
|
||||
size: 20,
|
||||
color: event.isCompleted
|
||||
? Colors.white
|
||||
: event.color,
|
||||
),
|
||||
),
|
||||
if (!isLast)
|
||||
Container(
|
||||
width: 2,
|
||||
height: 60,
|
||||
color: event.isCompleted
|
||||
? event.color.withOpacity(0.3)
|
||||
: AppTheme.borderLight,
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
|
||||
// Event content
|
||||
Expanded(
|
||||
child: Container(
|
||||
margin: const EdgeInsets.only(bottom: 20),
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: _getEventBackgroundColor(event),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(
|
||||
color: event.color.withOpacity(0.2),
|
||||
),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
event.title,
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: event.isCompleted
|
||||
? AppTheme.textPrimary
|
||||
: AppTheme.textSecondary,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (event.isSuccess)
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 8,
|
||||
vertical: 4,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: AppTheme.successColor.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: const Text(
|
||||
'Terminé',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppTheme.successColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (event.isWarning)
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 8,
|
||||
vertical: 4,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: AppTheme.errorColor.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: const Text(
|
||||
'En retard',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppTheme.errorColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
event.description,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: event.isCompleted
|
||||
? AppTheme.textSecondary
|
||||
: AppTheme.textHint,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.access_time,
|
||||
size: 16,
|
||||
color: AppTheme.textHint,
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
_formatDateTime(event.date),
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
color: AppTheme.textHint,
|
||||
),
|
||||
),
|
||||
if (event.isFuture) ...[
|
||||
const SizedBox(width: 8),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 6,
|
||||
vertical: 2,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: AppTheme.infoColor.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: const Text(
|
||||
'À venir',
|
||||
style: TextStyle(
|
||||
fontSize: 10,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppTheme.infoColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Color _getEventBackgroundColor(TimelineEvent event) {
|
||||
if (event.isSuccess) {
|
||||
return AppTheme.successColor.withOpacity(0.05);
|
||||
}
|
||||
if (event.isWarning) {
|
||||
return AppTheme.errorColor.withOpacity(0.05);
|
||||
}
|
||||
if (event.isFuture) {
|
||||
return AppTheme.infoColor.withOpacity(0.05);
|
||||
}
|
||||
return Colors.white;
|
||||
}
|
||||
|
||||
String _formatDate(DateTime date) {
|
||||
return '${date.day.toString().padLeft(2, '0')}/${date.month.toString().padLeft(2, '0')}/${date.year}';
|
||||
}
|
||||
|
||||
String _formatDateTime(DateTime date) {
|
||||
return '${_formatDate(date)} à ${date.hour.toString().padLeft(2, '0')}:${date.minute.toString().padLeft(2, '0')}';
|
||||
}
|
||||
}
|
||||
|
||||
/// Modèle pour les événements de la timeline
|
||||
class TimelineEvent {
|
||||
final String title;
|
||||
final String description;
|
||||
final DateTime date;
|
||||
final IconData icon;
|
||||
final Color color;
|
||||
final bool isCompleted;
|
||||
final bool isSuccess;
|
||||
final bool isWarning;
|
||||
final bool isFuture;
|
||||
|
||||
TimelineEvent({
|
||||
required this.title,
|
||||
required this.description,
|
||||
required this.date,
|
||||
required this.icon,
|
||||
required this.color,
|
||||
this.isCompleted = false,
|
||||
this.isSuccess = false,
|
||||
this.isWarning = false,
|
||||
this.isFuture = false,
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,457 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import '../../../../core/models/cotisation_model.dart';
|
||||
import '../../../../shared/theme/app_theme.dart';
|
||||
import '../../../../shared/widgets/buttons/buttons.dart';
|
||||
import '../../../../shared/widgets/buttons/primary_button.dart';
|
||||
import 'payment_method_selector.dart';
|
||||
|
||||
/// Widget de formulaire de paiement
|
||||
class PaymentFormWidget extends StatefulWidget {
|
||||
final CotisationModel cotisation;
|
||||
final Function(Map<String, dynamic>) onPaymentInitiated;
|
||||
|
||||
const PaymentFormWidget({
|
||||
super.key,
|
||||
required this.cotisation,
|
||||
required this.onPaymentInitiated,
|
||||
});
|
||||
|
||||
@override
|
||||
State<PaymentFormWidget> createState() => _PaymentFormWidgetState();
|
||||
}
|
||||
|
||||
class _PaymentFormWidgetState extends State<PaymentFormWidget>
|
||||
with TickerProviderStateMixin {
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
final _phoneController = TextEditingController();
|
||||
final _nameController = TextEditingController();
|
||||
final _emailController = TextEditingController();
|
||||
final _amountController = TextEditingController();
|
||||
|
||||
late final AnimationController _animationController;
|
||||
late final Animation<Offset> _slideAnimation;
|
||||
|
||||
String? _selectedPaymentMethod;
|
||||
bool _isProcessing = false;
|
||||
bool _acceptTerms = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_animationController = AnimationController(
|
||||
duration: const Duration(milliseconds: 600),
|
||||
vsync: this,
|
||||
);
|
||||
_slideAnimation = Tween<Offset>(
|
||||
begin: const Offset(0, 0.3),
|
||||
end: Offset.zero,
|
||||
).animate(CurvedAnimation(
|
||||
parent: _animationController,
|
||||
curve: Curves.easeOutCubic,
|
||||
));
|
||||
|
||||
// Initialiser le montant avec le montant restant à payer
|
||||
final remainingAmount = widget.cotisation.montantDu - widget.cotisation.montantPaye;
|
||||
_amountController.text = remainingAmount.toStringAsFixed(0);
|
||||
|
||||
_animationController.forward();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_phoneController.dispose();
|
||||
_nameController.dispose();
|
||||
_emailController.dispose();
|
||||
_amountController.dispose();
|
||||
_animationController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SlideTransition(
|
||||
position: _slideAnimation,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Form(
|
||||
key: _formKey,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// Sélection de la méthode de paiement
|
||||
PaymentMethodSelector(
|
||||
selectedMethod: _selectedPaymentMethod,
|
||||
montant: double.tryParse(_amountController.text) ?? 0,
|
||||
onMethodSelected: (method) {
|
||||
setState(() {
|
||||
_selectedPaymentMethod = method;
|
||||
});
|
||||
},
|
||||
),
|
||||
|
||||
if (_selectedPaymentMethod != null) ...[
|
||||
const SizedBox(height: 24),
|
||||
_buildPaymentForm(),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPaymentForm() {
|
||||
return AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 300),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'Informations de paiement',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppTheme.textPrimary,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// Montant à payer
|
||||
_buildAmountField(),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// Numéro de téléphone (pour Mobile Money)
|
||||
if (_isMobileMoneyMethod()) ...[
|
||||
_buildPhoneField(),
|
||||
const SizedBox(height: 16),
|
||||
],
|
||||
|
||||
// Nom du payeur
|
||||
_buildNameField(),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// Email (optionnel)
|
||||
_buildEmailField(),
|
||||
const SizedBox(height: 20),
|
||||
|
||||
// Conditions d'utilisation
|
||||
_buildTermsCheckbox(),
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// Bouton de paiement
|
||||
_buildPaymentButton(),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildAmountField() {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'Montant à payer',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: AppTheme.textSecondary,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
TextFormField(
|
||||
controller: _amountController,
|
||||
keyboardType: TextInputType.number,
|
||||
inputFormatters: [
|
||||
FilteringTextInputFormatter.digitsOnly,
|
||||
LengthLimitingTextInputFormatter(8),
|
||||
],
|
||||
decoration: InputDecoration(
|
||||
hintText: 'Entrez le montant',
|
||||
suffixText: 'XOF',
|
||||
prefixIcon: const Icon(Icons.attach_money),
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: const BorderSide(color: AppTheme.primaryColor, width: 2),
|
||||
),
|
||||
),
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return 'Veuillez entrer un montant';
|
||||
}
|
||||
final amount = double.tryParse(value);
|
||||
if (amount == null || amount <= 0) {
|
||||
return 'Montant invalide';
|
||||
}
|
||||
final remaining = widget.cotisation.montantDu - widget.cotisation.montantPaye;
|
||||
if (amount > remaining) {
|
||||
return 'Montant supérieur au solde restant (${remaining.toStringAsFixed(0)} XOF)';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
onChanged: (value) {
|
||||
setState(() {}); // Recalculer les frais
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPhoneField() {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'Numéro ${_getPaymentMethodName()}',
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: AppTheme.textSecondary,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
TextFormField(
|
||||
controller: _phoneController,
|
||||
keyboardType: TextInputType.phone,
|
||||
inputFormatters: [
|
||||
FilteringTextInputFormatter.digitsOnly,
|
||||
LengthLimitingTextInputFormatter(10),
|
||||
],
|
||||
decoration: InputDecoration(
|
||||
hintText: 'Ex: 0123456789',
|
||||
prefixIcon: const Icon(Icons.phone),
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: const BorderSide(color: AppTheme.primaryColor, width: 2),
|
||||
),
|
||||
),
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return 'Veuillez entrer votre numéro de téléphone';
|
||||
}
|
||||
if (value.length < 8) {
|
||||
return 'Numéro de téléphone invalide';
|
||||
}
|
||||
if (!_validatePhoneForMethod(value)) {
|
||||
return 'Ce numéro n\'est pas compatible avec ${_getPaymentMethodName()}';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildNameField() {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'Nom du payeur',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: AppTheme.textSecondary,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
TextFormField(
|
||||
controller: _nameController,
|
||||
textCapitalization: TextCapitalization.words,
|
||||
decoration: InputDecoration(
|
||||
hintText: 'Entrez votre nom complet',
|
||||
prefixIcon: const Icon(Icons.person),
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: const BorderSide(color: AppTheme.primaryColor, width: 2),
|
||||
),
|
||||
),
|
||||
validator: (value) {
|
||||
if (value == null || value.trim().isEmpty) {
|
||||
return 'Veuillez entrer votre nom';
|
||||
}
|
||||
if (value.trim().length < 2) {
|
||||
return 'Nom trop court';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildEmailField() {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'Email (optionnel)',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: AppTheme.textSecondary,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
TextFormField(
|
||||
controller: _emailController,
|
||||
keyboardType: TextInputType.emailAddress,
|
||||
decoration: InputDecoration(
|
||||
hintText: 'exemple@email.com',
|
||||
prefixIcon: const Icon(Icons.email),
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: const BorderSide(color: AppTheme.primaryColor, width: 2),
|
||||
),
|
||||
),
|
||||
validator: (value) {
|
||||
if (value != null && value.isNotEmpty) {
|
||||
if (!RegExp(r'^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$').hasMatch(value)) {
|
||||
return 'Email invalide';
|
||||
}
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTermsCheckbox() {
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Checkbox(
|
||||
value: _acceptTerms,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
_acceptTerms = value ?? false;
|
||||
});
|
||||
},
|
||||
activeColor: AppTheme.primaryColor,
|
||||
),
|
||||
Expanded(
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
setState(() {
|
||||
_acceptTerms = !_acceptTerms;
|
||||
});
|
||||
},
|
||||
child: const Text(
|
||||
'J\'accepte les conditions d\'utilisation et la politique de confidentialité',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: AppTheme.textSecondary,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPaymentButton() {
|
||||
return SizedBox(
|
||||
width: double.infinity,
|
||||
child: PrimaryButton(
|
||||
text: _isProcessing
|
||||
? 'Traitement en cours...'
|
||||
: 'Confirmer le paiement',
|
||||
icon: _isProcessing ? null : Icons.payment,
|
||||
onPressed: _canProceedPayment() ? _processPayment : null,
|
||||
isLoading: _isProcessing,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
bool _canProceedPayment() {
|
||||
return _selectedPaymentMethod != null &&
|
||||
_acceptTerms &&
|
||||
!_isProcessing &&
|
||||
_amountController.text.isNotEmpty;
|
||||
}
|
||||
|
||||
bool _isMobileMoneyMethod() {
|
||||
return _selectedPaymentMethod == 'ORANGE_MONEY' ||
|
||||
_selectedPaymentMethod == 'WAVE' ||
|
||||
_selectedPaymentMethod == 'MOOV_MONEY';
|
||||
}
|
||||
|
||||
String _getPaymentMethodName() {
|
||||
switch (_selectedPaymentMethod) {
|
||||
case 'ORANGE_MONEY':
|
||||
return 'Orange Money';
|
||||
case 'WAVE':
|
||||
return 'Wave';
|
||||
case 'MOOV_MONEY':
|
||||
return 'Moov Money';
|
||||
case 'CARTE_BANCAIRE':
|
||||
return 'Carte bancaire';
|
||||
default:
|
||||
return 'Paiement';
|
||||
}
|
||||
}
|
||||
|
||||
bool _validatePhoneForMethod(String phone) {
|
||||
final cleanNumber = phone.replaceAll(RegExp(r'[^\d]'), '');
|
||||
|
||||
switch (_selectedPaymentMethod) {
|
||||
case 'ORANGE_MONEY':
|
||||
// Orange: 07, 08, 09
|
||||
return RegExp(r'^(225)?(0[789])\d{8}$').hasMatch(cleanNumber);
|
||||
case 'WAVE':
|
||||
// Wave accepte tous les numéros ivoiriens
|
||||
return RegExp(r'^(225)?(0[1-9])\d{8}$').hasMatch(cleanNumber);
|
||||
case 'MOOV_MONEY':
|
||||
// Moov: 01, 02, 03
|
||||
return RegExp(r'^(225)?(0[123])\d{8}$').hasMatch(cleanNumber);
|
||||
default:
|
||||
return cleanNumber.length >= 8;
|
||||
}
|
||||
}
|
||||
|
||||
void _processPayment() {
|
||||
if (!_formKey.currentState!.validate()) {
|
||||
return;
|
||||
}
|
||||
|
||||
setState(() {
|
||||
_isProcessing = true;
|
||||
});
|
||||
|
||||
// Préparer les données de paiement
|
||||
final paymentData = {
|
||||
'montant': double.parse(_amountController.text),
|
||||
'methodePaiement': _selectedPaymentMethod!,
|
||||
'numeroTelephone': _phoneController.text,
|
||||
'nomPayeur': _nameController.text.trim(),
|
||||
'emailPayeur': _emailController.text.trim().isEmpty
|
||||
? null
|
||||
: _emailController.text.trim(),
|
||||
};
|
||||
|
||||
// Déclencher le paiement
|
||||
widget.onPaymentInitiated(paymentData);
|
||||
|
||||
// Simuler un délai de traitement
|
||||
Future.delayed(const Duration(seconds: 2), () {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_isProcessing = false;
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,443 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../../../../core/services/payment_service.dart';
|
||||
import '../../../../shared/theme/app_theme.dart';
|
||||
|
||||
/// Widget de sélection des méthodes de paiement
|
||||
class PaymentMethodSelector extends StatefulWidget {
|
||||
final String? selectedMethod;
|
||||
final Function(String) onMethodSelected;
|
||||
final double montant;
|
||||
|
||||
const PaymentMethodSelector({
|
||||
super.key,
|
||||
this.selectedMethod,
|
||||
required this.onMethodSelected,
|
||||
required this.montant,
|
||||
});
|
||||
|
||||
@override
|
||||
State<PaymentMethodSelector> createState() => _PaymentMethodSelectorState();
|
||||
}
|
||||
|
||||
class _PaymentMethodSelectorState extends State<PaymentMethodSelector>
|
||||
with TickerProviderStateMixin {
|
||||
late final AnimationController _animationController;
|
||||
late final Animation<double> _scaleAnimation;
|
||||
|
||||
List<PaymentMethod> _paymentMethods = [];
|
||||
String? _selectedMethod;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_selectedMethod = widget.selectedMethod;
|
||||
_animationController = AnimationController(
|
||||
duration: const Duration(milliseconds: 300),
|
||||
vsync: this,
|
||||
);
|
||||
_scaleAnimation = Tween<double>(begin: 0.8, end: 1.0).animate(
|
||||
CurvedAnimation(parent: _animationController, curve: Curves.elasticOut),
|
||||
);
|
||||
|
||||
_loadPaymentMethods();
|
||||
_animationController.forward();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_animationController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _loadPaymentMethods() {
|
||||
// En production, ceci viendrait du PaymentService
|
||||
_paymentMethods = [
|
||||
PaymentMethod(
|
||||
id: 'ORANGE_MONEY',
|
||||
nom: 'Orange Money',
|
||||
icone: '📱',
|
||||
couleur: '#FF6600',
|
||||
description: 'Paiement via Orange Money',
|
||||
fraisMinimum: 0,
|
||||
fraisMaximum: 1000,
|
||||
montantMinimum: 100,
|
||||
montantMaximum: 1000000,
|
||||
),
|
||||
PaymentMethod(
|
||||
id: 'WAVE',
|
||||
nom: 'Wave',
|
||||
icone: '🌊',
|
||||
couleur: '#00D4FF',
|
||||
description: 'Paiement via Wave',
|
||||
fraisMinimum: 0,
|
||||
fraisMaximum: 500,
|
||||
montantMinimum: 100,
|
||||
montantMaximum: 2000000,
|
||||
),
|
||||
PaymentMethod(
|
||||
id: 'MOOV_MONEY',
|
||||
nom: 'Moov Money',
|
||||
icone: '💙',
|
||||
couleur: '#0066CC',
|
||||
description: 'Paiement via Moov Money',
|
||||
fraisMinimum: 0,
|
||||
fraisMaximum: 800,
|
||||
montantMinimum: 100,
|
||||
montantMaximum: 1500000,
|
||||
),
|
||||
PaymentMethod(
|
||||
id: 'CARTE_BANCAIRE',
|
||||
nom: 'Carte bancaire',
|
||||
icone: '💳',
|
||||
couleur: '#4CAF50',
|
||||
description: 'Paiement par carte bancaire',
|
||||
fraisMinimum: 100,
|
||||
fraisMaximum: 2000,
|
||||
montantMinimum: 500,
|
||||
montantMaximum: 5000000,
|
||||
),
|
||||
];
|
||||
|
||||
// Filtrer les méthodes disponibles selon le montant
|
||||
_paymentMethods = _paymentMethods.where((method) {
|
||||
return widget.montant >= method.montantMinimum &&
|
||||
widget.montant <= method.montantMaximum;
|
||||
}).toList();
|
||||
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ScaleTransition(
|
||||
scale: _scaleAnimation,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'Choisissez votre méthode de paiement',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppTheme.textPrimary,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
if (_paymentMethods.isEmpty)
|
||||
_buildNoMethodsAvailable()
|
||||
else
|
||||
_buildMethodsList(),
|
||||
|
||||
if (_selectedMethod != null) ...[
|
||||
const SizedBox(height: 20),
|
||||
_buildSelectedMethodInfo(),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildNoMethodsAvailable() {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(20),
|
||||
decoration: BoxDecoration(
|
||||
color: AppTheme.warningColor.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(
|
||||
color: AppTheme.warningColor.withOpacity(0.3),
|
||||
),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.warning_amber,
|
||||
size: 48,
|
||||
color: AppTheme.warningColor,
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
const Text(
|
||||
'Aucune méthode de paiement disponible',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppTheme.textPrimary,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
'Le montant de ${widget.montant.toStringAsFixed(0)} XOF ne correspond aux limites d\'aucune méthode de paiement.',
|
||||
textAlign: TextAlign.center,
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
color: AppTheme.textSecondary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildMethodsList() {
|
||||
return Column(
|
||||
children: _paymentMethods.map((method) {
|
||||
final isSelected = _selectedMethod == method.id;
|
||||
final fees = _calculateFees(method);
|
||||
|
||||
return AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 200),
|
||||
margin: const EdgeInsets.only(bottom: 12),
|
||||
child: Material(
|
||||
color: Colors.transparent,
|
||||
child: InkWell(
|
||||
onTap: () => _selectMethod(method),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: isSelected
|
||||
? _getMethodColor(method.couleur).withOpacity(0.1)
|
||||
: Colors.white,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(
|
||||
color: isSelected
|
||||
? _getMethodColor(method.couleur)
|
||||
: AppTheme.borderLight,
|
||||
width: isSelected ? 2 : 1,
|
||||
),
|
||||
boxShadow: isSelected ? [
|
||||
BoxShadow(
|
||||
color: _getMethodColor(method.couleur).withOpacity(0.2),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
] : null,
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
// Icône de la méthode
|
||||
Container(
|
||||
width: 50,
|
||||
height: 50,
|
||||
decoration: BoxDecoration(
|
||||
color: _getMethodColor(method.couleur).withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(25),
|
||||
),
|
||||
child: Center(
|
||||
child: Text(
|
||||
method.icone,
|
||||
style: const TextStyle(fontSize: 24),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
|
||||
// Informations de la méthode
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
method.nom,
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: isSelected
|
||||
? _getMethodColor(method.couleur)
|
||||
: AppTheme.textPrimary,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
method.description,
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
color: AppTheme.textSecondary,
|
||||
),
|
||||
),
|
||||
if (fees > 0) ...[
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'Frais: ${fees.toStringAsFixed(0)} XOF',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: AppTheme.warningColor,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
// Indicateur de sélection
|
||||
AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 200),
|
||||
width: 24,
|
||||
height: 24,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: isSelected
|
||||
? _getMethodColor(method.couleur)
|
||||
: Colors.transparent,
|
||||
border: Border.all(
|
||||
color: isSelected
|
||||
? _getMethodColor(method.couleur)
|
||||
: AppTheme.borderLight,
|
||||
width: 2,
|
||||
),
|
||||
),
|
||||
child: isSelected
|
||||
? const Icon(
|
||||
Icons.check,
|
||||
size: 16,
|
||||
color: Colors.white,
|
||||
)
|
||||
: null,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSelectedMethodInfo() {
|
||||
final method = _paymentMethods.firstWhere((m) => m.id == _selectedMethod);
|
||||
final fees = _calculateFees(method);
|
||||
final total = widget.montant + fees;
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: _getMethodColor(method.couleur).withOpacity(0.05),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(
|
||||
color: _getMethodColor(method.couleur).withOpacity(0.2),
|
||||
),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Text(
|
||||
method.icone,
|
||||
style: const TextStyle(fontSize: 20),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
'Récapitulatif - ${method.nom}',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: _getMethodColor(method.couleur),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
|
||||
_buildSummaryRow('Montant', '${widget.montant.toStringAsFixed(0)} XOF'),
|
||||
if (fees > 0)
|
||||
_buildSummaryRow('Frais', '${fees.toStringAsFixed(0)} XOF'),
|
||||
const Divider(),
|
||||
_buildSummaryRow(
|
||||
'Total à payer',
|
||||
'${total.toStringAsFixed(0)} XOF',
|
||||
isTotal: true,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSummaryRow(String label, String value, {bool isTotal = false}) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 4),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
label,
|
||||
style: TextStyle(
|
||||
fontSize: isTotal ? 16 : 14,
|
||||
fontWeight: isTotal ? FontWeight.bold : FontWeight.normal,
|
||||
color: AppTheme.textSecondary,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
value,
|
||||
style: TextStyle(
|
||||
fontSize: isTotal ? 16 : 14,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: isTotal ? AppTheme.textPrimary : AppTheme.textSecondary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _selectMethod(PaymentMethod method) {
|
||||
setState(() {
|
||||
_selectedMethod = method.id;
|
||||
});
|
||||
widget.onMethodSelected(method.id);
|
||||
|
||||
// Animation de feedback
|
||||
_animationController.reset();
|
||||
_animationController.forward();
|
||||
}
|
||||
|
||||
double _calculateFees(PaymentMethod method) {
|
||||
// Simulation du calcul des frais
|
||||
switch (method.id) {
|
||||
case 'ORANGE_MONEY':
|
||||
return _calculateOrangeMoneyFees(widget.montant);
|
||||
case 'WAVE':
|
||||
return _calculateWaveFees(widget.montant);
|
||||
case 'MOOV_MONEY':
|
||||
return _calculateMoovMoneyFees(widget.montant);
|
||||
case 'CARTE_BANCAIRE':
|
||||
return _calculateCardFees(widget.montant);
|
||||
default:
|
||||
return 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
double _calculateOrangeMoneyFees(double montant) {
|
||||
if (montant <= 1000) return 0;
|
||||
if (montant <= 5000) return 25;
|
||||
if (montant <= 10000) return 50;
|
||||
if (montant <= 25000) return 100;
|
||||
if (montant <= 50000) return 200;
|
||||
return montant * 0.005; // 0.5%
|
||||
}
|
||||
|
||||
double _calculateWaveFees(double montant) {
|
||||
if (montant <= 2000) return 0;
|
||||
if (montant <= 10000) return 25;
|
||||
if (montant <= 50000) return 100;
|
||||
return montant * 0.003; // 0.3%
|
||||
}
|
||||
|
||||
double _calculateMoovMoneyFees(double montant) {
|
||||
if (montant <= 1000) return 0;
|
||||
if (montant <= 5000) return 30;
|
||||
if (montant <= 15000) return 75;
|
||||
if (montant <= 50000) return 150;
|
||||
return montant * 0.004; // 0.4%
|
||||
}
|
||||
|
||||
double _calculateCardFees(double montant) {
|
||||
return 100 + (montant * 0.025); // 100 XOF + 2.5%
|
||||
}
|
||||
|
||||
Color _getMethodColor(String colorHex) {
|
||||
return Color(int.parse(colorHex.replaceFirst('#', '0xFF')));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user