Alignement design systeme OK
This commit is contained in:
@@ -0,0 +1,579 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
import '../../../../core/models/membre_search_criteria.dart';
|
||||
import '../../../../core/models/membre_search_result.dart';
|
||||
import '../../../dashboard/presentation/widgets/dashboard_activity_tile.dart';
|
||||
import '../widgets/membre_search_form.dart';
|
||||
import '../widgets/membre_search_results.dart';
|
||||
import '../widgets/search_statistics_card.dart';
|
||||
|
||||
/// Page de recherche avancée des membres
|
||||
/// Interface complète pour la recherche sophistiquée avec filtres multiples
|
||||
class AdvancedSearchPage extends StatefulWidget {
|
||||
const AdvancedSearchPage({super.key});
|
||||
|
||||
@override
|
||||
State<AdvancedSearchPage> createState() => _AdvancedSearchPageState();
|
||||
}
|
||||
|
||||
class _AdvancedSearchPageState extends State<AdvancedSearchPage>
|
||||
with TickerProviderStateMixin {
|
||||
late TabController _tabController;
|
||||
MembreSearchCriteria _currentCriteria = MembreSearchCriteria.empty;
|
||||
MembreSearchResult? _currentResult;
|
||||
bool _isSearching = false;
|
||||
String? _errorMessage;
|
||||
|
||||
// Contrôleurs pour les champs de recherche
|
||||
final _queryController = TextEditingController();
|
||||
final _nomController = TextEditingController();
|
||||
final _prenomController = TextEditingController();
|
||||
final _emailController = TextEditingController();
|
||||
final _telephoneController = TextEditingController();
|
||||
final _regionController = TextEditingController();
|
||||
final _villeController = TextEditingController();
|
||||
final _professionController = TextEditingController();
|
||||
|
||||
// Valeurs pour les filtres
|
||||
String? _selectedStatut;
|
||||
List<String> _selectedRoles = [];
|
||||
List<String> _selectedOrganisations = [];
|
||||
RangeValues _ageRange = const RangeValues(18, 65);
|
||||
DateTimeRange? _adhesionDateRange;
|
||||
bool _includeInactifs = false;
|
||||
bool _membreBureau = false;
|
||||
bool _responsable = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_tabController = TabController(length: 3, vsync: this);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_tabController.dispose();
|
||||
_queryController.dispose();
|
||||
_nomController.dispose();
|
||||
_prenomController.dispose();
|
||||
_emailController.dispose();
|
||||
_telephoneController.dispose();
|
||||
_regionController.dispose();
|
||||
_villeController.dispose();
|
||||
_professionController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Recherche Avancée'),
|
||||
backgroundColor: Theme.of(context).primaryColor,
|
||||
foregroundColor: Colors.white,
|
||||
elevation: 0,
|
||||
bottom: TabBar(
|
||||
controller: _tabController,
|
||||
indicatorColor: Colors.white,
|
||||
labelColor: Colors.white,
|
||||
unselectedLabelColor: Colors.white70,
|
||||
tabs: const [
|
||||
Tab(icon: Icon(Icons.search), text: 'Critères'),
|
||||
Tab(icon: Icon(Icons.list), text: 'Résultats'),
|
||||
Tab(icon: Icon(Icons.analytics), text: 'Statistiques'),
|
||||
],
|
||||
),
|
||||
),
|
||||
body: TabBarView(
|
||||
controller: _tabController,
|
||||
children: [
|
||||
_buildSearchCriteriaTab(),
|
||||
_buildSearchResultsTab(),
|
||||
_buildStatisticsTab(),
|
||||
],
|
||||
),
|
||||
floatingActionButton: _buildSearchFab(),
|
||||
);
|
||||
}
|
||||
|
||||
/// Onglet des critères de recherche
|
||||
Widget _buildSearchCriteriaTab() {
|
||||
return SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// Recherche rapide
|
||||
_buildQuickSearchSection(),
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// Critères détaillés
|
||||
_buildDetailedCriteriaSection(),
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// Filtres avancés
|
||||
_buildAdvancedFiltersSection(),
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// Boutons d'action
|
||||
_buildActionButtons(),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Section de recherche rapide
|
||||
Widget _buildQuickSearchSection() {
|
||||
return Card(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Icon(Icons.flash_on, color: Theme.of(context).primaryColor),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
'Recherche Rapide',
|
||||
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
TextField(
|
||||
controller: _queryController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Rechercher un membre',
|
||||
hintText: 'Nom, prénom ou email...',
|
||||
prefixIcon: Icon(Icons.search),
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
onSubmitted: (_) => _performQuickSearch(),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Wrap(
|
||||
spacing: 8,
|
||||
children: [
|
||||
_buildQuickFilterChip('Membres actifs', () {
|
||||
_selectedStatut = 'ACTIF';
|
||||
_includeInactifs = false;
|
||||
}),
|
||||
_buildQuickFilterChip('Membres bureau', () {
|
||||
_membreBureau = true;
|
||||
_selectedStatut = 'ACTIF';
|
||||
}),
|
||||
_buildQuickFilterChip('Responsables', () {
|
||||
_responsable = true;
|
||||
_selectedStatut = 'ACTIF';
|
||||
}),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Section des critères détaillés
|
||||
Widget _buildDetailedCriteriaSection() {
|
||||
return Card(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Icon(Icons.tune, color: Theme.of(context).primaryColor),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
'Critères Détaillés',
|
||||
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: _nomController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Nom',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: _prenomController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Prénom',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
TextField(
|
||||
controller: _emailController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Email',
|
||||
hintText: 'exemple@unionflow.com',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: _telephoneController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Téléphone',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: DropdownButtonFormField<String>(
|
||||
value: _selectedStatut,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Statut',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
items: const [
|
||||
DropdownMenuItem(value: null, child: Text('Tous')),
|
||||
DropdownMenuItem(value: 'ACTIF', child: Text('Actif')),
|
||||
DropdownMenuItem(value: 'INACTIF', child: Text('Inactif')),
|
||||
DropdownMenuItem(value: 'SUSPENDU', child: Text('Suspendu')),
|
||||
DropdownMenuItem(value: 'RADIE', child: Text('Radié')),
|
||||
],
|
||||
onChanged: (value) => setState(() => _selectedStatut = value),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Section des filtres avancés
|
||||
Widget _buildAdvancedFiltersSection() {
|
||||
return Card(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Icon(Icons.filter_alt, color: Theme.of(context).primaryColor),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
'Filtres Avancés',
|
||||
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// Tranche d'âge
|
||||
Text('Tranche d\'âge: ${_ageRange.start.round()}-${_ageRange.end.round()} ans'),
|
||||
RangeSlider(
|
||||
values: _ageRange,
|
||||
min: 18,
|
||||
max: 80,
|
||||
divisions: 62,
|
||||
labels: RangeLabels(
|
||||
'${_ageRange.start.round()}',
|
||||
'${_ageRange.end.round()}',
|
||||
),
|
||||
onChanged: (values) => setState(() => _ageRange = values),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// Options booléennes
|
||||
CheckboxListTile(
|
||||
title: const Text('Inclure les membres inactifs'),
|
||||
value: _includeInactifs,
|
||||
onChanged: (value) => setState(() => _includeInactifs = value ?? false),
|
||||
),
|
||||
CheckboxListTile(
|
||||
title: const Text('Membres du bureau uniquement'),
|
||||
value: _membreBureau,
|
||||
onChanged: (value) => setState(() => _membreBureau = value ?? false),
|
||||
),
|
||||
CheckboxListTile(
|
||||
title: const Text('Responsables uniquement'),
|
||||
value: _responsable,
|
||||
onChanged: (value) => setState(() => _responsable = value ?? false),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Boutons d'action
|
||||
Widget _buildActionButtons() {
|
||||
return Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: OutlinedButton.icon(
|
||||
onPressed: _clearCriteria,
|
||||
icon: const Icon(Icons.clear),
|
||||
label: const Text('Effacer'),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: ElevatedButton.icon(
|
||||
onPressed: _isSearching ? null : _performAdvancedSearch,
|
||||
icon: _isSearching
|
||||
? const SizedBox(
|
||||
width: 16,
|
||||
height: 16,
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
)
|
||||
: const Icon(Icons.search),
|
||||
label: Text(_isSearching ? 'Recherche...' : 'Rechercher'),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/// Onglet des résultats
|
||||
Widget _buildSearchResultsTab() {
|
||||
if (_currentResult == null) {
|
||||
return const Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(Icons.search, size: 64, color: Colors.grey),
|
||||
SizedBox(height: 16),
|
||||
Text(
|
||||
'Aucune recherche effectuée',
|
||||
style: TextStyle(fontSize: 18, color: Colors.grey),
|
||||
),
|
||||
SizedBox(height: 8),
|
||||
Text(
|
||||
'Utilisez l\'onglet Critères pour lancer une recherche',
|
||||
style: TextStyle(color: Colors.grey),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (_errorMessage != null) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Icon(Icons.error, size: 64, color: Colors.red),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'Erreur de recherche',
|
||||
style: Theme.of(context).textTheme.titleLarge,
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
_errorMessage!,
|
||||
textAlign: TextAlign.center,
|
||||
style: const TextStyle(color: Colors.red),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
ElevatedButton(
|
||||
onPressed: () => setState(() => _errorMessage = null),
|
||||
child: const Text('Réessayer'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return MembreSearchResults(result: _currentResult!);
|
||||
}
|
||||
|
||||
/// Onglet des statistiques
|
||||
Widget _buildStatisticsTab() {
|
||||
if (_currentResult?.statistics == null) {
|
||||
return const Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(Icons.analytics, size: 64, color: Colors.grey),
|
||||
SizedBox(height: 16),
|
||||
Text(
|
||||
'Aucune statistique disponible',
|
||||
style: TextStyle(fontSize: 18, color: Colors.grey),
|
||||
),
|
||||
SizedBox(height: 8),
|
||||
Text(
|
||||
'Effectuez une recherche pour voir les statistiques',
|
||||
style: TextStyle(color: Colors.grey),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return SearchStatisticsCard(statistics: _currentResult!.statistics!);
|
||||
}
|
||||
|
||||
/// FAB de recherche
|
||||
Widget _buildSearchFab() {
|
||||
return FloatingActionButton.extended(
|
||||
onPressed: _isSearching ? null : _performAdvancedSearch,
|
||||
icon: _isSearching
|
||||
? const SizedBox(
|
||||
width: 20,
|
||||
height: 20,
|
||||
child: CircularProgressIndicator(strokeWidth: 2, color: Colors.white),
|
||||
)
|
||||
: const Icon(Icons.search),
|
||||
label: Text(_isSearching ? 'Recherche...' : 'Rechercher'),
|
||||
);
|
||||
}
|
||||
|
||||
/// Chip de filtre rapide
|
||||
Widget _buildQuickFilterChip(String label, VoidCallback onTap) {
|
||||
return ActionChip(
|
||||
label: Text(label),
|
||||
onPressed: onTap,
|
||||
backgroundColor: Theme.of(context).primaryColor.withOpacity(0.1),
|
||||
labelStyle: TextStyle(color: Theme.of(context).primaryColor),
|
||||
);
|
||||
}
|
||||
|
||||
/// Effectue une recherche rapide
|
||||
void _performQuickSearch() {
|
||||
if (_queryController.text.trim().isEmpty) return;
|
||||
|
||||
final criteria = MembreSearchCriteria.quickSearch(_queryController.text.trim());
|
||||
_performSearch(criteria);
|
||||
}
|
||||
|
||||
/// Effectue une recherche avancée
|
||||
void _performAdvancedSearch() {
|
||||
final criteria = _buildSearchCriteria();
|
||||
_performSearch(criteria);
|
||||
}
|
||||
|
||||
/// Construit les critères de recherche à partir des champs
|
||||
MembreSearchCriteria _buildSearchCriteria() {
|
||||
return MembreSearchCriteria(
|
||||
query: _queryController.text.trim().isEmpty ? null : _queryController.text.trim(),
|
||||
nom: _nomController.text.trim().isEmpty ? null : _nomController.text.trim(),
|
||||
prenom: _prenomController.text.trim().isEmpty ? null : _prenomController.text.trim(),
|
||||
email: _emailController.text.trim().isEmpty ? null : _emailController.text.trim(),
|
||||
telephone: _telephoneController.text.trim().isEmpty ? null : _telephoneController.text.trim(),
|
||||
statut: _selectedStatut,
|
||||
ageMin: _ageRange.start.round(),
|
||||
ageMax: _ageRange.end.round(),
|
||||
region: _regionController.text.trim().isEmpty ? null : _regionController.text.trim(),
|
||||
ville: _villeController.text.trim().isEmpty ? null : _villeController.text.trim(),
|
||||
profession: _professionController.text.trim().isEmpty ? null : _professionController.text.trim(),
|
||||
organisationIds: _selectedOrganisations.isEmpty ? null : _selectedOrganisations,
|
||||
roles: _selectedRoles.isEmpty ? null : _selectedRoles,
|
||||
membreBureau: _membreBureau ? true : null,
|
||||
responsable: _responsable ? true : null,
|
||||
includeInactifs: _includeInactifs,
|
||||
);
|
||||
}
|
||||
|
||||
/// Effectue la recherche
|
||||
void _performSearch(MembreSearchCriteria criteria) async {
|
||||
if (!criteria.hasAnyCriteria) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('Veuillez spécifier au moins un critère de recherche'),
|
||||
backgroundColor: Colors.orange,
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
setState(() {
|
||||
_isSearching = true;
|
||||
_errorMessage = null;
|
||||
_currentCriteria = criteria;
|
||||
});
|
||||
|
||||
try {
|
||||
// TODO: Appeler le service de recherche
|
||||
// final result = await _searchService.searchMembresAdvanced(criteria: criteria);
|
||||
|
||||
// Simulation pour l'instant
|
||||
await Future.delayed(const Duration(seconds: 2));
|
||||
final result = MembreSearchResult.empty(criteria);
|
||||
|
||||
setState(() {
|
||||
_currentResult = result;
|
||||
_isSearching = false;
|
||||
});
|
||||
|
||||
// Basculer vers l'onglet des résultats
|
||||
_tabController.animateTo(1);
|
||||
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(result.resultDescription),
|
||||
backgroundColor: Colors.green,
|
||||
),
|
||||
);
|
||||
} catch (e) {
|
||||
setState(() {
|
||||
_errorMessage = e.toString();
|
||||
_isSearching = false;
|
||||
});
|
||||
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('Erreur de recherche: $e'),
|
||||
backgroundColor: Colors.red,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Efface tous les critères
|
||||
void _clearCriteria() {
|
||||
setState(() {
|
||||
_queryController.clear();
|
||||
_nomController.clear();
|
||||
_prenomController.clear();
|
||||
_emailController.clear();
|
||||
_telephoneController.clear();
|
||||
_regionController.clear();
|
||||
_villeController.clear();
|
||||
_professionController.clear();
|
||||
_selectedStatut = null;
|
||||
_selectedRoles.clear();
|
||||
_selectedOrganisations.clear();
|
||||
_ageRange = const RangeValues(18, 65);
|
||||
_adhesionDateRange = null;
|
||||
_includeInactifs = false;
|
||||
_membreBureau = false;
|
||||
_responsable = false;
|
||||
_currentResult = null;
|
||||
_errorMessage = null;
|
||||
});
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,433 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../../core/models/membre_search_criteria.dart';
|
||||
|
||||
/// Formulaire de recherche de membres
|
||||
/// Widget réutilisable pour la saisie des critères de recherche
|
||||
class MembreSearchForm extends StatefulWidget {
|
||||
final MembreSearchCriteria initialCriteria;
|
||||
final Function(MembreSearchCriteria) onCriteriaChanged;
|
||||
final VoidCallback? onSearch;
|
||||
final VoidCallback? onClear;
|
||||
final bool isCompact;
|
||||
|
||||
const MembreSearchForm({
|
||||
super.key,
|
||||
this.initialCriteria = MembreSearchCriteria.empty,
|
||||
required this.onCriteriaChanged,
|
||||
this.onSearch,
|
||||
this.onClear,
|
||||
this.isCompact = false,
|
||||
});
|
||||
|
||||
@override
|
||||
State<MembreSearchForm> createState() => _MembreSearchFormState();
|
||||
}
|
||||
|
||||
class _MembreSearchFormState extends State<MembreSearchForm> {
|
||||
late TextEditingController _queryController;
|
||||
late TextEditingController _nomController;
|
||||
late TextEditingController _prenomController;
|
||||
late TextEditingController _emailController;
|
||||
late TextEditingController _telephoneController;
|
||||
|
||||
String? _selectedStatut;
|
||||
List<String> _selectedRoles = [];
|
||||
RangeValues _ageRange = const RangeValues(18, 65);
|
||||
bool _includeInactifs = false;
|
||||
bool _membreBureau = false;
|
||||
bool _responsable = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_initializeControllers();
|
||||
_loadInitialCriteria();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_queryController.dispose();
|
||||
_nomController.dispose();
|
||||
_prenomController.dispose();
|
||||
_emailController.dispose();
|
||||
_telephoneController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _initializeControllers() {
|
||||
_queryController = TextEditingController();
|
||||
_nomController = TextEditingController();
|
||||
_prenomController = TextEditingController();
|
||||
_emailController = TextEditingController();
|
||||
_telephoneController = TextEditingController();
|
||||
|
||||
// Écouter les changements pour mettre à jour les critères
|
||||
_queryController.addListener(_updateCriteria);
|
||||
_nomController.addListener(_updateCriteria);
|
||||
_prenomController.addListener(_updateCriteria);
|
||||
_emailController.addListener(_updateCriteria);
|
||||
_telephoneController.addListener(_updateCriteria);
|
||||
}
|
||||
|
||||
void _loadInitialCriteria() {
|
||||
final criteria = widget.initialCriteria;
|
||||
_queryController.text = criteria.query ?? '';
|
||||
_nomController.text = criteria.nom ?? '';
|
||||
_prenomController.text = criteria.prenom ?? '';
|
||||
_emailController.text = criteria.email ?? '';
|
||||
_telephoneController.text = criteria.telephone ?? '';
|
||||
_selectedStatut = criteria.statut;
|
||||
_selectedRoles = criteria.roles ?? [];
|
||||
_ageRange = RangeValues(
|
||||
criteria.ageMin?.toDouble() ?? 18,
|
||||
criteria.ageMax?.toDouble() ?? 65,
|
||||
);
|
||||
_includeInactifs = criteria.includeInactifs;
|
||||
_membreBureau = criteria.membreBureau ?? false;
|
||||
_responsable = criteria.responsable ?? false;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (widget.isCompact) {
|
||||
return _buildCompactForm();
|
||||
}
|
||||
return _buildFullForm();
|
||||
}
|
||||
|
||||
/// Formulaire compact pour recherche rapide
|
||||
Widget _buildCompactForm() {
|
||||
return Card(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
children: [
|
||||
TextField(
|
||||
controller: _queryController,
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Rechercher un membre',
|
||||
hintText: 'Nom, prénom ou email...',
|
||||
prefixIcon: const Icon(Icons.search),
|
||||
suffixIcon: _queryController.text.isNotEmpty
|
||||
? IconButton(
|
||||
icon: const Icon(Icons.clear),
|
||||
onPressed: () {
|
||||
_queryController.clear();
|
||||
_updateCriteria();
|
||||
},
|
||||
)
|
||||
: null,
|
||||
border: const OutlineInputBorder(),
|
||||
),
|
||||
onSubmitted: (_) => widget.onSearch?.call(),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: DropdownButtonFormField<String>(
|
||||
value: _selectedStatut,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Statut',
|
||||
border: OutlineInputBorder(),
|
||||
isDense: true,
|
||||
),
|
||||
items: const [
|
||||
DropdownMenuItem(value: null, child: Text('Tous')),
|
||||
DropdownMenuItem(value: 'ACTIF', child: Text('Actif')),
|
||||
DropdownMenuItem(value: 'INACTIF', child: Text('Inactif')),
|
||||
],
|
||||
onChanged: (value) {
|
||||
setState(() => _selectedStatut = value);
|
||||
_updateCriteria();
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
if (widget.onSearch != null)
|
||||
ElevatedButton.icon(
|
||||
onPressed: widget.onSearch,
|
||||
icon: const Icon(Icons.search),
|
||||
label: const Text('Rechercher'),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Formulaire complet avec tous les critères
|
||||
Widget _buildFullForm() {
|
||||
return Column(
|
||||
children: [
|
||||
// Recherche générale
|
||||
_buildGeneralSearchSection(),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// Critères détaillés
|
||||
_buildDetailedCriteriaSection(),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// Filtres avancés
|
||||
_buildAdvancedFiltersSection(),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// Boutons d'action
|
||||
_buildActionButtons(),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/// Section de recherche générale
|
||||
Widget _buildGeneralSearchSection() {
|
||||
return Card(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'Recherche Générale',
|
||||
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
TextField(
|
||||
controller: _queryController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Terme de recherche',
|
||||
hintText: 'Nom, prénom, email...',
|
||||
prefixIcon: Icon(Icons.search),
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Section des critères détaillés
|
||||
Widget _buildDetailedCriteriaSection() {
|
||||
return Card(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'Critères Détaillés',
|
||||
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: _nomController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Nom',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: _prenomController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Prénom',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
TextField(
|
||||
controller: _emailController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Email',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: _telephoneController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Téléphone',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: DropdownButtonFormField<String>(
|
||||
value: _selectedStatut,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Statut',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
items: const [
|
||||
DropdownMenuItem(value: null, child: Text('Tous')),
|
||||
DropdownMenuItem(value: 'ACTIF', child: Text('Actif')),
|
||||
DropdownMenuItem(value: 'INACTIF', child: Text('Inactif')),
|
||||
DropdownMenuItem(value: 'SUSPENDU', child: Text('Suspendu')),
|
||||
DropdownMenuItem(value: 'RADIE', child: Text('Radié')),
|
||||
],
|
||||
onChanged: (value) {
|
||||
setState(() => _selectedStatut = value);
|
||||
_updateCriteria();
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Section des filtres avancés
|
||||
Widget _buildAdvancedFiltersSection() {
|
||||
return Card(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'Filtres Avancés',
|
||||
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// Tranche d'âge
|
||||
Text('Tranche d\'âge: ${_ageRange.start.round()}-${_ageRange.end.round()} ans'),
|
||||
RangeSlider(
|
||||
values: _ageRange,
|
||||
min: 18,
|
||||
max: 80,
|
||||
divisions: 62,
|
||||
labels: RangeLabels(
|
||||
'${_ageRange.start.round()}',
|
||||
'${_ageRange.end.round()}',
|
||||
),
|
||||
onChanged: (values) {
|
||||
setState(() => _ageRange = values);
|
||||
_updateCriteria();
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// Options booléennes
|
||||
CheckboxListTile(
|
||||
title: const Text('Inclure les membres inactifs'),
|
||||
value: _includeInactifs,
|
||||
onChanged: (value) {
|
||||
setState(() => _includeInactifs = value ?? false);
|
||||
_updateCriteria();
|
||||
},
|
||||
),
|
||||
CheckboxListTile(
|
||||
title: const Text('Membres du bureau uniquement'),
|
||||
value: _membreBureau,
|
||||
onChanged: (value) {
|
||||
setState(() => _membreBureau = value ?? false);
|
||||
_updateCriteria();
|
||||
},
|
||||
),
|
||||
CheckboxListTile(
|
||||
title: const Text('Responsables uniquement'),
|
||||
value: _responsable,
|
||||
onChanged: (value) {
|
||||
setState(() => _responsable = value ?? false);
|
||||
_updateCriteria();
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Boutons d'action
|
||||
Widget _buildActionButtons() {
|
||||
return Row(
|
||||
children: [
|
||||
if (widget.onClear != null)
|
||||
Expanded(
|
||||
child: OutlinedButton.icon(
|
||||
onPressed: () {
|
||||
_clearForm();
|
||||
widget.onClear?.call();
|
||||
},
|
||||
icon: const Icon(Icons.clear),
|
||||
label: const Text('Effacer'),
|
||||
),
|
||||
),
|
||||
if (widget.onClear != null && widget.onSearch != null)
|
||||
const SizedBox(width: 16),
|
||||
if (widget.onSearch != null)
|
||||
Expanded(
|
||||
flex: widget.onClear != null ? 2 : 1,
|
||||
child: ElevatedButton.icon(
|
||||
onPressed: widget.onSearch,
|
||||
icon: const Icon(Icons.search),
|
||||
label: const Text('Rechercher'),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/// Met à jour les critères de recherche
|
||||
void _updateCriteria() {
|
||||
final criteria = MembreSearchCriteria(
|
||||
query: _queryController.text.trim().isEmpty ? null : _queryController.text.trim(),
|
||||
nom: _nomController.text.trim().isEmpty ? null : _nomController.text.trim(),
|
||||
prenom: _prenomController.text.trim().isEmpty ? null : _prenomController.text.trim(),
|
||||
email: _emailController.text.trim().isEmpty ? null : _emailController.text.trim(),
|
||||
telephone: _telephoneController.text.trim().isEmpty ? null : _telephoneController.text.trim(),
|
||||
statut: _selectedStatut,
|
||||
roles: _selectedRoles.isEmpty ? null : _selectedRoles,
|
||||
ageMin: _ageRange.start.round(),
|
||||
ageMax: _ageRange.end.round(),
|
||||
membreBureau: _membreBureau ? true : null,
|
||||
responsable: _responsable ? true : null,
|
||||
includeInactifs: _includeInactifs,
|
||||
);
|
||||
|
||||
widget.onCriteriaChanged(criteria);
|
||||
}
|
||||
|
||||
/// Efface le formulaire
|
||||
void _clearForm() {
|
||||
setState(() {
|
||||
_queryController.clear();
|
||||
_nomController.clear();
|
||||
_prenomController.clear();
|
||||
_emailController.clear();
|
||||
_telephoneController.clear();
|
||||
_selectedStatut = null;
|
||||
_selectedRoles.clear();
|
||||
_ageRange = const RangeValues(18, 65);
|
||||
_includeInactifs = false;
|
||||
_membreBureau = false;
|
||||
_responsable = false;
|
||||
});
|
||||
_updateCriteria();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,388 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../../core/models/membre_search_result.dart' as search_model;
|
||||
import '../../data/models/membre_model.dart' as member_model;
|
||||
|
||||
/// Widget d'affichage des résultats de recherche de membres
|
||||
/// Gère la pagination, le tri et l'affichage des membres trouvés
|
||||
class MembreSearchResults extends StatefulWidget {
|
||||
final search_model.MembreSearchResult result;
|
||||
final Function(member_model.MembreModel)? onMembreSelected;
|
||||
final bool showPagination;
|
||||
|
||||
const MembreSearchResults({
|
||||
super.key,
|
||||
required this.result,
|
||||
this.onMembreSelected,
|
||||
this.showPagination = true,
|
||||
});
|
||||
|
||||
@override
|
||||
State<MembreSearchResults> createState() => _MembreSearchResultsState();
|
||||
}
|
||||
|
||||
class _MembreSearchResultsState extends State<MembreSearchResults> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (widget.result.isEmpty) {
|
||||
return _buildEmptyState();
|
||||
}
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
// En-tête avec informations sur les résultats
|
||||
_buildResultsHeader(),
|
||||
|
||||
// Liste des membres
|
||||
Expanded(
|
||||
child: _buildMembersList(),
|
||||
),
|
||||
|
||||
// Pagination si activée
|
||||
if (widget.showPagination && widget.result.totalPages > 1)
|
||||
_buildPagination(),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/// État vide quand aucun résultat
|
||||
Widget _buildEmptyState() {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.search_off,
|
||||
size: 64,
|
||||
color: Colors.grey[400],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'Aucun membre trouvé',
|
||||
style: Theme.of(context).textTheme.titleLarge?.copyWith(
|
||||
color: Colors.grey[600],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
'Essayez de modifier vos critères de recherche',
|
||||
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
||||
color: Colors.grey[500],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
ElevatedButton.icon(
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
icon: const Icon(Icons.tune),
|
||||
label: const Text('Modifier les critères'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// En-tête avec informations sur les résultats
|
||||
Widget _buildResultsHeader() {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).primaryColor.withOpacity(0.1),
|
||||
border: Border(
|
||||
bottom: BorderSide(
|
||||
color: Theme.of(context).dividerColor,
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.search,
|
||||
color: Theme.of(context).primaryColor,
|
||||
size: 20,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
widget.result.resultDescription,
|
||||
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
Chip(
|
||||
label: Text('${widget.result.executionTimeMs}ms'),
|
||||
backgroundColor: Colors.green.withOpacity(0.1),
|
||||
labelStyle: const TextStyle(
|
||||
color: Colors.green,
|
||||
fontSize: 12,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
if (widget.result.criteria.description.isNotEmpty) ...[
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
'Critères: ${widget.result.criteria.description}',
|
||||
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
||||
color: Colors.grey[600],
|
||||
),
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Liste des membres trouvés
|
||||
Widget _buildMembersList() {
|
||||
return ListView.builder(
|
||||
itemCount: widget.result.membres.length,
|
||||
itemBuilder: (context, index) {
|
||||
final membre = widget.result.membres[index];
|
||||
return _buildMembreCard(membre, index);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/// Carte d'affichage d'un membre
|
||||
Widget _buildMembreCard(member_model.MembreModel membre, int index) {
|
||||
return Card(
|
||||
margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 4),
|
||||
child: ListTile(
|
||||
leading: CircleAvatar(
|
||||
backgroundColor: _getStatusColor(membre.statut ?? 'ACTIF'),
|
||||
child: Text(
|
||||
_getInitials(membre.nom, membre.prenom),
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
title: Text(
|
||||
'${membre.prenom} ${membre.nom}',
|
||||
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
subtitle: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
if (membre.email.isNotEmpty)
|
||||
Row(
|
||||
children: [
|
||||
const Icon(Icons.email, size: 14, color: Colors.grey),
|
||||
const SizedBox(width: 4),
|
||||
Expanded(
|
||||
child: Text(
|
||||
membre.email,
|
||||
style: const TextStyle(fontSize: 12),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
if (membre.telephone?.isNotEmpty == true)
|
||||
Row(
|
||||
children: [
|
||||
const Icon(Icons.phone, size: 14, color: Colors.grey),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
membre.telephone!,
|
||||
style: const TextStyle(fontSize: 12),
|
||||
),
|
||||
],
|
||||
),
|
||||
if (membre.organisation?.nom?.isNotEmpty == true)
|
||||
Row(
|
||||
children: [
|
||||
const Icon(Icons.business, size: 14, color: Colors.grey),
|
||||
const SizedBox(width: 4),
|
||||
Expanded(
|
||||
child: Text(
|
||||
membre.organisation!.nom!,
|
||||
style: const TextStyle(fontSize: 12),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
trailing: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
_buildStatusChip(membre.statut ?? 'ACTIF'),
|
||||
if (membre.role?.isNotEmpty == true) ...[
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
_formatRoles(membre.role!),
|
||||
style: const TextStyle(
|
||||
fontSize: 10,
|
||||
color: Colors.grey,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
onTap: widget.onMembreSelected != null
|
||||
? () => widget.onMembreSelected!(membre)
|
||||
: null,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Pagination
|
||||
Widget _buildPagination() {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).cardColor,
|
||||
border: Border(
|
||||
top: BorderSide(
|
||||
color: Theme.of(context).dividerColor,
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
// Bouton page précédente
|
||||
ElevatedButton.icon(
|
||||
onPressed: widget.result.hasPrevious ? _goToPreviousPage : null,
|
||||
icon: const Icon(Icons.chevron_left),
|
||||
label: const Text('Précédent'),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Colors.grey[100],
|
||||
foregroundColor: Colors.grey[700],
|
||||
),
|
||||
),
|
||||
|
||||
// Indicateur de page
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).primaryColor.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
),
|
||||
child: Text(
|
||||
'Page ${widget.result.currentPage + 1} / ${widget.result.totalPages}',
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).primaryColor,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// Bouton page suivante
|
||||
ElevatedButton.icon(
|
||||
onPressed: widget.result.hasNext ? _goToNextPage : null,
|
||||
icon: const Icon(Icons.chevron_right),
|
||||
label: const Text('Suivant'),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Theme.of(context).primaryColor,
|
||||
foregroundColor: Colors.white,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Chip de statut
|
||||
Widget _buildStatusChip(String statut) {
|
||||
final color = _getStatusColor(statut);
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 2),
|
||||
decoration: BoxDecoration(
|
||||
color: color.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(color: color, width: 1),
|
||||
),
|
||||
child: Text(
|
||||
_getStatusLabel(statut),
|
||||
style: TextStyle(
|
||||
color: color,
|
||||
fontSize: 10,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Obtient la couleur du statut
|
||||
Color _getStatusColor(String statut) {
|
||||
switch (statut.toUpperCase()) {
|
||||
case 'ACTIF':
|
||||
return Colors.green;
|
||||
case 'INACTIF':
|
||||
return Colors.orange;
|
||||
case 'SUSPENDU':
|
||||
return Colors.red;
|
||||
case 'RADIE':
|
||||
return Colors.grey;
|
||||
default:
|
||||
return Colors.grey;
|
||||
}
|
||||
}
|
||||
|
||||
/// Obtient le libellé du statut
|
||||
String _getStatusLabel(String statut) {
|
||||
switch (statut.toUpperCase()) {
|
||||
case 'ACTIF':
|
||||
return 'Actif';
|
||||
case 'INACTIF':
|
||||
return 'Inactif';
|
||||
case 'SUSPENDU':
|
||||
return 'Suspendu';
|
||||
case 'RADIE':
|
||||
return 'Radié';
|
||||
default:
|
||||
return statut;
|
||||
}
|
||||
}
|
||||
|
||||
/// Obtient les initiales d'un membre
|
||||
String _getInitials(String nom, String prenom) {
|
||||
final nomInitial = nom.isNotEmpty ? nom[0].toUpperCase() : '';
|
||||
final prenomInitial = prenom.isNotEmpty ? prenom[0].toUpperCase() : '';
|
||||
return '$prenomInitial$nomInitial';
|
||||
}
|
||||
|
||||
/// Formate les rôles pour l'affichage
|
||||
String _formatRoles(String roles) {
|
||||
final rolesList = roles.split(',').map((r) => r.trim()).toList();
|
||||
if (rolesList.length <= 2) {
|
||||
return rolesList.join(', ');
|
||||
}
|
||||
return '${rolesList.take(2).join(', ')}...';
|
||||
}
|
||||
|
||||
/// Navigation vers la page précédente
|
||||
void _goToPreviousPage() {
|
||||
// TODO: Implémenter la navigation vers la page précédente
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('Navigation vers la page précédente'),
|
||||
duration: Duration(seconds: 1),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Navigation vers la page suivante
|
||||
void _goToNextPage() {
|
||||
// TODO: Implémenter la navigation vers la page suivante
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('Navigation vers la page suivante'),
|
||||
duration: Duration(seconds: 1),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,416 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:fl_chart/fl_chart.dart';
|
||||
|
||||
import '../../../../core/models/membre_search_result.dart';
|
||||
|
||||
/// Widget d'affichage des statistiques de recherche
|
||||
/// Présente les métriques et graphiques des résultats de recherche
|
||||
class SearchStatisticsCard extends StatelessWidget {
|
||||
final SearchStatistics statistics;
|
||||
|
||||
const SearchStatisticsCard({
|
||||
super.key,
|
||||
required this.statistics,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// Titre
|
||||
Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.analytics,
|
||||
color: Theme.of(context).primaryColor,
|
||||
size: 24,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
'Statistiques de Recherche',
|
||||
style: Theme.of(context).textTheme.titleLarge?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// Métriques principales
|
||||
_buildMainMetrics(context),
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// Graphique de répartition actifs/inactifs
|
||||
_buildStatusChart(context),
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// Métriques détaillées
|
||||
_buildDetailedMetrics(context),
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// Informations complémentaires
|
||||
_buildAdditionalInfo(context),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Métriques principales
|
||||
Widget _buildMainMetrics(BuildContext context) {
|
||||
return Card(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'Vue d\'ensemble',
|
||||
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: _buildMetricCard(
|
||||
context,
|
||||
'Total Membres',
|
||||
statistics.totalMembres.toString(),
|
||||
Icons.people,
|
||||
Colors.blue,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: _buildMetricCard(
|
||||
context,
|
||||
'Membres Actifs',
|
||||
statistics.membresActifs.toString(),
|
||||
Icons.person,
|
||||
Colors.green,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: _buildMetricCard(
|
||||
context,
|
||||
'Âge Moyen',
|
||||
'${statistics.ageMoyen.toStringAsFixed(1)} ans',
|
||||
Icons.cake,
|
||||
Colors.orange,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: _buildMetricCard(
|
||||
context,
|
||||
'Ancienneté',
|
||||
'${statistics.ancienneteMoyenne.toStringAsFixed(1)} ans',
|
||||
Icons.schedule,
|
||||
Colors.purple,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Carte de métrique individuelle
|
||||
Widget _buildMetricCard(
|
||||
BuildContext context,
|
||||
String title,
|
||||
String value,
|
||||
IconData icon,
|
||||
Color color,
|
||||
) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(12.0),
|
||||
decoration: BoxDecoration(
|
||||
color: color.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(color: color.withOpacity(0.3)),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
Icon(icon, color: color, size: 24),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
value,
|
||||
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: color,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
title,
|
||||
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
||||
color: Colors.grey[600],
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Graphique de répartition des statuts
|
||||
Widget _buildStatusChart(BuildContext context) {
|
||||
if (statistics.totalMembres == 0) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
|
||||
return Card(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'Répartition par Statut',
|
||||
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
SizedBox(
|
||||
height: 200,
|
||||
child: Row(
|
||||
children: [
|
||||
// Graphique en secteurs
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: PieChart(
|
||||
PieChartData(
|
||||
sections: [
|
||||
PieChartSectionData(
|
||||
value: statistics.membresActifs.toDouble(),
|
||||
title: '${statistics.pourcentageActifs.toStringAsFixed(1)}%',
|
||||
color: Colors.green,
|
||||
radius: 60,
|
||||
titleStyle: const TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
if (statistics.membresInactifs > 0)
|
||||
PieChartSectionData(
|
||||
value: statistics.membresInactifs.toDouble(),
|
||||
title: '${statistics.pourcentageInactifs.toStringAsFixed(1)}%',
|
||||
color: Colors.orange,
|
||||
radius: 60,
|
||||
titleStyle: const TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
],
|
||||
sectionsSpace: 2,
|
||||
centerSpaceRadius: 40,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// Légende
|
||||
Expanded(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_buildLegendItem(
|
||||
'Actifs',
|
||||
statistics.membresActifs,
|
||||
Colors.green,
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
if (statistics.membresInactifs > 0)
|
||||
_buildLegendItem(
|
||||
'Inactifs',
|
||||
statistics.membresInactifs,
|
||||
Colors.orange,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Item de légende
|
||||
Widget _buildLegendItem(String label, int count, Color color) {
|
||||
return Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 12,
|
||||
height: 12,
|
||||
decoration: BoxDecoration(
|
||||
color: color,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
'$label ($count)',
|
||||
style: const TextStyle(fontSize: 12),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/// Métriques détaillées
|
||||
Widget _buildDetailedMetrics(BuildContext context) {
|
||||
return Card(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'Détails Démographiques',
|
||||
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_buildDetailRow(
|
||||
context,
|
||||
'Tranche d\'âge',
|
||||
statistics.trancheAge,
|
||||
Icons.calendar_today,
|
||||
),
|
||||
_buildDetailRow(
|
||||
context,
|
||||
'Organisations',
|
||||
'${statistics.nombreOrganisations} représentées',
|
||||
Icons.business,
|
||||
),
|
||||
_buildDetailRow(
|
||||
context,
|
||||
'Régions',
|
||||
'${statistics.nombreRegions} représentées',
|
||||
Icons.location_on,
|
||||
),
|
||||
_buildDetailRow(
|
||||
context,
|
||||
'Taux d\'activité',
|
||||
'${statistics.pourcentageActifs.toStringAsFixed(1)}%',
|
||||
Icons.trending_up,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Ligne de détail
|
||||
Widget _buildDetailRow(
|
||||
BuildContext context,
|
||||
String label,
|
||||
String value,
|
||||
IconData icon,
|
||||
) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8.0),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
icon,
|
||||
size: 20,
|
||||
color: Colors.grey[600],
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Text(
|
||||
label,
|
||||
style: Theme.of(context).textTheme.bodyMedium,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
value,
|
||||
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Informations complémentaires
|
||||
Widget _buildAdditionalInfo(BuildContext context) {
|
||||
return Card(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.info_outline,
|
||||
color: Theme.of(context).primaryColor,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
'Informations Complémentaires',
|
||||
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
statistics.description,
|
||||
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
||||
color: Colors.grey[700],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Container(
|
||||
padding: const EdgeInsets.all(12.0),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.blue.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(color: Colors.blue.withOpacity(0.3)),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.lightbulb, color: Colors.blue),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
'Ces statistiques sont calculées en temps réel sur les résultats de votre recherche.',
|
||||
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
||||
color: Colors.blue[700],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user