refactoring
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
/// BLoC pour la gestion des rapports (Clean Architecture)
|
||||
library reports_bloc;
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
@@ -52,6 +53,7 @@ class ReportsBloc extends Bloc<ReportsEvent, ReportsState> {
|
||||
statsEvenements: results[3],
|
||||
));
|
||||
} catch (e) {
|
||||
if (e is DioException && e.type == DioExceptionType.cancel) return;
|
||||
emit(ReportsError('Erreur lors du chargement des rapports : $e'));
|
||||
}
|
||||
}
|
||||
@@ -65,6 +67,7 @@ class ReportsBloc extends Bloc<ReportsEvent, ReportsState> {
|
||||
await _scheduleReport(cronExpression: event.cronExpression);
|
||||
emit(const ReportScheduled());
|
||||
} catch (e) {
|
||||
if (e is DioException && e.type == DioExceptionType.cancel) return;
|
||||
emit(ReportsError('Impossible de programmer le rapport : $e'));
|
||||
}
|
||||
}
|
||||
@@ -78,6 +81,7 @@ class ReportsBloc extends Bloc<ReportsEvent, ReportsState> {
|
||||
await _generateReport(event.type, format: event.format);
|
||||
emit(ReportGenerated(event.type));
|
||||
} catch (e) {
|
||||
if (e is DioException && e.type == DioExceptionType.cancel) return;
|
||||
emit(ReportsError('Impossible de générer le rapport : $e'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,18 +63,18 @@ class _ReportsPageState extends State<ReportsPage>
|
||||
}
|
||||
if (state is ReportScheduled) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(state.message), backgroundColor: const Color(0xFF00B894), behavior: SnackBarBehavior.floating),
|
||||
SnackBar(content: Text(state.message), backgroundColor: AppColors.success, behavior: SnackBarBehavior.floating),
|
||||
);
|
||||
}
|
||||
if (state is ReportGenerated) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(state.message), backgroundColor: const Color(0xFF00B894), behavior: SnackBarBehavior.floating),
|
||||
SnackBar(content: Text(state.message), backgroundColor: AppColors.success, behavior: SnackBarBehavior.floating),
|
||||
);
|
||||
}
|
||||
},
|
||||
builder: (context, state) {
|
||||
return Scaffold(
|
||||
backgroundColor: AppColors.darkBackground,
|
||||
backgroundColor: AppColors.lightBackground,
|
||||
body: Column(
|
||||
children: [
|
||||
_buildHeader(),
|
||||
@@ -107,10 +107,10 @@ class _ReportsPageState extends State<ReportsPage>
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
padding: EdgeInsets.only(
|
||||
top: MediaQuery.of(context).padding.top + 20,
|
||||
bottom: 30,
|
||||
left: 20,
|
||||
right: 20,
|
||||
top: MediaQuery.of(context).padding.top + 12,
|
||||
bottom: 16,
|
||||
left: 12,
|
||||
right: 12,
|
||||
),
|
||||
decoration: const BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
@@ -162,7 +162,7 @@ class _ReportsPageState extends State<ReportsPage>
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
const SizedBox(height: 12),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
@@ -197,10 +197,10 @@ class _ReportsPageState extends State<ReportsPage>
|
||||
|
||||
Widget _buildHeaderStat(String label, String value, IconData icon) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 8),
|
||||
padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 8),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withOpacity(0.15),
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
border: Border.all(color: Colors.white.withOpacity(0.2)),
|
||||
),
|
||||
child: Column(
|
||||
@@ -228,7 +228,7 @@ class _ReportsPageState extends State<ReportsPage>
|
||||
return Container(
|
||||
margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.darkBackground,
|
||||
color: AppColors.lightBackground,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(color: AppColors.lightBorder.withOpacity(0.1)),
|
||||
),
|
||||
@@ -252,14 +252,14 @@ class _ReportsPageState extends State<ReportsPage>
|
||||
|
||||
Widget _buildOverviewTab() {
|
||||
return ListView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
padding: const EdgeInsets.all(12),
|
||||
children: [
|
||||
_buildKPICards(),
|
||||
const SizedBox(height: 24),
|
||||
const SizedBox(height: 12),
|
||||
_buildActivityChart(),
|
||||
const SizedBox(height: 24),
|
||||
const SizedBox(height: 12),
|
||||
_buildQuickReports(),
|
||||
const SizedBox(height: 32),
|
||||
const SizedBox(height: 16),
|
||||
],
|
||||
);
|
||||
}
|
||||
@@ -275,15 +275,15 @@ class _ReportsPageState extends State<ReportsPage>
|
||||
Row(
|
||||
children: [
|
||||
Expanded(child: _buildKPICard('Total Membres', totalMembres, Icons.people_outline, AppColors.info)),
|
||||
const SizedBox(width: 16),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(child: _buildKPICard('Membres Actifs', membresActifs, Icons.how_to_reg_outlined, AppColors.success)),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
const SizedBox(height: 8),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(child: _buildKPICard('Cotisations', totalCotisations, Icons.payments_outlined, AppColors.brandGreen)),
|
||||
const SizedBox(width: 16),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(child: _buildKPICard('Événements', totalEvenements, Icons.event_available_outlined, AppColors.warning)),
|
||||
],
|
||||
),
|
||||
@@ -293,18 +293,18 @@ class _ReportsPageState extends State<ReportsPage>
|
||||
|
||||
Widget _buildKPICard(String title, String value, IconData icon, Color color) {
|
||||
return CoreCard(
|
||||
padding: const EdgeInsets.all(20),
|
||||
padding: const EdgeInsets.all(10),
|
||||
child: Column(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(10),
|
||||
padding: const EdgeInsets.all(8),
|
||||
decoration: BoxDecoration(
|
||||
color: color.withOpacity(0.1),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: Icon(icon, color: color, size: 24),
|
||||
child: Icon(icon, color: color, size: 20),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
const SizedBox(height: 6),
|
||||
Text(
|
||||
value,
|
||||
style: AppTypography.headerSmall.copyWith(color: color, fontWeight: FontWeight.bold),
|
||||
@@ -326,21 +326,21 @@ class _ReportsPageState extends State<ReportsPage>
|
||||
|
||||
Widget _buildActivityChart() {
|
||||
return CoreCard(
|
||||
padding: const EdgeInsets.all(20),
|
||||
padding: const EdgeInsets.all(10),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
const Icon(Icons.analytics_outlined, color: AppColors.primaryGreen, size: 20),
|
||||
const SizedBox(width: 12),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
'Évolution de l\'Activité'.toUpperCase(),
|
||||
style: AppTypography.subtitleSmall.copyWith(fontWeight: FontWeight.bold, letterSpacing: 1.1),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
const SizedBox(height: 10),
|
||||
Container(
|
||||
height: 180,
|
||||
decoration: BoxDecoration(
|
||||
@@ -368,21 +368,21 @@ class _ReportsPageState extends State<ReportsPage>
|
||||
|
||||
Widget _buildQuickReports() {
|
||||
return CoreCard(
|
||||
padding: const EdgeInsets.all(20),
|
||||
padding: const EdgeInsets.all(10),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
const Icon(Icons.flash_on_outlined, color: AppColors.warning, size: 20),
|
||||
const SizedBox(width: 12),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
'Rapports Favoris'.toUpperCase(),
|
||||
style: AppTypography.subtitleSmall.copyWith(fontWeight: FontWeight.bold, letterSpacing: 1.1),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
const SizedBox(height: 10),
|
||||
_buildQuickReportItem('Bilan Annuel', 'Synthèse financière et activité', Icons.summarize_outlined, () => _generateReport('monthly')),
|
||||
_buildQuickReportItem('Engagement Membres', 'Analyse de participation globale', Icons.query_stats_outlined, () => _generateReport('top_members')),
|
||||
_buildQuickReportItem('Impact Événements', 'Analyse SEO et participation', Icons.insights_outlined, () => _generateReport('events_analysis')),
|
||||
@@ -393,12 +393,12 @@ class _ReportsPageState extends State<ReportsPage>
|
||||
|
||||
Widget _buildQuickReportItem(String title, String subtitle, IconData icon, VoidCallback onTap) {
|
||||
return Container(
|
||||
margin: const EdgeInsets.only(bottom: 12),
|
||||
margin: const EdgeInsets.only(bottom: 6),
|
||||
child: InkWell(
|
||||
onTap: onTap,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(12),
|
||||
padding: const EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.lightBorder.withOpacity(0.05),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
@@ -439,11 +439,11 @@ class _ReportsPageState extends State<ReportsPage>
|
||||
padding: const EdgeInsets.all(12),
|
||||
child: Column(
|
||||
children: [
|
||||
const SizedBox(height: 16),
|
||||
const SizedBox(height: 8),
|
||||
_buildMembersStats(),
|
||||
const SizedBox(height: 16),
|
||||
const SizedBox(height: 8),
|
||||
_buildMembersReports(),
|
||||
const SizedBox(height: 80),
|
||||
const SizedBox(height: 40),
|
||||
],
|
||||
),
|
||||
);
|
||||
@@ -455,21 +455,21 @@ class _ReportsPageState extends State<ReportsPage>
|
||||
final actifs = _statsMembres['actifs7j']?.toString() ?? '--';
|
||||
|
||||
return CoreCard(
|
||||
padding: const EdgeInsets.all(20),
|
||||
padding: const EdgeInsets.all(10),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
const Icon(Icons.people_alt_outlined, color: AppColors.info, size: 20),
|
||||
const SizedBox(width: 12),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
'Indicateurs Membres'.toUpperCase(),
|
||||
style: AppTypography.subtitleSmall.copyWith(fontWeight: FontWeight.bold, letterSpacing: 1.1),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
const SizedBox(height: 10),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(child: _buildStatItem('Total', total)),
|
||||
@@ -752,7 +752,7 @@ class _ReportsPageState extends State<ReportsPage>
|
||||
Navigator.of(context).pop();
|
||||
context.read<ReportsBloc>().add(GenerateReportRequested('export', format: _selectedFormat));
|
||||
},
|
||||
style: ElevatedButton.styleFrom(backgroundColor: const Color(0xFF6C5CE7), foregroundColor: Colors.white),
|
||||
style: ElevatedButton.styleFrom(backgroundColor: AppColors.primaryGreen, foregroundColor: Colors.white),
|
||||
child: const Text('Exporter'),
|
||||
),
|
||||
],
|
||||
@@ -770,7 +770,7 @@ class _ReportsPageState extends State<ReportsPage>
|
||||
|
||||
void _showSuccessSnackBar(String message) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(message), backgroundColor: const Color(0xFF00B894), behavior: SnackBarBehavior.floating),
|
||||
SnackBar(content: Text(message), backgroundColor: AppColors.success, behavior: SnackBarBehavior.floating),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user