Initial commit: unionflow-mobile-apps
Application Flutter complète (sans build artifacts). Signed-off-by: lions dev Team
This commit is contained in:
108
lib/features/reports/data/models/analytics_model.dart
Normal file
108
lib/features/reports/data/models/analytics_model.dart
Normal file
@@ -0,0 +1,108 @@
|
||||
library analytics_model;
|
||||
|
||||
import 'package:equatable/equatable.dart';
|
||||
|
||||
/// Modèle pour une métrique analytics — aligné avec AnalyticsDataDTO
|
||||
class AnalyticsModel extends Equatable {
|
||||
final String? id;
|
||||
final String typeMetrique;
|
||||
final String periodeAnalyse;
|
||||
final double valeur;
|
||||
final double? valeurPrecedente;
|
||||
final double? pourcentageEvolution;
|
||||
final DateTime? dateDebut;
|
||||
final DateTime? dateFin;
|
||||
final String? libelle;
|
||||
final String? description;
|
||||
final String? unite;
|
||||
final String? couleur;
|
||||
final String? icone;
|
||||
|
||||
const AnalyticsModel({
|
||||
this.id,
|
||||
required this.typeMetrique,
|
||||
required this.periodeAnalyse,
|
||||
required this.valeur,
|
||||
this.valeurPrecedente,
|
||||
this.pourcentageEvolution,
|
||||
this.dateDebut,
|
||||
this.dateFin,
|
||||
this.libelle,
|
||||
this.description,
|
||||
this.unite,
|
||||
this.couleur,
|
||||
this.icone,
|
||||
});
|
||||
|
||||
bool get hasPositiveTrend =>
|
||||
pourcentageEvolution != null && pourcentageEvolution! > 0;
|
||||
bool get hasNegativeTrend =>
|
||||
pourcentageEvolution != null && pourcentageEvolution! < 0;
|
||||
|
||||
factory AnalyticsModel.fromJson(Map<String, dynamic> json) {
|
||||
return AnalyticsModel(
|
||||
id: json['id']?.toString(),
|
||||
typeMetrique: json['typeMetrique']?.toString() ?? '',
|
||||
periodeAnalyse: json['periodeAnalyse']?.toString() ?? '',
|
||||
valeur: _parseDouble(json['valeur']),
|
||||
valeurPrecedente: json['valeurPrecedente'] != null
|
||||
? _parseDouble(json['valeurPrecedente'])
|
||||
: null,
|
||||
pourcentageEvolution: json['pourcentageEvolution'] != null
|
||||
? _parseDouble(json['pourcentageEvolution'])
|
||||
: null,
|
||||
dateDebut: json['dateDebut'] != null
|
||||
? DateTime.tryParse(json['dateDebut'].toString())
|
||||
: null,
|
||||
dateFin: json['dateFin'] != null
|
||||
? DateTime.tryParse(json['dateFin'].toString())
|
||||
: null,
|
||||
libelle: json['libellePersonnalise']?.toString() ?? json['typeMetrique']?.toString(),
|
||||
description: json['description']?.toString(),
|
||||
unite: json['unite']?.toString(),
|
||||
couleur: json['couleur']?.toString(),
|
||||
icone: json['icone']?.toString(),
|
||||
);
|
||||
}
|
||||
|
||||
static double _parseDouble(dynamic val) {
|
||||
if (val == null) return 0.0;
|
||||
if (val is num) return val.toDouble();
|
||||
return double.tryParse(val.toString()) ?? 0.0;
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [id, typeMetrique, valeur, periodeAnalyse];
|
||||
}
|
||||
|
||||
/// KPI synthétique pour le tableau de bord des rapports
|
||||
class KpiModel extends Equatable {
|
||||
final String libelle;
|
||||
final double valeur;
|
||||
final String? unite;
|
||||
final double? evolution;
|
||||
final String? couleur;
|
||||
|
||||
const KpiModel({
|
||||
required this.libelle,
|
||||
required this.valeur,
|
||||
this.unite,
|
||||
this.evolution,
|
||||
this.couleur,
|
||||
});
|
||||
|
||||
factory KpiModel.fromJson(Map<String, dynamic> json) {
|
||||
return KpiModel(
|
||||
libelle: json['libelle']?.toString() ?? json['nom']?.toString() ?? '',
|
||||
valeur: AnalyticsModel._parseDouble(json['valeur'] ?? json['value']),
|
||||
unite: json['unite']?.toString(),
|
||||
evolution: json['evolution'] != null
|
||||
? AnalyticsModel._parseDouble(json['evolution'])
|
||||
: null,
|
||||
couleur: json['couleur']?.toString(),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [libelle, valeur];
|
||||
}
|
||||
230
lib/features/reports/data/repositories/reports_repository.dart
Normal file
230
lib/features/reports/data/repositories/reports_repository.dart
Normal file
@@ -0,0 +1,230 @@
|
||||
/// Repository pour la gestion des rapports et analytics
|
||||
library reports_repository_impl;
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
import 'package:unionflow_mobile_apps/core/network/api_client.dart';
|
||||
import 'package:unionflow_mobile_apps/core/utils/logger.dart';
|
||||
import '../../domain/repositories/reports_repository.dart';
|
||||
import '../models/analytics_model.dart';
|
||||
|
||||
/// Implémentation du repository des rapports
|
||||
@LazySingleton(as: IReportsRepository)
|
||||
class ReportsRepositoryImpl implements IReportsRepository {
|
||||
final ApiClient _apiClient;
|
||||
static const String _analyticsBase = '/api/v1/analytics';
|
||||
static const String _membresBase = '/api/membres';
|
||||
static const String _cotisationsBase = '/api/cotisations';
|
||||
static const String _evenementsBase = '/api/evenements';
|
||||
|
||||
ReportsRepositoryImpl(this._apiClient);
|
||||
|
||||
@override
|
||||
Future<List<AnalyticsModel>> getMetriques(String typeMetrique, String periode) async {
|
||||
try {
|
||||
final response = await _apiClient.get(
|
||||
'$_analyticsBase/metriques/$typeMetrique',
|
||||
queryParameters: {'periodeAnalyse': periode},
|
||||
);
|
||||
if (response.statusCode == 200) {
|
||||
final data = response.data;
|
||||
if (data is List) {
|
||||
return data.map((e) => AnalyticsModel.fromJson(e as Map<String, dynamic>)).toList();
|
||||
}
|
||||
if (data is Map) {
|
||||
return [AnalyticsModel.fromJson(data as Map<String, dynamic>)];
|
||||
}
|
||||
}
|
||||
return [];
|
||||
} on DioException catch (e, st) {
|
||||
AppLogger.error('ReportsRepository: getMetriques échoué', error: e, stackTrace: st);
|
||||
if (e.response?.statusCode == 404 || e.response?.statusCode == 400) return [];
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Map<String, dynamic>> getPerformanceGlobale() async {
|
||||
try {
|
||||
final response = await _apiClient.get('$_analyticsBase/performance-globale');
|
||||
if (response.statusCode == 200 && response.data is Map) {
|
||||
return response.data as Map<String, dynamic>;
|
||||
}
|
||||
return {};
|
||||
} on DioException catch (e, st) {
|
||||
AppLogger.error('ReportsRepository: getPerformanceGlobale échoué', error: e, stackTrace: st);
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<AnalyticsModel>> getEvolutions(String typeMetrique) async {
|
||||
try {
|
||||
final response = await _apiClient.get(
|
||||
'$_analyticsBase/evolutions',
|
||||
queryParameters: {'typeMetrique': typeMetrique},
|
||||
);
|
||||
if (response.statusCode == 200) {
|
||||
final data = response.data;
|
||||
if (data is List) {
|
||||
return data.map((e) => AnalyticsModel.fromJson(e as Map<String, dynamic>)).toList();
|
||||
}
|
||||
}
|
||||
return [];
|
||||
} on DioException catch (e, st) {
|
||||
AppLogger.error('ReportsRepository: getEvolutions échoué', error: e, stackTrace: st);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Map<String, dynamic>> getStatistiquesMembres() async {
|
||||
try {
|
||||
final response = await _apiClient.get('$_membresBase/statistiques');
|
||||
if (response.statusCode == 200 && response.data is Map) {
|
||||
return response.data as Map<String, dynamic>;
|
||||
}
|
||||
return {};
|
||||
} on DioException catch (e, st) {
|
||||
AppLogger.error('ReportsRepository: getStatistiquesMembres échoué', error: e, stackTrace: st);
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Map<String, dynamic>> getStatistiquesCotisations(int annee) async {
|
||||
try {
|
||||
final response = await _apiClient.get(
|
||||
'$_cotisationsBase/statistiques',
|
||||
queryParameters: {'annee': annee},
|
||||
);
|
||||
if (response.statusCode == 200 && response.data is Map) {
|
||||
return response.data as Map<String, dynamic>;
|
||||
}
|
||||
return {};
|
||||
} on DioException catch (e, st) {
|
||||
AppLogger.error('ReportsRepository: getStatistiquesCotisations échoué', error: e, stackTrace: st);
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Map<String, dynamic>> getStatistiquesEvenements() async {
|
||||
try {
|
||||
final response = await _apiClient.get('$_evenementsBase/statistiques');
|
||||
if (response.statusCode == 200 && response.data is Map) {
|
||||
return response.data as Map<String, dynamic>;
|
||||
}
|
||||
return {};
|
||||
} on DioException catch (e, st) {
|
||||
AppLogger.error('ReportsRepository: getStatistiquesEvenements échoué', error: e, stackTrace: st);
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<Map<String, dynamic>>> getAvailableReports() async {
|
||||
try {
|
||||
final response = await _apiClient.get('$_analyticsBase/reports/available');
|
||||
if (response.statusCode == 200) {
|
||||
final data = response.data;
|
||||
if (data is List) {
|
||||
return data.map((e) => Map<String, dynamic>.from(e as Map)).toList();
|
||||
}
|
||||
}
|
||||
return [];
|
||||
} on DioException catch (e, st) {
|
||||
AppLogger.error('ReportsRepository: getAvailableReports échoué', error: e, stackTrace: st);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> generateReport(String type, {String? format}) async {
|
||||
try {
|
||||
final queryParams = <String, dynamic>{'type': type};
|
||||
if (format != null) queryParams['format'] = format;
|
||||
final response = await _apiClient.post(
|
||||
'$_analyticsBase/reports/generate',
|
||||
queryParameters: queryParams,
|
||||
);
|
||||
if (response.statusCode != 200 && response.statusCode != 201 && response.statusCode != 202) {
|
||||
throw Exception('Generate report failed: ${response.statusCode}');
|
||||
}
|
||||
} on DioException catch (e, st) {
|
||||
AppLogger.error('ReportsRepository: generateReport échoué', error: e, stackTrace: st);
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<String> exportReportPdf(String type) async {
|
||||
try {
|
||||
final response = await _apiClient.post(
|
||||
'$_analyticsBase/reports/export',
|
||||
queryParameters: {'type': type, 'format': 'pdf'},
|
||||
);
|
||||
if (response.statusCode == 200 && response.data is Map) {
|
||||
final data = response.data as Map<String, dynamic>;
|
||||
// Le backend retourne l'URL du fichier PDF généré
|
||||
return data['url'] as String? ?? data['fileUrl'] as String? ?? '';
|
||||
}
|
||||
throw Exception('Export PDF failed: ${response.statusCode}');
|
||||
} on DioException catch (e, st) {
|
||||
AppLogger.error('ReportsRepository: exportReportPdf échoué', error: e, stackTrace: st);
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<String> exportReportExcel(String type, {String format = 'excel'}) async {
|
||||
try {
|
||||
final response = await _apiClient.post(
|
||||
'$_analyticsBase/reports/export',
|
||||
queryParameters: {'type': type, 'format': format},
|
||||
);
|
||||
if (response.statusCode == 200 && response.data is Map) {
|
||||
final data = response.data as Map<String, dynamic>;
|
||||
// Le backend retourne l'URL du fichier Excel/CSV généré
|
||||
return data['url'] as String? ?? data['fileUrl'] as String? ?? '';
|
||||
}
|
||||
throw Exception('Export $format failed: ${response.statusCode}');
|
||||
} on DioException catch (e, st) {
|
||||
AppLogger.error('ReportsRepository: exportReportExcel échoué', error: e, stackTrace: st);
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> scheduleReport({String? cronExpression}) async {
|
||||
try {
|
||||
final response = await _apiClient.post(
|
||||
'$_analyticsBase/reports/schedule',
|
||||
data: cronExpression != null ? {'cronExpression': cronExpression} : null,
|
||||
);
|
||||
if (response.statusCode != 200 && response.statusCode != 201 && response.statusCode != 204) {
|
||||
throw Exception('Schedule report failed: ${response.statusCode}');
|
||||
}
|
||||
} on DioException catch (e, st) {
|
||||
AppLogger.error('ReportsRepository: scheduleReport échoué', error: e, stackTrace: st);
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<Map<String, dynamic>>> getScheduledReports() async {
|
||||
try {
|
||||
final response = await _apiClient.get('$_analyticsBase/reports/scheduled');
|
||||
if (response.statusCode == 200) {
|
||||
final data = response.data;
|
||||
if (data is List) {
|
||||
return data.map((e) => Map<String, dynamic>.from(e as Map)).toList();
|
||||
}
|
||||
}
|
||||
return [];
|
||||
} on DioException catch (e, st) {
|
||||
AppLogger.error('ReportsRepository: getScheduledReports échoué', error: e, stackTrace: st);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/// Interface du repository des rapports (Clean Architecture - Domain Layer)
|
||||
library reports_repository;
|
||||
|
||||
import '../../data/models/analytics_model.dart';
|
||||
|
||||
/// Interface du repository pour la gestion des rapports et analytics
|
||||
/// Contrat défini dans la couche Domain, implémenté dans la couche Data
|
||||
abstract class IReportsRepository {
|
||||
/// Récupère les métriques d'analyse
|
||||
Future<List<AnalyticsModel>> getMetriques(String typeMetrique, String periode);
|
||||
|
||||
/// Récupère la performance globale
|
||||
Future<Map<String, dynamic>> getPerformanceGlobale();
|
||||
|
||||
/// Récupère les évolutions d'une métrique
|
||||
Future<List<AnalyticsModel>> getEvolutions(String typeMetrique);
|
||||
|
||||
/// Récupère les statistiques des membres
|
||||
Future<Map<String, dynamic>> getStatistiquesMembres();
|
||||
|
||||
/// Récupère les statistiques des cotisations pour une année
|
||||
Future<Map<String, dynamic>> getStatistiquesCotisations(int annee);
|
||||
|
||||
/// Récupère les statistiques des événements
|
||||
Future<Map<String, dynamic>> getStatistiquesEvenements();
|
||||
|
||||
/// Liste les rapports disponibles (types de rapports générables)
|
||||
/// Endpoint: GET /api/v1/analytics/reports/available
|
||||
Future<List<Map<String, dynamic>>> getAvailableReports();
|
||||
|
||||
/// Génère un rapport (générique, sans format spécifique)
|
||||
/// Endpoint: POST /api/v1/analytics/reports/generate
|
||||
Future<void> generateReport(String type, {String? format});
|
||||
|
||||
/// Exporte un rapport au format PDF
|
||||
/// Wrapper de generateReport avec format='pdf'
|
||||
Future<String> exportReportPdf(String type);
|
||||
|
||||
/// Exporte un rapport au format Excel/CSV
|
||||
/// Wrapper de generateReport avec format='excel' ou 'csv'
|
||||
Future<String> exportReportExcel(String type, {String format = 'excel'});
|
||||
|
||||
/// Programme un rapport automatique (avec expression cron)
|
||||
/// Endpoint: POST /api/v1/analytics/reports/schedule
|
||||
Future<void> scheduleReport({String? cronExpression});
|
||||
|
||||
/// Récupère la liste des rapports programmés
|
||||
/// Endpoint: GET /api/v1/analytics/reports/scheduled
|
||||
Future<List<Map<String, dynamic>>> getScheduledReports();
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
/// Use Case: Exporter un rapport au format Excel/CSV
|
||||
library export_report_excel;
|
||||
|
||||
import 'package:injectable/injectable.dart';
|
||||
import '../repositories/reports_repository.dart';
|
||||
|
||||
/// Exporte un rapport au format Excel ou CSV
|
||||
@injectable
|
||||
class ExportReportExcel {
|
||||
final IReportsRepository _repository;
|
||||
|
||||
ExportReportExcel(this._repository);
|
||||
|
||||
/// Exécute le use case
|
||||
/// [type] : Type de rapport à exporter
|
||||
/// [format] : Format d'export ('excel' ou 'csv', défaut: 'excel')
|
||||
/// Retourne l'URL ou le chemin du fichier Excel/CSV généré
|
||||
/// Wrapper de generateReport avec format='excel' ou 'csv'
|
||||
Future<String> call(String type, {String format = 'excel'}) async {
|
||||
return _repository.exportReportExcel(type, format: format);
|
||||
}
|
||||
}
|
||||
21
lib/features/reports/domain/usecases/export_report_pdf.dart
Normal file
21
lib/features/reports/domain/usecases/export_report_pdf.dart
Normal file
@@ -0,0 +1,21 @@
|
||||
/// Use Case: Exporter un rapport au format PDF
|
||||
library export_report_pdf;
|
||||
|
||||
import 'package:injectable/injectable.dart';
|
||||
import '../repositories/reports_repository.dart';
|
||||
|
||||
/// Exporte un rapport au format PDF
|
||||
@injectable
|
||||
class ExportReportPdf {
|
||||
final IReportsRepository _repository;
|
||||
|
||||
ExportReportPdf(this._repository);
|
||||
|
||||
/// Exécute le use case
|
||||
/// [type] : Type de rapport à exporter
|
||||
/// Retourne l'URL ou le chemin du fichier PDF généré
|
||||
/// Wrapper de generateReport avec format='pdf'
|
||||
Future<String> call(String type) async {
|
||||
return _repository.exportReportPdf(type);
|
||||
}
|
||||
}
|
||||
21
lib/features/reports/domain/usecases/generate_report.dart
Normal file
21
lib/features/reports/domain/usecases/generate_report.dart
Normal file
@@ -0,0 +1,21 @@
|
||||
/// Use Case: Générer un rapport
|
||||
library generate_report;
|
||||
|
||||
import 'package:injectable/injectable.dart';
|
||||
import '../repositories/reports_repository.dart';
|
||||
|
||||
/// Génère un rapport pour un type donné
|
||||
@injectable
|
||||
class GenerateReport {
|
||||
final IReportsRepository _repository;
|
||||
|
||||
GenerateReport(this._repository);
|
||||
|
||||
/// Exécute le use case
|
||||
/// [type] : Type de rapport (membres, cotisations, evenements, etc.)
|
||||
/// [format] : Format optionnel (pdf, excel, csv)
|
||||
/// Endpoint: POST /api/v1/analytics/reports/generate
|
||||
Future<void> call(String type, {String? format}) async {
|
||||
return _repository.generateReport(type, format: format);
|
||||
}
|
||||
}
|
||||
21
lib/features/reports/domain/usecases/get_reports.dart
Normal file
21
lib/features/reports/domain/usecases/get_reports.dart
Normal file
@@ -0,0 +1,21 @@
|
||||
/// Use Case: Récupérer les rapports disponibles
|
||||
library get_reports;
|
||||
|
||||
import 'package:injectable/injectable.dart';
|
||||
import '../repositories/reports_repository.dart';
|
||||
|
||||
/// Récupère la liste des rapports disponibles (types générables)
|
||||
@injectable
|
||||
class GetReports {
|
||||
final IReportsRepository _repository;
|
||||
|
||||
GetReports(this._repository);
|
||||
|
||||
/// Exécute le use case
|
||||
/// Retourne une liste de rapports disponibles avec leurs métadonnées
|
||||
/// Exemple: [{ "type": "membres", "nom": "Rapport Membres", "description": "..." }]
|
||||
/// Endpoint: GET /api/v1/analytics/reports/available
|
||||
Future<List<Map<String, dynamic>>> call() async {
|
||||
return _repository.getAvailableReports();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/// Use Case: Récupérer les rapports programmés
|
||||
library get_scheduled_reports;
|
||||
|
||||
import 'package:injectable/injectable.dart';
|
||||
import '../repositories/reports_repository.dart';
|
||||
|
||||
/// Récupère la liste des rapports programmés pour l'utilisateur
|
||||
@injectable
|
||||
class GetScheduledReports {
|
||||
final IReportsRepository _repository;
|
||||
|
||||
GetScheduledReports(this._repository);
|
||||
|
||||
/// Exécute le use case
|
||||
/// Retourne une liste de rapports programmés avec leur configuration
|
||||
/// Exemple: [{ "id": "1", "type": "membres", "cronExpression": "0 0 1 * *", "active": true }]
|
||||
/// Endpoint: GET /api/v1/analytics/reports/scheduled
|
||||
Future<List<Map<String, dynamic>>> call() async {
|
||||
return _repository.getScheduledReports();
|
||||
}
|
||||
}
|
||||
22
lib/features/reports/domain/usecases/schedule_report.dart
Normal file
22
lib/features/reports/domain/usecases/schedule_report.dart
Normal file
@@ -0,0 +1,22 @@
|
||||
/// Use Case: Programmer un rapport automatique
|
||||
library schedule_report;
|
||||
|
||||
import 'package:injectable/injectable.dart';
|
||||
import '../repositories/reports_repository.dart';
|
||||
|
||||
/// Programme un rapport pour génération automatique récurrente
|
||||
@injectable
|
||||
class ScheduleReport {
|
||||
final IReportsRepository _repository;
|
||||
|
||||
ScheduleReport(this._repository);
|
||||
|
||||
/// Exécute le use case
|
||||
/// [cronExpression] : Expression cron optionnelle pour la récurrence
|
||||
/// Exemples: "0 0 1 * *" (1er de chaque mois à minuit)
|
||||
/// "0 9 * * 1" (tous les lundis à 9h)
|
||||
/// Endpoint: POST /api/v1/analytics/reports/schedule
|
||||
Future<void> call({String? cronExpression}) async {
|
||||
return _repository.scheduleReport(cronExpression: cronExpression);
|
||||
}
|
||||
}
|
||||
96
lib/features/reports/presentation/bloc/reports_bloc.dart
Normal file
96
lib/features/reports/presentation/bloc/reports_bloc.dart
Normal file
@@ -0,0 +1,96 @@
|
||||
/// BLoC pour la gestion des rapports (Clean Architecture)
|
||||
library reports_bloc;
|
||||
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
import '../../domain/usecases/get_reports.dart';
|
||||
import '../../domain/usecases/generate_report.dart';
|
||||
import '../../domain/usecases/export_report_pdf.dart';
|
||||
import '../../domain/usecases/export_report_excel.dart';
|
||||
import '../../domain/usecases/schedule_report.dart';
|
||||
import '../../domain/usecases/get_scheduled_reports.dart';
|
||||
import '../../domain/repositories/reports_repository.dart';
|
||||
|
||||
part 'reports_event.dart';
|
||||
part 'reports_state.dart';
|
||||
|
||||
/// BLoC pour la gestion des rapports (Clean Architecture)
|
||||
@injectable
|
||||
class ReportsBloc extends Bloc<ReportsEvent, ReportsState> {
|
||||
final GetReports _getReports;
|
||||
final GenerateReport _generateReport;
|
||||
final ExportReportPdf _exportReportPdf;
|
||||
final ExportReportExcel _exportReportExcel;
|
||||
final ScheduleReport _scheduleReport;
|
||||
final GetScheduledReports _getScheduledReports;
|
||||
final IReportsRepository _repository; // Pour méthodes non-couvertes (statistics, analytics)
|
||||
|
||||
ReportsBloc(
|
||||
this._getReports,
|
||||
this._generateReport,
|
||||
this._exportReportPdf,
|
||||
this._exportReportExcel,
|
||||
this._scheduleReport,
|
||||
this._getScheduledReports,
|
||||
this._repository,
|
||||
) : super(const ReportsInitial()) {
|
||||
on<LoadDashboardReports>(_onLoadDashboard);
|
||||
on<ScheduleReportRequested>(_onScheduleReport);
|
||||
on<GenerateReportRequested>(_onGenerateReport);
|
||||
}
|
||||
|
||||
/// Charge le tableau de bord des rapports
|
||||
Future<void> _onLoadDashboard(
|
||||
LoadDashboardReports event,
|
||||
Emitter<ReportsState> emit,
|
||||
) async {
|
||||
try {
|
||||
emit(const ReportsLoading());
|
||||
final anneeActuelle = DateTime.now().year;
|
||||
|
||||
// Appels parallèles pour les performances
|
||||
final results = await Future.wait([
|
||||
_repository.getPerformanceGlobale(),
|
||||
_repository.getStatistiquesMembres(),
|
||||
_repository.getStatistiquesCotisations(anneeActuelle),
|
||||
_repository.getStatistiquesEvenements(),
|
||||
]);
|
||||
|
||||
emit(ReportsDashboardLoaded(
|
||||
performance: results[0],
|
||||
statsMembres: results[1],
|
||||
statsCotisations: results[2],
|
||||
statsEvenements: results[3],
|
||||
));
|
||||
} catch (e) {
|
||||
emit(ReportsError('Erreur lors du chargement des rapports : $e'));
|
||||
}
|
||||
}
|
||||
|
||||
/// Programme un rapport automatique
|
||||
Future<void> _onScheduleReport(
|
||||
ScheduleReportRequested event,
|
||||
Emitter<ReportsState> emit,
|
||||
) async {
|
||||
try {
|
||||
await _scheduleReport(cronExpression: event.cronExpression);
|
||||
emit(const ReportScheduled());
|
||||
} catch (e) {
|
||||
emit(ReportsError('Impossible de programmer le rapport : $e'));
|
||||
}
|
||||
}
|
||||
|
||||
/// Génère un rapport
|
||||
Future<void> _onGenerateReport(
|
||||
GenerateReportRequested event,
|
||||
Emitter<ReportsState> emit,
|
||||
) async {
|
||||
try {
|
||||
await _generateReport(event.type, format: event.format);
|
||||
emit(ReportGenerated(event.type));
|
||||
} catch (e) {
|
||||
emit(ReportsError('Impossible de générer le rapport : $e'));
|
||||
}
|
||||
}
|
||||
}
|
||||
45
lib/features/reports/presentation/bloc/reports_event.dart
Normal file
45
lib/features/reports/presentation/bloc/reports_event.dart
Normal file
@@ -0,0 +1,45 @@
|
||||
part of 'reports_bloc.dart';
|
||||
|
||||
abstract class ReportsEvent extends Equatable {
|
||||
const ReportsEvent();
|
||||
|
||||
@override
|
||||
List<Object?> get props => [];
|
||||
}
|
||||
|
||||
class LoadDashboardReports extends ReportsEvent {
|
||||
const LoadDashboardReports();
|
||||
}
|
||||
|
||||
class LoadMembresStats extends ReportsEvent {
|
||||
const LoadMembresStats();
|
||||
}
|
||||
|
||||
class LoadCotisationsStats extends ReportsEvent {
|
||||
final int annee;
|
||||
const LoadCotisationsStats({required this.annee});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [annee];
|
||||
}
|
||||
|
||||
class LoadEvenementsStats extends ReportsEvent {
|
||||
const LoadEvenementsStats();
|
||||
}
|
||||
|
||||
class ScheduleReportRequested extends ReportsEvent {
|
||||
final String? cronExpression;
|
||||
const ScheduleReportRequested({this.cronExpression});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [cronExpression];
|
||||
}
|
||||
|
||||
class GenerateReportRequested extends ReportsEvent {
|
||||
final String type;
|
||||
final String? format;
|
||||
const GenerateReportRequested(this.type, {this.format});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [type, format];
|
||||
}
|
||||
58
lib/features/reports/presentation/bloc/reports_state.dart
Normal file
58
lib/features/reports/presentation/bloc/reports_state.dart
Normal file
@@ -0,0 +1,58 @@
|
||||
part of 'reports_bloc.dart';
|
||||
|
||||
abstract class ReportsState extends Equatable {
|
||||
const ReportsState();
|
||||
|
||||
@override
|
||||
List<Object?> get props => [];
|
||||
}
|
||||
|
||||
class ReportsInitial extends ReportsState {
|
||||
const ReportsInitial();
|
||||
}
|
||||
|
||||
class ReportsLoading extends ReportsState {
|
||||
const ReportsLoading();
|
||||
}
|
||||
|
||||
class ReportsDashboardLoaded extends ReportsState {
|
||||
final Map<String, dynamic> performance;
|
||||
final Map<String, dynamic> statsMembres;
|
||||
final Map<String, dynamic> statsCotisations;
|
||||
final Map<String, dynamic> statsEvenements;
|
||||
|
||||
const ReportsDashboardLoaded({
|
||||
required this.performance,
|
||||
required this.statsMembres,
|
||||
required this.statsCotisations,
|
||||
required this.statsEvenements,
|
||||
});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [performance, statsMembres, statsCotisations, statsEvenements];
|
||||
}
|
||||
|
||||
class ReportsError extends ReportsState {
|
||||
final String message;
|
||||
const ReportsError(this.message);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [message];
|
||||
}
|
||||
|
||||
class ReportScheduled extends ReportsState {
|
||||
final String message;
|
||||
const ReportScheduled([this.message = 'Programmation configurée. Vous recevrez le rapport par email.']);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [message];
|
||||
}
|
||||
|
||||
class ReportGenerated extends ReportsState {
|
||||
final String type;
|
||||
final String message;
|
||||
const ReportGenerated(this.type, [this.message = 'Génération lancée. Vous recevrez le rapport par email.']);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [type, message];
|
||||
}
|
||||
778
lib/features/reports/presentation/pages/reports_page.dart
Normal file
778
lib/features/reports/presentation/pages/reports_page.dart
Normal file
@@ -0,0 +1,778 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import '../bloc/reports_bloc.dart';
|
||||
import '../../../../shared/design_system/unionflow_design_system.dart';
|
||||
import '../../../../shared/widgets/core_card.dart';
|
||||
|
||||
/// Page Rapports & Analytics - UnionFlow Mobile
|
||||
///
|
||||
/// Page complète de génération et consultation des rapports avec
|
||||
/// analytics avancés, graphiques et export de données.
|
||||
class ReportsPage extends StatefulWidget {
|
||||
const ReportsPage({super.key});
|
||||
|
||||
@override
|
||||
State<ReportsPage> createState() => _ReportsPageState();
|
||||
}
|
||||
|
||||
class _ReportsPageState extends State<ReportsPage>
|
||||
with TickerProviderStateMixin {
|
||||
late TabController _tabController;
|
||||
|
||||
String _selectedPeriod = 'Dernier mois';
|
||||
String _selectedFormat = 'PDF';
|
||||
|
||||
final List<String> _periods = ['Dernière semaine', 'Dernier mois', 'Dernier trimestre', 'Dernière année'];
|
||||
final List<String> _formats = ['PDF', 'Excel', 'CSV', 'JSON'];
|
||||
|
||||
// Données live du backend
|
||||
Map<String, dynamic> _statsMembres = {};
|
||||
Map<String, dynamic> _statsCotisations = {};
|
||||
Map<String, dynamic> _statsEvenements = {};
|
||||
Map<String, dynamic> _performance = {};
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_tabController = TabController(length: 4, vsync: this);
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
context.read<ReportsBloc>().add(const LoadDashboardReports());
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_tabController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocConsumer<ReportsBloc, ReportsState>(
|
||||
listener: (context, state) {
|
||||
if (state is ReportsDashboardLoaded) {
|
||||
setState(() {
|
||||
_performance = state.performance;
|
||||
_statsMembres = state.statsMembres;
|
||||
_statsCotisations = state.statsCotisations;
|
||||
_statsEvenements = state.statsEvenements;
|
||||
});
|
||||
}
|
||||
if (state is ReportsError) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(state.message), backgroundColor: Colors.orange),
|
||||
);
|
||||
}
|
||||
if (state is ReportScheduled) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(state.message), backgroundColor: const Color(0xFF00B894), behavior: SnackBarBehavior.floating),
|
||||
);
|
||||
}
|
||||
if (state is ReportGenerated) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(state.message), backgroundColor: const Color(0xFF00B894), behavior: SnackBarBehavior.floating),
|
||||
);
|
||||
}
|
||||
},
|
||||
builder: (context, state) {
|
||||
return Scaffold(
|
||||
backgroundColor: AppColors.darkBackground,
|
||||
body: Column(
|
||||
children: [
|
||||
_buildHeader(),
|
||||
_buildTabBar(),
|
||||
if (state is ReportsLoading)
|
||||
const LinearProgressIndicator(
|
||||
minHeight: 2,
|
||||
backgroundColor: Colors.transparent,
|
||||
valueColor: AlwaysStoppedAnimation<Color>(AppColors.primaryGreen),
|
||||
),
|
||||
Expanded(
|
||||
child: TabBarView(
|
||||
controller: _tabController,
|
||||
children: [
|
||||
_buildOverviewTab(),
|
||||
_buildMembersTab(),
|
||||
_buildOrganizationsTab(),
|
||||
_buildEventsTab(),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildHeader() {
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
padding: EdgeInsets.only(
|
||||
top: MediaQuery.of(context).padding.top + 20,
|
||||
bottom: 30,
|
||||
left: 20,
|
||||
right: 20,
|
||||
),
|
||||
decoration: const BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: [
|
||||
AppColors.primaryGreen,
|
||||
AppColors.brandGreen,
|
||||
],
|
||||
),
|
||||
borderRadius: BorderRadius.only(
|
||||
bottomLeft: Radius.circular(32),
|
||||
bottomRight: Radius.circular(32),
|
||||
),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'UnionFlow Analytics'.toUpperCase(),
|
||||
style: AppTypography.subtitleSmall.copyWith(
|
||||
color: Colors.white.withOpacity(0.8),
|
||||
fontWeight: FontWeight.bold,
|
||||
letterSpacing: 1.2,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
const Text(
|
||||
'Rapports & Insights',
|
||||
style: AppTypography.headerSmall,
|
||||
),
|
||||
],
|
||||
),
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withOpacity(0.2),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: IconButton(
|
||||
onPressed: () => _showExportDialog(),
|
||||
icon: const Icon(Icons.file_download_outlined, color: Colors.white),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: _buildHeaderStat(
|
||||
'Membres',
|
||||
_statsMembres['total']?.toString() ?? '...',
|
||||
Icons.people_outline,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: _buildHeaderStat(
|
||||
'Organisations',
|
||||
_statsMembres['totalOrganisations']?.toString() ?? '...',
|
||||
Icons.business_outlined,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: _buildHeaderStat(
|
||||
'Événements',
|
||||
_statsEvenements['total']?.toString() ?? '...',
|
||||
Icons.event_outlined,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildHeaderStat(String label, String value, IconData icon) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 8),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withOpacity(0.15),
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(color: Colors.white.withOpacity(0.2)),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
Icon(icon, color: Colors.white, size: 18),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
value,
|
||||
style: AppTypography.headerSmall.copyWith(fontSize: 18),
|
||||
),
|
||||
Text(
|
||||
label.toUpperCase(),
|
||||
style: AppTypography.subtitleSmall.copyWith(
|
||||
color: Colors.white.withOpacity(0.7),
|
||||
fontSize: 8,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTabBar() {
|
||||
return Container(
|
||||
margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.darkBackground,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(color: AppColors.lightBorder.withOpacity(0.1)),
|
||||
),
|
||||
child: TabBar(
|
||||
controller: _tabController,
|
||||
labelColor: AppColors.primaryGreen,
|
||||
unselectedLabelColor: AppColors.textSecondaryLight,
|
||||
indicatorColor: AppColors.primaryGreen,
|
||||
indicatorSize: TabBarIndicatorSize.label,
|
||||
dividerColor: Colors.transparent,
|
||||
labelStyle: AppTypography.badgeText.copyWith(fontWeight: FontWeight.bold),
|
||||
tabs: const [
|
||||
Tab(text: 'GLOBAL'),
|
||||
Tab(text: 'MEMBRES'),
|
||||
Tab(text: 'ORGS'),
|
||||
Tab(text: 'EVENTS'),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildOverviewTab() {
|
||||
return ListView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
children: [
|
||||
_buildKPICards(),
|
||||
const SizedBox(height: 24),
|
||||
_buildActivityChart(),
|
||||
const SizedBox(height: 24),
|
||||
_buildQuickReports(),
|
||||
const SizedBox(height: 32),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildKPICards() {
|
||||
final totalMembres = _statsMembres['total']?.toString() ?? '--';
|
||||
final membresActifs = _statsMembres['actifs']?.toString() ?? '--';
|
||||
final totalCotisations = _statsCotisations['total']?.toString() ?? '--';
|
||||
final totalEvenements = _statsEvenements['total']?.toString() ?? '--';
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Expanded(child: _buildKPICard('Total Membres', totalMembres, Icons.people_outline, AppColors.info)),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(child: _buildKPICard('Membres Actifs', membresActifs, Icons.how_to_reg_outlined, AppColors.success)),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(child: _buildKPICard('Cotisations', totalCotisations, Icons.payments_outlined, AppColors.brandGreen)),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(child: _buildKPICard('Événements', totalEvenements, Icons.event_available_outlined, AppColors.warning)),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildKPICard(String title, String value, IconData icon, Color color) {
|
||||
return CoreCard(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Column(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(
|
||||
color: color.withOpacity(0.1),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: Icon(icon, color: color, size: 24),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
value,
|
||||
style: AppTypography.headerSmall.copyWith(color: color, fontWeight: FontWeight.bold),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
title.toUpperCase(),
|
||||
style: AppTypography.subtitleSmall.copyWith(
|
||||
fontSize: 9,
|
||||
fontWeight: FontWeight.bold,
|
||||
letterSpacing: 0.5,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildActivityChart() {
|
||||
return CoreCard(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
const Icon(Icons.analytics_outlined, color: AppColors.primaryGreen, size: 20),
|
||||
const SizedBox(width: 12),
|
||||
Text(
|
||||
'Évolution de l\'Activité'.toUpperCase(),
|
||||
style: AppTypography.subtitleSmall.copyWith(fontWeight: FontWeight.bold, letterSpacing: 1.1),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
Container(
|
||||
height: 180,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.lightBorder.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
child: const Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(Icons.auto_graph_outlined, color: AppColors.textSecondaryLight, size: 40),
|
||||
SizedBox(height: 12),
|
||||
Text(
|
||||
'Visualisation graphique en préparation',
|
||||
style: AppTypography.subtitleSmall,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildQuickReports() {
|
||||
return CoreCard(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
const Icon(Icons.flash_on_outlined, color: AppColors.warning, size: 20),
|
||||
const SizedBox(width: 12),
|
||||
Text(
|
||||
'Rapports Favoris'.toUpperCase(),
|
||||
style: AppTypography.subtitleSmall.copyWith(fontWeight: FontWeight.bold, letterSpacing: 1.1),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
_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')),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildQuickReportItem(String title, String subtitle, IconData icon, VoidCallback onTap) {
|
||||
return Container(
|
||||
margin: const EdgeInsets.only(bottom: 12),
|
||||
child: InkWell(
|
||||
onTap: onTap,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.lightBorder.withOpacity(0.05),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(color: AppColors.lightBorder.withOpacity(0.1)),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(8),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.primaryGreen.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Icon(icon, color: AppColors.primaryGreen, size: 20),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(title, style: AppTypography.actionText),
|
||||
const SizedBox(height: 2),
|
||||
Text(subtitle, style: AppTypography.subtitleSmall.copyWith(fontSize: 10)),
|
||||
],
|
||||
),
|
||||
),
|
||||
const Icon(Icons.chevron_right_outlined, color: AppColors.textSecondaryLight, size: 20),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Onglet membres
|
||||
Widget _buildMembersTab() {
|
||||
return SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(12),
|
||||
child: Column(
|
||||
children: [
|
||||
const SizedBox(height: 16),
|
||||
_buildMembersStats(),
|
||||
const SizedBox(height: 16),
|
||||
_buildMembersReports(),
|
||||
const SizedBox(height: 80),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildMembersStats() {
|
||||
final total = _statsMembres['total']?.toString() ?? '--';
|
||||
final nouveaux = _statsMembres['nouveaux30j']?.toString() ?? '--';
|
||||
final actifs = _statsMembres['actifs7j']?.toString() ?? '--';
|
||||
|
||||
return CoreCard(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
const Icon(Icons.people_alt_outlined, color: AppColors.info, size: 20),
|
||||
const SizedBox(width: 12),
|
||||
Text(
|
||||
'Indicateurs Membres'.toUpperCase(),
|
||||
style: AppTypography.subtitleSmall.copyWith(fontWeight: FontWeight.bold, letterSpacing: 1.1),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(child: _buildStatItem('Total', total)),
|
||||
Container(width: 1, height: 30, color: AppColors.lightBorder.withOpacity(0.2)),
|
||||
Expanded(child: _buildStatItem('Nouveaux', nouveaux)),
|
||||
Container(width: 1, height: 30, color: AppColors.lightBorder.withOpacity(0.2)),
|
||||
Expanded(child: _buildStatItem('Actifs %', actifs)),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildMembersReports() {
|
||||
return CoreCard(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
const Icon(Icons.assignment_ind_outlined, color: AppColors.info, size: 20),
|
||||
const SizedBox(width: 12),
|
||||
Text(
|
||||
'Rapports Membres'.toUpperCase(),
|
||||
style: AppTypography.subtitleSmall.copyWith(fontWeight: FontWeight.bold, letterSpacing: 1.1),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_buildReportItem('Liste complète des membres', 'Export avec toutes les informations', Icons.list_alt_outlined),
|
||||
_buildReportItem('Analyse d\'engagement', 'Participation et activité des membres', Icons.trending_up_outlined),
|
||||
_buildReportItem('Segmentation démographique', 'Répartition par âge, région, etc.', Icons.pie_chart_outline),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Onglet organisations
|
||||
Widget _buildOrganizationsTab() {
|
||||
return SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(12),
|
||||
child: Column(
|
||||
children: [
|
||||
const SizedBox(height: 16),
|
||||
_buildOrganizationsStats(),
|
||||
const SizedBox(height: 16),
|
||||
_buildOrganizationsReports(),
|
||||
const SizedBox(height: 80),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildOrganizationsStats() {
|
||||
final total = _statsMembres['totalOrganisations']?.toString() ?? '--';
|
||||
final actives = _statsMembres['organisationsActives']?.toString() ?? '--';
|
||||
final moy = _statsMembres['membresParOrganisation']?.toString() ?? '--';
|
||||
|
||||
return CoreCard(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
const Icon(Icons.business_center_outlined, color: AppColors.primaryGreen, size: 20),
|
||||
const SizedBox(width: 12),
|
||||
Text(
|
||||
'Indicateurs Organisations'.toUpperCase(),
|
||||
style: AppTypography.subtitleSmall.copyWith(fontWeight: FontWeight.bold, letterSpacing: 1.1),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(child: _buildStatItem('Total', total)),
|
||||
Container(width: 1, height: 30, color: AppColors.lightBorder.withOpacity(0.2)),
|
||||
Expanded(child: _buildStatItem('Actives', actives)),
|
||||
Container(width: 1, height: 30, color: AppColors.lightBorder.withOpacity(0.2)),
|
||||
Expanded(child: _buildStatItem('Membres moy.', moy)),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildOrganizationsReports() {
|
||||
return CoreCard(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
const Icon(Icons.folder_shared_outlined, color: AppColors.primaryGreen, size: 20),
|
||||
const SizedBox(width: 12),
|
||||
Text(
|
||||
'Rapports Structures'.toUpperCase(),
|
||||
style: AppTypography.subtitleSmall.copyWith(fontWeight: FontWeight.bold, letterSpacing: 1.1),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_buildReportItem('Annuaire des organisations', 'Liste complète avec contacts', Icons.contact_phone_outlined),
|
||||
_buildReportItem('Performance par organisation', 'Activité et engagement', Icons.bar_chart_outlined),
|
||||
_buildReportItem('Analyse de croissance', 'Évolution du nombre de membres', Icons.trending_up_outlined),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Onglet événements
|
||||
Widget _buildEventsTab() {
|
||||
return SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(12),
|
||||
child: Column(
|
||||
children: [
|
||||
const SizedBox(height: 16),
|
||||
_buildEventsStats(),
|
||||
const SizedBox(height: 16),
|
||||
_buildEventsReports(),
|
||||
const SizedBox(height: 80),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildEventsStats() {
|
||||
final total = _statsEvenements['total']?.toString() ?? '--';
|
||||
final venir = _statsEvenements['aVenir']?.toString() ?? '--';
|
||||
final participation = _statsEvenements['participationMoyenne']?.toString() ?? '--';
|
||||
|
||||
return CoreCard(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
const Icon(Icons.event_note_outlined, color: AppColors.warning, size: 20),
|
||||
const SizedBox(width: 12),
|
||||
Text(
|
||||
'Indicateurs Événements'.toUpperCase(),
|
||||
style: AppTypography.subtitleSmall.copyWith(fontWeight: FontWeight.bold, letterSpacing: 1.1),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(child: _buildStatItem('Total', total)),
|
||||
Container(width: 1, height: 30, color: AppColors.lightBorder.withOpacity(0.2)),
|
||||
Expanded(child: _buildStatItem('À Venir', venir)),
|
||||
Container(width: 1, height: 30, color: AppColors.lightBorder.withOpacity(0.2)),
|
||||
Expanded(child: _buildStatItem('Part. moyenne', participation)),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildEventsReports() {
|
||||
return CoreCard(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
const Icon(Icons.history_edu_outlined, color: AppColors.warning, size: 20),
|
||||
const SizedBox(width: 12),
|
||||
Text(
|
||||
'Rapports Logistique'.toUpperCase(),
|
||||
style: AppTypography.subtitleSmall.copyWith(fontWeight: FontWeight.bold, letterSpacing: 1.1),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_buildReportItem('Calendrier des événements', 'Planning complet avec détails', Icons.calendar_today_outlined),
|
||||
_buildReportItem('Analyse de participation', 'Taux de participation et feedback', Icons.people_outline),
|
||||
_buildReportItem('ROI des événements', 'Retour sur investissement financier', Icons.analytics_outlined),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Composants communs
|
||||
Widget _buildStatItem(String label, String value) {
|
||||
return Column(
|
||||
children: [
|
||||
Text(
|
||||
value,
|
||||
style: AppTypography.headerSmall.copyWith(color: AppColors.primaryGreen, fontWeight: FontWeight.bold),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
label.toUpperCase(),
|
||||
style: AppTypography.subtitleSmall.copyWith(fontSize: 8, fontWeight: FontWeight.bold),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildReportItem(String title, String subtitle, IconData icon) {
|
||||
return Container(
|
||||
margin: const EdgeInsets.only(bottom: 12),
|
||||
child: InkWell(
|
||||
onTap: () => _generateReport(title.toLowerCase().replaceAll(' ', '_')),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.lightBorder.withOpacity(0.05),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(color: AppColors.lightBorder.withOpacity(0.1)),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(8),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.primaryGreen.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Icon(icon, color: AppColors.primaryGreen, size: 20),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(title, style: AppTypography.actionText),
|
||||
const SizedBox(height: 2),
|
||||
Text(subtitle, style: AppTypography.subtitleSmall.copyWith(fontSize: 10)),
|
||||
],
|
||||
),
|
||||
),
|
||||
const Icon(Icons.file_download_outlined, color: AppColors.textSecondaryLight, size: 20),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Méthodes d'action
|
||||
void _showExportDialog() {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('Exporter rapport'),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
DropdownButtonFormField<String>(
|
||||
value: _selectedPeriod,
|
||||
decoration: const InputDecoration(labelText: 'Période'),
|
||||
items: _periods.map((period) => DropdownMenuItem(value: period, child: Text(period))).toList(),
|
||||
onChanged: (value) => setState(() => _selectedPeriod = value!),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
DropdownButtonFormField<String>(
|
||||
value: _selectedFormat,
|
||||
decoration: const InputDecoration(labelText: 'Format'),
|
||||
items: _formats.map((format) => DropdownMenuItem(value: format, child: Text(format))).toList(),
|
||||
onChanged: (value) => setState(() => _selectedFormat = value!),
|
||||
),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
TextButton(onPressed: () => Navigator.of(context).pop(), child: const Text('Annuler')),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
context.read<ReportsBloc>().add(GenerateReportRequested('export', format: _selectedFormat));
|
||||
},
|
||||
style: ElevatedButton.styleFrom(backgroundColor: const Color(0xFF6C5CE7), foregroundColor: Colors.white),
|
||||
child: const Text('Exporter'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _scheduleReport() {
|
||||
context.read<ReportsBloc>().add(const ScheduleReportRequested());
|
||||
}
|
||||
|
||||
void _generateReport(String type) {
|
||||
context.read<ReportsBloc>().add(GenerateReportRequested(type));
|
||||
}
|
||||
|
||||
void _showSuccessSnackBar(String message) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(message), backgroundColor: const Color(0xFF00B894), behavior: SnackBarBehavior.floating),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
library reports_page_wrapper;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import '../../../../core/di/injection_container.dart';
|
||||
import '../bloc/reports_bloc.dart';
|
||||
import 'reports_page.dart';
|
||||
|
||||
/// Wrapper qui fournit le ReportsBloc à la ReportsPage
|
||||
class ReportsPageWrapper extends StatelessWidget {
|
||||
const ReportsPageWrapper({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider<ReportsBloc>(
|
||||
create: (_) => sl<ReportsBloc>(),
|
||||
child: const ReportsPage(),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user