refactoring

This commit is contained in:
dahoud
2026-03-31 09:14:47 +00:00
parent 9bfffeeebe
commit 5383df6dcb
200 changed files with 11192 additions and 7063 deletions

View File

@@ -1,6 +1,7 @@
/// BLoC pour la gestion des contributions
library contributions_bloc;
import 'package:dio/dio.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:injectable/injectable.dart';
import '../../../core/utils/logger.dart';
@@ -82,6 +83,7 @@ class ContributionsBloc extends Bloc<ContributionsEvent, ContributionsState> {
'total': result.total,
});
} catch (e, stackTrace) {
if (e is DioException && e.type == DioExceptionType.cancel) return;
AppLogger.error('Erreur lors du chargement des contributions', error: e, stackTrace: stackTrace);
emit(ContributionsError(message: 'Erreur lors du chargement des contributions', error: e));
}
@@ -96,6 +98,7 @@ class ContributionsBloc extends Bloc<ContributionsEvent, ContributionsState> {
final contribution = await _getContributionById(event.id);
emit(ContributionDetailLoaded(contribution: contribution));
} catch (e, stackTrace) {
if (e is DioException && e.type == DioExceptionType.cancel) return;
AppLogger.error('Erreur', error: e, stackTrace: stackTrace);
emit(ContributionsError(message: 'Contribution non trouvée', error: e));
}
@@ -110,6 +113,7 @@ class ContributionsBloc extends Bloc<ContributionsEvent, ContributionsState> {
final created = await _createContribution(event.contribution);
emit(ContributionCreated(contribution: created));
} catch (e, stackTrace) {
if (e is DioException && e.type == DioExceptionType.cancel) return;
AppLogger.error('Erreur', error: e, stackTrace: stackTrace);
emit(ContributionsError(message: 'Erreur lors de la création de la contribution', error: e));
}
@@ -124,6 +128,7 @@ class ContributionsBloc extends Bloc<ContributionsEvent, ContributionsState> {
final updated = await _updateContribution(event.id, event.contribution);
emit(ContributionUpdated(contribution: updated));
} catch (e, stackTrace) {
if (e is DioException && e.type == DioExceptionType.cancel) return;
AppLogger.error('Erreur', error: e, stackTrace: stackTrace);
emit(ContributionsError(message: 'Erreur lors de la mise à jour', error: e));
}
@@ -138,6 +143,7 @@ class ContributionsBloc extends Bloc<ContributionsEvent, ContributionsState> {
await _deleteContribution(event.id);
emit(ContributionDeleted(id: event.id));
} catch (e, stackTrace) {
if (e is DioException && e.type == DioExceptionType.cancel) return;
AppLogger.error('Erreur', error: e, stackTrace: stackTrace);
emit(ContributionsError(message: 'Erreur lors de la suppression', error: e));
}
@@ -167,6 +173,7 @@ class ContributionsBloc extends Bloc<ContributionsEvent, ContributionsState> {
totalPages: result.totalPages,
));
} catch (e, stackTrace) {
if (e is DioException && e.type == DioExceptionType.cancel) return;
AppLogger.error('Erreur', error: e, stackTrace: stackTrace);
emit(ContributionsError(message: 'Erreur lors de la recherche', error: e));
}
@@ -193,6 +200,7 @@ class ContributionsBloc extends Bloc<ContributionsEvent, ContributionsState> {
totalPages: result.totalPages,
));
} catch (e, stackTrace) {
if (e is DioException && e.type == DioExceptionType.cancel) return;
AppLogger.error('Erreur', error: e, stackTrace: stackTrace);
emit(ContributionsError(message: 'Erreur lors du chargement', error: e));
}
@@ -214,6 +222,7 @@ class ContributionsBloc extends Bloc<ContributionsEvent, ContributionsState> {
totalPages: payees.isEmpty ? 0 : 1,
));
} catch (e, stackTrace) {
if (e is DioException && e.type == DioExceptionType.cancel) return;
AppLogger.error('Erreur', error: e, stackTrace: stackTrace);
emit(ContributionsError(message: 'Erreur', error: e));
}
@@ -235,6 +244,7 @@ class ContributionsBloc extends Bloc<ContributionsEvent, ContributionsState> {
totalPages: nonPayees.isEmpty ? 0 : 1,
));
} catch (e, stackTrace) {
if (e is DioException && e.type == DioExceptionType.cancel) return;
AppLogger.error('Erreur', error: e, stackTrace: stackTrace);
emit(ContributionsError(message: 'Erreur', error: e));
}
@@ -256,6 +266,7 @@ class ContributionsBloc extends Bloc<ContributionsEvent, ContributionsState> {
totalPages: enRetard.isEmpty ? 0 : 1,
));
} catch (e, stackTrace) {
if (e is DioException && e.type == DioExceptionType.cancel) return;
AppLogger.error('Erreur', error: e, stackTrace: stackTrace);
emit(ContributionsError(message: 'Erreur', error: e));
}
@@ -279,6 +290,7 @@ class ContributionsBloc extends Bloc<ContributionsEvent, ContributionsState> {
emit(PaymentRecorded(contribution: updated));
} catch (e, stackTrace) {
if (e is DioException && e.type == DioExceptionType.cancel) return;
AppLogger.error('Erreur', error: e, stackTrace: stackTrace);
emit(ContributionsError(message: 'Erreur lors de l\'enregistrement du paiement', error: e));
}
@@ -306,6 +318,7 @@ class ContributionsBloc extends Bloc<ContributionsEvent, ContributionsState> {
contributions: contributions,
));
} catch (e, stackTrace) {
if (e is DioException && e.type == DioExceptionType.cancel) return;
AppLogger.error('Erreur', error: e, stackTrace: stackTrace);
emit(ContributionsError(message: 'Erreur', error: e));
}
@@ -345,6 +358,7 @@ class ContributionsBloc extends Bloc<ContributionsEvent, ContributionsState> {
final count = await _repository.genererCotisationsAnnuelles(event.annee);
emit(ContributionsGenerated(nombreGenere: count));
} catch (e, stackTrace) {
if (e is DioException && e.type == DioExceptionType.cancel) return;
AppLogger.error('Erreur', error: e, stackTrace: stackTrace);
emit(ContributionsError(message: 'Erreur', error: e));
}
@@ -359,6 +373,7 @@ class ContributionsBloc extends Bloc<ContributionsEvent, ContributionsState> {
await _repository.envoyerRappel(event.contributionId);
emit(ReminderSent(contributionId: event.contributionId));
} catch (e, stackTrace) {
if (e is DioException && e.type == DioExceptionType.cancel) return;
AppLogger.error('Erreur', error: e, stackTrace: stackTrace);
emit(ContributionsError(message: 'Erreur', error: e));
}

View File

@@ -3,6 +3,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import '../../../../core/utils/logger.dart';
import 'package:fl_chart/fl_chart.dart';
import 'package:intl/intl.dart';
import '../../../../shared/design_system/tokens/app_colors.dart';
import '../../../../shared/design_system/unionflow_design_system.dart';
import '../../../../shared/design_system/tokens/unionflow_colors.dart';
import '../../../../shared/widgets/loading_widget.dart';
@@ -91,22 +92,22 @@ class _MesStatistiquesCotisationsPageState extends State<MesStatistiquesCotisati
return SingleChildScrollView(
physics: const AlwaysScrollableScrollPhysics(),
padding: const EdgeInsets.all(20),
padding: const EdgeInsets.all(12),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
_buildHeader(),
const SizedBox(height: 24),
const SizedBox(height: 12),
_buildKpiCards(),
const SizedBox(height: 20),
const SizedBox(height: 10),
_buildTauxSection(),
const SizedBox(height: 20),
const SizedBox(height: 10),
if (_cotisations != null && _cotisations!.isNotEmpty) _buildRepartitionChart(),
if (_cotisations != null && _cotisations!.isNotEmpty) const SizedBox(height: 20),
if (_cotisations != null && _cotisations!.isNotEmpty) const SizedBox(height: 10),
if (_cotisations != null && _cotisations!.isNotEmpty) _buildEvolutionSection(),
const SizedBox(height: 20),
const SizedBox(height: 10),
_buildProchainesEcheances(),
const SizedBox(height: 32),
const SizedBox(height: 16),
],
),
);
@@ -148,7 +149,7 @@ class _MesStatistiquesCotisationsPageState extends State<MesStatistiquesCotisati
'Montant dû',
_currencyFormat.format(montantDu),
icon: Icons.pending_actions_outlined,
color: montantDu > 0 ? UnionFlowColors.terracotta : UnionFlowColors.success,
color: montantDu > 0 ? UnionFlowColors.terracotta : AppColors.success,
),
),
const SizedBox(width: 12),
@@ -157,7 +158,7 @@ class _MesStatistiquesCotisationsPageState extends State<MesStatistiquesCotisati
'Payé cette année',
_currencyFormat.format(totalPayeAnnee),
icon: Icons.check_circle_outline,
color: UnionFlowColors.unionGreen,
color: AppColors.primaryGreen,
),
),
],
@@ -170,7 +171,7 @@ class _MesStatistiquesCotisationsPageState extends State<MesStatistiquesCotisati
'En attente',
'$enAttente',
icon: Icons.schedule,
color: enAttente > 0 ? UnionFlowColors.gold : UnionFlowColors.success,
color: enAttente > 0 ? UnionFlowColors.gold : AppColors.success,
),
),
const SizedBox(width: 12),
@@ -192,10 +193,10 @@ class _MesStatistiquesCotisationsPageState extends State<MesStatistiquesCotisati
Widget _kpiCard(String label, String value, {required IconData icon, required Color color}) {
return Container(
padding: const EdgeInsets.all(16),
padding: const EdgeInsets.all(10),
decoration: BoxDecoration(
color: ColorTokens.surface,
borderRadius: BorderRadius.circular(12),
borderRadius: BorderRadius.circular(8),
border: Border.all(color: ColorTokens.outline),
boxShadow: [BoxShadow(color: ColorTokens.shadow.withOpacity(0.06), blurRadius: 8, offset: const Offset(0, 2))],
),
@@ -235,10 +236,10 @@ class _MesStatistiquesCotisationsPageState extends State<MesStatistiquesCotisati
final taux = total > 0 ? (totalPayeAnnee / total * 100) : 0.0;
return Container(
padding: const EdgeInsets.all(20),
padding: const EdgeInsets.all(10),
decoration: BoxDecoration(
color: ColorTokens.surface,
borderRadius: BorderRadius.circular(16),
borderRadius: BorderRadius.circular(10),
border: Border.all(color: ColorTokens.outline),
boxShadow: [BoxShadow(color: ColorTokens.shadow.withOpacity(0.06), blurRadius: 8, offset: const Offset(0, 2))],
),
@@ -260,7 +261,7 @@ class _MesStatistiquesCotisationsPageState extends State<MesStatistiquesCotisati
minHeight: 12,
backgroundColor: ColorTokens.onSurfaceVariant.withOpacity(0.2),
valueColor: AlwaysStoppedAnimation<Color>(
taux >= 75 ? UnionFlowColors.success : (taux >= 50 ? UnionFlowColors.gold : UnionFlowColors.terracotta),
taux >= 75 ? AppColors.success : (taux >= 50 ? UnionFlowColors.gold : UnionFlowColors.terracotta),
),
),
),
@@ -271,7 +272,7 @@ class _MesStatistiquesCotisationsPageState extends State<MesStatistiquesCotisati
Text('0 %', style: AppTypography.bodyTextSmall.copyWith(color: ColorTokens.onSurfaceVariant)),
Text(
'${taux.toStringAsFixed(0)} %',
style: AppTypography.headerSmall.copyWith(color: UnionFlowColors.unionGreen, fontWeight: FontWeight.w700),
style: AppTypography.headerSmall.copyWith(color: AppColors.primaryGreen, fontWeight: FontWeight.w700),
),
Text('100 %', style: AppTypography.bodyTextSmall.copyWith(color: ColorTokens.onSurfaceVariant)),
],
@@ -293,7 +294,7 @@ class _MesStatistiquesCotisationsPageState extends State<MesStatistiquesCotisati
final sections = <PieChartSectionData>[];
if (paye > 0) {
sections.add(PieChartSectionData(
color: UnionFlowColors.unionGreen,
color: AppColors.primaryGreen,
value: paye,
title: 'Payé',
radius: 60,
@@ -312,10 +313,10 @@ class _MesStatistiquesCotisationsPageState extends State<MesStatistiquesCotisati
if (sections.isEmpty) return const SizedBox.shrink();
return Container(
padding: const EdgeInsets.all(20),
padding: const EdgeInsets.all(10),
decoration: BoxDecoration(
color: ColorTokens.surface,
borderRadius: BorderRadius.circular(16),
borderRadius: BorderRadius.circular(10),
border: Border.all(color: ColorTokens.outline),
boxShadow: [BoxShadow(color: ColorTokens.shadow.withOpacity(0.06), blurRadius: 8, offset: const Offset(0, 2))],
),
@@ -344,7 +345,7 @@ class _MesStatistiquesCotisationsPageState extends State<MesStatistiquesCotisati
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
_legendItem(UnionFlowColors.unionGreen, 'Payé', _currencyFormat.format(paye)),
_legendItem(AppColors.primaryGreen, 'Payé', _currencyFormat.format(paye)),
_legendItem(UnionFlowColors.terracotta, '', _currencyFormat.format(du)),
],
),
@@ -392,10 +393,10 @@ class _MesStatistiquesCotisationsPageState extends State<MesStatistiquesCotisati
final xIntervalSafe = xInterval < 1 ? 1.0 : xInterval;
return Container(
padding: const EdgeInsets.all(20),
padding: const EdgeInsets.all(10),
decoration: BoxDecoration(
color: ColorTokens.surface,
borderRadius: BorderRadius.circular(16),
borderRadius: BorderRadius.circular(10),
border: Border.all(color: ColorTokens.outline),
boxShadow: [BoxShadow(color: ColorTokens.shadow.withOpacity(0.06), blurRadius: 8, offset: const Offset(0, 2))],
),
@@ -453,11 +454,11 @@ class _MesStatistiquesCotisationsPageState extends State<MesStatistiquesCotisati
LineChartBarData(
spots: spots,
isCurved: true,
color: UnionFlowColors.unionGreen,
color: AppColors.primaryGreen,
barWidth: 2,
isStrokeCapRound: true,
dotData: const FlDotData(show: true),
belowBarData: BarAreaData(show: true, color: UnionFlowColors.unionGreen.withOpacity(0.15)),
belowBarData: BarAreaData(show: true, color: AppColors.primaryGreen.withOpacity(0.15)),
),
],
),
@@ -476,10 +477,10 @@ class _MesStatistiquesCotisationsPageState extends State<MesStatistiquesCotisati
if (top.isEmpty) return const SizedBox.shrink();
return Container(
padding: const EdgeInsets.all(20),
padding: const EdgeInsets.all(10),
decoration: BoxDecoration(
color: ColorTokens.surface,
borderRadius: BorderRadius.circular(16),
borderRadius: BorderRadius.circular(10),
border: Border.all(color: ColorTokens.outline),
boxShadow: [BoxShadow(color: ColorTokens.shadow.withOpacity(0.06), blurRadius: 8, offset: const Offset(0, 2))],
),