refactoring
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
/// BLoC pour la gestion des adhésions (demandes d'adhésion)
|
||||
library adhesions_bloc;
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
@@ -34,6 +35,7 @@ class AdhesionsBloc extends Bloc<AdhesionsEvent, AdhesionsState> {
|
||||
final list = await _repository.getAll(page: event.page, size: event.size);
|
||||
emit(state.copyWith(status: AdhesionsStatus.loaded, adhesions: list));
|
||||
} catch (e) {
|
||||
if (e is DioException && e.type == DioExceptionType.cancel) return;
|
||||
emit(state.copyWith(status: AdhesionsStatus.error, message: e.toString(), error: e));
|
||||
}
|
||||
}
|
||||
@@ -44,6 +46,7 @@ class AdhesionsBloc extends Bloc<AdhesionsEvent, AdhesionsState> {
|
||||
final list = await _repository.getByMembre(event.membreId, page: event.page, size: event.size);
|
||||
emit(state.copyWith(status: AdhesionsStatus.loaded, adhesions: list));
|
||||
} catch (e) {
|
||||
if (e is DioException && e.type == DioExceptionType.cancel) return;
|
||||
emit(state.copyWith(status: AdhesionsStatus.error, message: e.toString(), error: e));
|
||||
}
|
||||
}
|
||||
@@ -55,6 +58,7 @@ class AdhesionsBloc extends Bloc<AdhesionsEvent, AdhesionsState> {
|
||||
final list = await _repository.getEnAttente(page: event.page, size: event.size);
|
||||
emit(state.copyWith(status: AdhesionsStatus.loaded, adhesions: list));
|
||||
} catch (e) {
|
||||
if (e is DioException && e.type == DioExceptionType.cancel) return;
|
||||
emit(state.copyWith(status: AdhesionsStatus.error, message: e.toString(), error: e));
|
||||
}
|
||||
}
|
||||
@@ -65,6 +69,7 @@ class AdhesionsBloc extends Bloc<AdhesionsEvent, AdhesionsState> {
|
||||
final list = await _repository.getByStatut(event.statut, page: event.page, size: event.size);
|
||||
emit(state.copyWith(status: AdhesionsStatus.loaded, adhesions: list));
|
||||
} catch (e) {
|
||||
if (e is DioException && e.type == DioExceptionType.cancel) return;
|
||||
emit(state.copyWith(status: AdhesionsStatus.error, message: e.toString(), error: e));
|
||||
}
|
||||
}
|
||||
@@ -75,6 +80,7 @@ class AdhesionsBloc extends Bloc<AdhesionsEvent, AdhesionsState> {
|
||||
final adhesion = await _repository.getById(event.id);
|
||||
emit(state.copyWith(status: AdhesionsStatus.loaded, adhesionDetail: adhesion));
|
||||
} catch (e) {
|
||||
if (e is DioException && e.type == DioExceptionType.cancel) return;
|
||||
emit(state.copyWith(status: AdhesionsStatus.error, message: e.toString(), error: e));
|
||||
}
|
||||
}
|
||||
@@ -85,6 +91,7 @@ class AdhesionsBloc extends Bloc<AdhesionsEvent, AdhesionsState> {
|
||||
await _repository.create(event.adhesion);
|
||||
add(const LoadAdhesions());
|
||||
} catch (e) {
|
||||
if (e is DioException && e.type == DioExceptionType.cancel) return;
|
||||
emit(state.copyWith(status: AdhesionsStatus.error, message: e.toString(), error: e));
|
||||
}
|
||||
}
|
||||
@@ -96,6 +103,7 @@ class AdhesionsBloc extends Bloc<AdhesionsEvent, AdhesionsState> {
|
||||
emit(state.copyWith(status: AdhesionsStatus.loaded, adhesionDetail: updated));
|
||||
add(const LoadAdhesions());
|
||||
} catch (e) {
|
||||
if (e is DioException && e.type == DioExceptionType.cancel) return;
|
||||
emit(state.copyWith(status: AdhesionsStatus.error, message: e.toString(), error: e));
|
||||
}
|
||||
}
|
||||
@@ -107,6 +115,7 @@ class AdhesionsBloc extends Bloc<AdhesionsEvent, AdhesionsState> {
|
||||
emit(state.copyWith(status: AdhesionsStatus.loaded, adhesionDetail: updated));
|
||||
add(const LoadAdhesions());
|
||||
} catch (e) {
|
||||
if (e is DioException && e.type == DioExceptionType.cancel) return;
|
||||
emit(state.copyWith(status: AdhesionsStatus.error, message: e.toString(), error: e));
|
||||
}
|
||||
}
|
||||
@@ -123,6 +132,7 @@ class AdhesionsBloc extends Bloc<AdhesionsEvent, AdhesionsState> {
|
||||
emit(state.copyWith(status: AdhesionsStatus.loaded, adhesionDetail: updated));
|
||||
add(const LoadAdhesions());
|
||||
} catch (e) {
|
||||
if (e is DioException && e.type == DioExceptionType.cancel) return;
|
||||
emit(state.copyWith(status: AdhesionsStatus.error, message: e.toString(), error: e));
|
||||
}
|
||||
}
|
||||
@@ -132,6 +142,7 @@ class AdhesionsBloc extends Bloc<AdhesionsEvent, AdhesionsState> {
|
||||
final stats = await _repository.getStats();
|
||||
emit(state.copyWith(stats: stats));
|
||||
} catch (e, st) {
|
||||
if (e is DioException && e.type == DioExceptionType.cancel) return;
|
||||
AppLogger.error('AdhesionsBloc: chargement stats échoué', error: e, stackTrace: st);
|
||||
emit(state.copyWith(
|
||||
status: AdhesionsStatus.error,
|
||||
|
||||
@@ -42,7 +42,7 @@ class _AdhesionDetailPageState extends State<AdhesionDetailPage> {
|
||||
listener: (context, state) {
|
||||
if (state.status == AdhesionsStatus.error && state.message != null) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(state.message!), backgroundColor: Colors.red),
|
||||
SnackBar(content: Text(state.message!), backgroundColor: AppColors.error),
|
||||
);
|
||||
}
|
||||
},
|
||||
@@ -58,7 +58,7 @@ class _AdhesionDetailPageState extends State<AdhesionDetailPage> {
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Icon(Icons.error_outline, size: 64, color: Colors.grey),
|
||||
const Icon(Icons.error_outline, size: 64, color: AppColors.textSecondaryLight),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'Adhésion introuvable',
|
||||
@@ -69,7 +69,7 @@ class _AdhesionDetailPageState extends State<AdhesionDetailPage> {
|
||||
);
|
||||
}
|
||||
return SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
padding: const EdgeInsets.all(12),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
@@ -190,7 +190,7 @@ Widget _buildStatutBadge(String? statut) {
|
||||
color = AppColors.brandGreenLight;
|
||||
break;
|
||||
case 'EN_PAIEMENT':
|
||||
color = Colors.blue;
|
||||
color = AppColors.warning;
|
||||
break;
|
||||
default:
|
||||
color = AppColors.textSecondaryLight;
|
||||
|
||||
@@ -76,7 +76,7 @@ class _AdhesionsPageState extends State<AdhesionsPage>
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(state.message!),
|
||||
backgroundColor: Colors.red,
|
||||
backgroundColor: AppColors.error,
|
||||
action: SnackBarAction(
|
||||
label: 'Réessayer',
|
||||
textColor: Colors.white,
|
||||
@@ -146,11 +146,11 @@ class _AdhesionsPageState extends State<AdhesionsPage>
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(Icons.assignment_outlined, size: 64, color: Colors.grey[400]),
|
||||
const SizedBox(height: 16),
|
||||
Icon(Icons.assignment_outlined, size: 40, color: AppColors.textSecondaryLight),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
'Aucune demande d\'adhésion',
|
||||
style: TextStyle(fontSize: 16, color: Colors.grey[600]),
|
||||
style: AppTypography.bodyTextSmall.copyWith(fontSize: 16, color: AppColors.textSecondaryLight),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
TextButton.icon(
|
||||
@@ -304,7 +304,7 @@ class _AdhesionCard extends StatelessWidget {
|
||||
color = AppColors.brandGreenLight;
|
||||
break;
|
||||
case 'EN_PAIEMENT':
|
||||
color = Colors.blue;
|
||||
color = AppColors.warning;
|
||||
break;
|
||||
default:
|
||||
color = AppColors.textSecondaryLight;
|
||||
|
||||
@@ -5,6 +5,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
import '../../../../core/utils/logger.dart';
|
||||
import '../../../../shared/design_system/unionflow_design_system.dart';
|
||||
import '../../bloc/adhesions_bloc.dart';
|
||||
import '../../data/models/adhesion_model.dart';
|
||||
import '../../../organizations/data/models/organization_model.dart';
|
||||
@@ -124,7 +125,7 @@ class _CreateAdhesionDialogState extends State<CreateAdhesionDialog> {
|
||||
enabled: false,
|
||||
)
|
||||
else
|
||||
const Text('Impossible de récupérer votre profil', style: TextStyle(color: Colors.red)),
|
||||
const Text('Impossible de récupérer votre profil', style: TextStyle(color: AppColors.error)),
|
||||
const SizedBox(height: 16),
|
||||
DropdownButtonFormField<String>(
|
||||
value: _organisationId,
|
||||
|
||||
@@ -3,6 +3,7 @@ library rejet_adhesion_dialog;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import '../../../../shared/design_system/unionflow_design_system.dart';
|
||||
import '../../bloc/adhesions_bloc.dart';
|
||||
|
||||
class RejetAdhesionDialog extends StatefulWidget {
|
||||
@@ -86,7 +87,7 @@ class _RejetAdhesionDialogState extends State<RejetAdhesionDialog> {
|
||||
),
|
||||
FilledButton(
|
||||
onPressed: _loading ? null : _submit,
|
||||
style: FilledButton.styleFrom(backgroundColor: Colors.red),
|
||||
style: FilledButton.styleFrom(backgroundColor: AppColors.error),
|
||||
child: _loading
|
||||
? const SizedBox(
|
||||
width: 20,
|
||||
|
||||
Reference in New Issue
Block a user