Initial commit: unionflow-mobile-apps
Application Flutter complète (sans build artifacts). Signed-off-by: lions dev Team
This commit is contained in:
@@ -0,0 +1,694 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../../../../core/di/injection_container.dart';
|
||||
import '../../../../shared/models/membre_search_criteria.dart';
|
||||
import '../../../../shared/models/membre_search_result.dart';
|
||||
import '../../../organizations/data/repositories/organization_repository.dart';
|
||||
import '../../../organizations/data/models/organization_model.dart';
|
||||
import '../../data/services/membre_search_service.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;
|
||||
late final MembreSearchService _searchService = sl<MembreSearchService>();
|
||||
MembreSearchCriteria _currentCriteria = MembreSearchCriteria.empty;
|
||||
List<OrganizationModel> _organisations = [];
|
||||
bool _organisationsLoaded = false;
|
||||
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;
|
||||
final List<String> _selectedRoles = [];
|
||||
final List<String> _selectedOrganisations = [];
|
||||
RangeValues _ageRange = const RangeValues(18, 65);
|
||||
DateTimeRange? _adhesionDateRange;
|
||||
bool _includeInactifs = false;
|
||||
bool _membreBureau = false;
|
||||
bool _responsable = false;
|
||||
|
||||
/// Rôles Keycloak utilisables pour le filtre (noms envoyés à l'API)
|
||||
static const List<String> _searchRoleCodes = [
|
||||
'MEMBRE_ACTIF',
|
||||
'MEMBRE_SIMPLE',
|
||||
'ADMIN_ORGANISATION',
|
||||
'SECRETAIRE',
|
||||
'TRESORIER',
|
||||
'CONSULTANT',
|
||||
'GESTIONNAIRE_RH',
|
||||
'SUPER_ADMINISTRATEUR',
|
||||
];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_tabController = TabController(length: 3, vsync: this);
|
||||
_loadOrganisations();
|
||||
}
|
||||
|
||||
static String _roleDisplayName(String code) {
|
||||
const labels = {
|
||||
'MEMBRE_ACTIF': 'Membre actif',
|
||||
'MEMBRE_SIMPLE': 'Membre',
|
||||
'ADMIN_ORGANISATION': 'Admin organisation',
|
||||
'SECRETAIRE': 'Secrétaire',
|
||||
'TRESORIER': 'Trésorier',
|
||||
'CONSULTANT': 'Consultant',
|
||||
'GESTIONNAIRE_RH': 'Gestionnaire RH',
|
||||
'SUPER_ADMINISTRATEUR': 'Super admin',
|
||||
};
|
||||
return labels[code] ?? code;
|
||||
}
|
||||
|
||||
Future<void> _loadOrganisations() async {
|
||||
if (_organisationsLoaded) return;
|
||||
try {
|
||||
final repo = sl<OrganizationRepository>();
|
||||
final list = await repo.getOrganizations(page: 0, size: 200);
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_organisations = list;
|
||||
_organisationsLoaded = true;
|
||||
});
|
||||
}
|
||||
} catch (_) {
|
||||
if (mounted) setState(() => _organisationsLoaded = true);
|
||||
}
|
||||
}
|
||||
|
||||
@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: 'email@domaine.org',
|
||||
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),
|
||||
|
||||
// Organisations (multi-select)
|
||||
Text(
|
||||
'Organisations',
|
||||
style: Theme.of(context).textTheme.titleSmall?.copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
_organisations.isEmpty && !_organisationsLoaded
|
||||
? const SizedBox(
|
||||
height: 24,
|
||||
child: Center(child: CircularProgressIndicator(strokeWidth: 2)),
|
||||
)
|
||||
: Wrap(
|
||||
spacing: 8,
|
||||
runSpacing: 8,
|
||||
children: _organisations
|
||||
.where((o) => o.id != null && o.id!.isNotEmpty)
|
||||
.map((org) {
|
||||
final id = org.id!;
|
||||
final selected = _selectedOrganisations.contains(id);
|
||||
return FilterChip(
|
||||
label: Text(org.nomCourt ?? org.nom, overflow: TextOverflow.ellipsis, maxLines: 1),
|
||||
selected: selected,
|
||||
onSelected: (v) {
|
||||
setState(() {
|
||||
if (v) {
|
||||
_selectedOrganisations.add(id);
|
||||
} else {
|
||||
_selectedOrganisations.remove(id);
|
||||
}
|
||||
});
|
||||
},
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// Rôles (multi-select)
|
||||
Text(
|
||||
'Rôles',
|
||||
style: Theme.of(context).textTheme.titleSmall?.copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Wrap(
|
||||
spacing: 8,
|
||||
runSpacing: 8,
|
||||
children: _searchRoleCodes.map((code) {
|
||||
final selected = _selectedRoles.contains(code);
|
||||
return FilterChip(
|
||||
label: Text(_roleDisplayName(code)),
|
||||
selected: selected,
|
||||
onSelected: (v) {
|
||||
setState(() {
|
||||
if (v) {
|
||||
_selectedRoles.add(code);
|
||||
} else {
|
||||
_selectedRoles.remove(code);
|
||||
}
|
||||
});
|
||||
},
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
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!,
|
||||
onPageChanged: (page) => _performSearch(_currentCriteria, page: page),
|
||||
);
|
||||
}
|
||||
|
||||
/// 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, {int page = 0}) 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 {
|
||||
final result = await _searchService.searchMembresAdvanced(
|
||||
criteria: criteria,
|
||||
page: page,
|
||||
);
|
||||
|
||||
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;
|
||||
});
|
||||
}
|
||||
}
|
||||
1985
lib/features/members/presentation/pages/members_page.dart
Normal file
1985
lib/features/members/presentation/pages/members_page.dart
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,445 @@
|
||||
import 'dart:async';
|
||||
import 'package:flutter/material.dart';
|
||||
import '../../../../shared/design_system/unionflow_design_v2.dart';
|
||||
import '../../../../shared/design_system/components/uf_app_bar.dart';
|
||||
import '../../../../core/constants/app_constants.dart';
|
||||
import '../widgets/add_member_dialog.dart';
|
||||
|
||||
/// Annuaire des Membres - Design UnionFlow
|
||||
class MembersPageWithDataAndPagination extends StatefulWidget {
|
||||
final List<Map<String, dynamic>> members;
|
||||
final int totalCount;
|
||||
final int currentPage;
|
||||
final int totalPages;
|
||||
final Function(int page, String? recherche) onPageChanged;
|
||||
final VoidCallback onRefresh;
|
||||
final void Function(String? query)? onSearch;
|
||||
final VoidCallback? onAddMember;
|
||||
|
||||
const MembersPageWithDataAndPagination({
|
||||
super.key,
|
||||
required this.members,
|
||||
required this.totalCount,
|
||||
required this.currentPage,
|
||||
required this.totalPages,
|
||||
required this.onPageChanged,
|
||||
required this.onRefresh,
|
||||
this.onSearch,
|
||||
this.onAddMember,
|
||||
});
|
||||
|
||||
@override
|
||||
State<MembersPageWithDataAndPagination> createState() => _MembersPageWithDataAndPaginationState();
|
||||
}
|
||||
|
||||
class _MembersPageWithDataAndPaginationState extends State<MembersPageWithDataAndPagination> {
|
||||
final TextEditingController _searchController = TextEditingController();
|
||||
String _searchQuery = '';
|
||||
String _filterStatus = 'Tous';
|
||||
Timer? _searchDebounce;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_searchDebounce?.cancel();
|
||||
_searchController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: UnionFlowColors.background,
|
||||
appBar: UFAppBar(
|
||||
title: 'Annuaire Membres',
|
||||
backgroundColor: UnionFlowColors.surface,
|
||||
foregroundColor: UnionFlowColors.textPrimary,
|
||||
actions: [
|
||||
if (widget.onAddMember != null)
|
||||
IconButton(
|
||||
icon: const Icon(Icons.person_add_outlined),
|
||||
color: UnionFlowColors.unionGreen,
|
||||
onPressed: widget.onAddMember,
|
||||
tooltip: 'Ajouter un membre',
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
],
|
||||
),
|
||||
body: Column(
|
||||
children: [
|
||||
_buildHeader(),
|
||||
_buildSearchAndFilters(),
|
||||
Expanded(child: _buildMembersList()),
|
||||
if (widget.totalPages > 1) _buildPagination(),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildHeader() {
|
||||
final activeCount = widget.members.where((m) => m['status'] == 'Actif').length;
|
||||
final pendingCount = widget.members.where((m) => m['status'] == 'En attente').length;
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(20),
|
||||
decoration: BoxDecoration(
|
||||
color: UnionFlowColors.surface,
|
||||
border: Border(
|
||||
bottom: BorderSide(color: UnionFlowColors.border.withOpacity(0.5), width: 1),
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(child: _buildStatBadge('Total', widget.totalCount.toString(), UnionFlowColors.unionGreen)),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(child: _buildStatBadge('Actifs', activeCount.toString(), UnionFlowColors.success)),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(child: _buildStatBadge('Attente', pendingCount.toString(), UnionFlowColors.warning)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildStatBadge(String label, String value, Color color) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 8),
|
||||
decoration: BoxDecoration(
|
||||
color: color.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(color: color.withOpacity(0.3), width: 1),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
Text(value, style: TextStyle(fontSize: 20, fontWeight: FontWeight.w700, color: color)),
|
||||
const SizedBox(height: 2),
|
||||
Text(label, style: TextStyle(fontSize: 10, fontWeight: FontWeight.w600, color: color)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSearchAndFilters() {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: UnionFlowColors.surface,
|
||||
border: Border(bottom: BorderSide(color: UnionFlowColors.border.withOpacity(0.5), width: 1)),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
TextField(
|
||||
controller: _searchController,
|
||||
onChanged: (v) {
|
||||
setState(() => _searchQuery = v);
|
||||
_searchDebounce?.cancel();
|
||||
_searchDebounce = Timer(AppConstants.searchDebounce, () {
|
||||
widget.onSearch?.call(v.isEmpty ? null : v);
|
||||
});
|
||||
},
|
||||
style: const TextStyle(fontSize: 14, color: UnionFlowColors.textPrimary),
|
||||
decoration: InputDecoration(
|
||||
hintText: 'Rechercher un membre...',
|
||||
hintStyle: const TextStyle(fontSize: 13, color: UnionFlowColors.textTertiary),
|
||||
prefixIcon: const Icon(Icons.search, size: 20, color: UnionFlowColors.textSecondary),
|
||||
suffixIcon: _searchQuery.isNotEmpty
|
||||
? IconButton(
|
||||
icon: const Icon(Icons.clear, size: 18, color: UnionFlowColors.textSecondary),
|
||||
onPressed: () {
|
||||
_searchDebounce?.cancel();
|
||||
_searchController.clear();
|
||||
setState(() => _searchQuery = '');
|
||||
widget.onSearch?.call(null);
|
||||
},
|
||||
)
|
||||
: null,
|
||||
contentPadding: const EdgeInsets.symmetric(vertical: 12, horizontal: 16),
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: BorderSide(color: UnionFlowColors.border.withOpacity(0.3)),
|
||||
),
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: BorderSide(color: UnionFlowColors.border.withOpacity(0.3)),
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: const BorderSide(color: UnionFlowColors.unionGreen, width: 1.5),
|
||||
),
|
||||
filled: true,
|
||||
fillColor: UnionFlowColors.surfaceVariant.withOpacity(0.3),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: Row(
|
||||
children: [
|
||||
_buildFilterChip('Tous'),
|
||||
const SizedBox(width: 8),
|
||||
_buildFilterChip('Actif'),
|
||||
const SizedBox(width: 8),
|
||||
_buildFilterChip('Inactif'),
|
||||
const SizedBox(width: 8),
|
||||
_buildFilterChip('En attente'),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildFilterChip(String label) {
|
||||
final isSelected = _filterStatus == label;
|
||||
return GestureDetector(
|
||||
onTap: () => setState(() => _filterStatus = label),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
decoration: BoxDecoration(
|
||||
color: isSelected ? UnionFlowColors.unionGreen : UnionFlowColors.surface,
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
border: Border.all(color: isSelected ? UnionFlowColors.unionGreen : UnionFlowColors.border, width: 1),
|
||||
),
|
||||
child: Text(
|
||||
label,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: isSelected ? Colors.white : UnionFlowColors.textSecondary,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildMembersList() {
|
||||
final filtered = widget.members.where((m) {
|
||||
final matchesSearch = _searchQuery.isEmpty ||
|
||||
m['name']!.toLowerCase().contains(_searchQuery.toLowerCase()) ||
|
||||
(m['email']?.toLowerCase().contains(_searchQuery.toLowerCase()) ?? false);
|
||||
final matchesStatus = _filterStatus == 'Tous' || m['status'] == _filterStatus;
|
||||
return matchesSearch && matchesStatus;
|
||||
}).toList();
|
||||
|
||||
if (filtered.isEmpty) return _buildEmptyState();
|
||||
|
||||
return RefreshIndicator(
|
||||
onRefresh: () async => widget.onRefresh(),
|
||||
color: UnionFlowColors.unionGreen,
|
||||
child: ListView.separated(
|
||||
padding: const EdgeInsets.all(16),
|
||||
itemCount: filtered.length,
|
||||
separatorBuilder: (_, __) => const SizedBox(height: 12),
|
||||
itemBuilder: (context, index) => _buildMemberCard(filtered[index]),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildMemberCard(Map<String, dynamic> member) {
|
||||
return GestureDetector(
|
||||
onTap: () => _showMemberDetails(member),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: UnionFlowColors.surface,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
boxShadow: UnionFlowColors.softShadow,
|
||||
border: Border.all(color: UnionFlowColors.border.withOpacity(0.3), width: 1),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 48,
|
||||
height: 48,
|
||||
decoration: const BoxDecoration(gradient: UnionFlowColors.primaryGradient, shape: BoxShape.circle),
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
member['initiales'] ?? '??',
|
||||
style: const TextStyle(color: Colors.white, fontWeight: FontWeight.w700, fontSize: 18),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
member['name'] ?? 'Inconnu',
|
||||
style: const TextStyle(fontSize: 14, fontWeight: FontWeight.w600, color: UnionFlowColors.textPrimary),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
member['role'] ?? 'Membre',
|
||||
style: const TextStyle(fontSize: 12, color: UnionFlowColors.textSecondary),
|
||||
),
|
||||
if (member['email'] != null) ...[
|
||||
const SizedBox(height: 4),
|
||||
Row(
|
||||
children: [
|
||||
const Icon(Icons.email_outlined, size: 12, color: UnionFlowColors.textTertiary),
|
||||
const SizedBox(width: 4),
|
||||
Text(member['email']!, style: const TextStyle(fontSize: 11, color: UnionFlowColors.textTertiary)),
|
||||
],
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
_buildStatusBadge(member['status']),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildStatusBadge(String? status) {
|
||||
Color color;
|
||||
switch (status) {
|
||||
case 'Actif':
|
||||
color = UnionFlowColors.success;
|
||||
break;
|
||||
case 'Inactif':
|
||||
color = UnionFlowColors.error;
|
||||
break;
|
||||
case 'En attente':
|
||||
color = UnionFlowColors.warning;
|
||||
break;
|
||||
default:
|
||||
color = UnionFlowColors.textSecondary;
|
||||
}
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: color.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(color: color.withOpacity(0.3), width: 1),
|
||||
),
|
||||
child: Text(status ?? '?', style: TextStyle(fontSize: 11, fontWeight: FontWeight.w600, color: color)),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildEmptyState() {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(24),
|
||||
decoration: const BoxDecoration(color: UnionFlowColors.unionGreenPale, shape: BoxShape.circle),
|
||||
child: const Icon(Icons.people_outline, size: 64, color: UnionFlowColors.unionGreen),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
const Text(
|
||||
'Aucun membre trouvé',
|
||||
style: TextStyle(fontSize: 16, fontWeight: FontWeight.w700, color: UnionFlowColors.textPrimary),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
_searchQuery.isEmpty ? 'Changez vos filtres' : 'Essayez une autre recherche',
|
||||
style: const TextStyle(fontSize: 13, color: UnionFlowColors.textSecondary),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPagination() {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(vertical: 12),
|
||||
decoration: BoxDecoration(
|
||||
color: UnionFlowColors.surface,
|
||||
border: Border(top: BorderSide(color: UnionFlowColors.border.withOpacity(0.5), width: 1)),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.chevron_left, size: 24),
|
||||
color: widget.currentPage > 0 ? UnionFlowColors.unionGreen : UnionFlowColors.textTertiary,
|
||||
onPressed: widget.currentPage > 0
|
||||
? () => widget.onPageChanged(
|
||||
widget.currentPage - 1,
|
||||
_searchQuery.isEmpty ? null : _searchQuery,
|
||||
)
|
||||
: null,
|
||||
),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
decoration: BoxDecoration(gradient: UnionFlowColors.primaryGradient, borderRadius: BorderRadius.circular(20)),
|
||||
child: Text(
|
||||
'Page ${widget.currentPage + 1} / ${widget.totalPages}',
|
||||
style: const TextStyle(fontSize: 13, fontWeight: FontWeight.w600, color: Colors.white),
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.chevron_right, size: 24),
|
||||
color: widget.currentPage < widget.totalPages - 1 ? UnionFlowColors.unionGreen : UnionFlowColors.textTertiary,
|
||||
onPressed: widget.currentPage < widget.totalPages - 1
|
||||
? () => widget.onPageChanged(
|
||||
widget.currentPage + 1,
|
||||
_searchQuery.isEmpty ? null : _searchQuery,
|
||||
)
|
||||
: null,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showMemberDetails(Map<String, dynamic> member) {
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
backgroundColor: Colors.transparent,
|
||||
builder: (context) => Container(
|
||||
padding: const EdgeInsets.all(24),
|
||||
decoration: const BoxDecoration(
|
||||
color: UnionFlowColors.surface,
|
||||
borderRadius: BorderRadius.vertical(top: Radius.circular(24)),
|
||||
),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Container(
|
||||
width: 80,
|
||||
height: 80,
|
||||
decoration: const BoxDecoration(gradient: UnionFlowColors.primaryGradient, shape: BoxShape.circle),
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
member['initiales'] ?? '??',
|
||||
style: const TextStyle(color: Colors.white, fontWeight: FontWeight.w900, fontSize: 32),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
member['name'] ?? '',
|
||||
style: const TextStyle(fontSize: 18, fontWeight: FontWeight.w700, color: UnionFlowColors.textPrimary),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
member['role'] ?? '',
|
||||
style: const TextStyle(fontSize: 13, color: UnionFlowColors.textSecondary),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
_buildInfoRow(Icons.email_outlined, member['email'] ?? 'Non fourni'),
|
||||
_buildInfoRow(Icons.phone_outlined, member['phone'] ?? 'Non fourni'),
|
||||
_buildInfoRow(Icons.location_on_outlined, member['location'] ?? 'Non renseigné'),
|
||||
_buildInfoRow(Icons.work_outline, member['department'] ?? 'Aucun département'),
|
||||
const SizedBox(height: 24),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildInfoRow(IconData icon, String text) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(icon, size: 18, color: UnionFlowColors.unionGreen),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(child: Text(text, style: const TextStyle(fontSize: 13, color: UnionFlowColors.textPrimary))),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,286 @@
|
||||
/// Wrapper BLoC pour la page des membres
|
||||
///
|
||||
/// Ce fichier enveloppe la MembersPage existante avec le MembresBloc
|
||||
/// pour connecter l'UI riche existante à l'API backend réelle.
|
||||
library members_page_wrapper;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
|
||||
import '../../../../shared/widgets/error_widget.dart';
|
||||
import '../../../../shared/widgets/loading_widget.dart';
|
||||
import '../../../../core/utils/logger.dart';
|
||||
import '../../bloc/membres_bloc.dart';
|
||||
import '../../bloc/membres_event.dart';
|
||||
import '../../bloc/membres_state.dart';
|
||||
import '../../data/models/membre_complete_model.dart';
|
||||
import '../widgets/add_member_dialog.dart';
|
||||
import 'members_page_connected.dart';
|
||||
|
||||
final _getIt = GetIt.instance;
|
||||
|
||||
/// Wrapper qui fournit le BLoC à la page des membres
|
||||
class MembersPageWrapper extends StatelessWidget {
|
||||
const MembersPageWrapper({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
AppLogger.info('MembersPageWrapper: Création du BlocProvider');
|
||||
|
||||
return BlocProvider<MembresBloc>(
|
||||
create: (context) {
|
||||
AppLogger.info('MembresPageWrapper: Initialisation du MembresBloc');
|
||||
final bloc = _getIt<MembresBloc>();
|
||||
// Charger les membres au démarrage
|
||||
bloc.add(const LoadMembres());
|
||||
return bloc;
|
||||
},
|
||||
child: const MembersPageConnected(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Page des membres connectée au BLoC
|
||||
///
|
||||
/// Cette page gère les états du BLoC et affiche l'UI appropriée
|
||||
class MembersPageConnected extends StatelessWidget {
|
||||
const MembersPageConnected({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocListener<MembresBloc, MembresState>(
|
||||
listener: (context, state) {
|
||||
// Après création : recharger la liste
|
||||
if (state is MembreCreated) {
|
||||
context.read<MembresBloc>().add(const LoadMembres(refresh: true));
|
||||
}
|
||||
|
||||
// Gestion des erreurs avec SnackBar
|
||||
if (state is MembresError) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(state.message),
|
||||
backgroundColor: Colors.red,
|
||||
duration: const Duration(seconds: 4),
|
||||
action: SnackBarAction(
|
||||
label: 'Réessayer',
|
||||
textColor: Colors.white,
|
||||
onPressed: () {
|
||||
context.read<MembresBloc>().add(const LoadMembres());
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
child: BlocBuilder<MembresBloc, MembresState>(
|
||||
builder: (context, state) {
|
||||
AppLogger.blocState('MembresBloc', state.runtimeType.toString());
|
||||
|
||||
// État initial
|
||||
if (state is MembresInitial) {
|
||||
return Container(
|
||||
color: const Color(0xFFF8F9FA),
|
||||
child: const Center(
|
||||
child: AppLoadingWidget(message: 'Initialisation...'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// État de chargement
|
||||
if (state is MembresLoading) {
|
||||
return Container(
|
||||
color: const Color(0xFFF8F9FA),
|
||||
child: const Center(
|
||||
child: AppLoadingWidget(message: 'Chargement des membres...'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// État de rafraîchissement (afficher l'UI avec un indicateur)
|
||||
if (state is MembresRefreshing) {
|
||||
// Affiche un indicateur pendant le rafraîchissement
|
||||
return Container(
|
||||
color: const Color(0xFFF8F9FA),
|
||||
child: const Center(
|
||||
child: AppLoadingWidget(message: 'Actualisation...'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Après création : on recharge la liste (listener a dispatché LoadMembres)
|
||||
if (state is MembreCreated) {
|
||||
return Container(
|
||||
color: const Color(0xFFF8F9FA),
|
||||
child: const Center(
|
||||
child: AppLoadingWidget(message: 'Actualisation...'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// État chargé avec succès
|
||||
if (state is MembresLoaded) {
|
||||
final membres = state.membres;
|
||||
AppLogger.info('MembresPageConnected: ${membres.length} membres chargés');
|
||||
|
||||
// Convertir les membres en format Map pour l'UI existante
|
||||
final membersData = _convertMembersToMapList(membres);
|
||||
|
||||
return MembersPageWithDataAndPagination(
|
||||
members: membersData,
|
||||
totalCount: state.totalElements,
|
||||
currentPage: state.currentPage,
|
||||
totalPages: state.totalPages,
|
||||
onPageChanged: (newPage, recherche) {
|
||||
AppLogger.userAction('Load page', data: {'page': newPage});
|
||||
context.read<MembresBloc>().add(LoadMembres(page: newPage, recherche: recherche));
|
||||
},
|
||||
onRefresh: () {
|
||||
AppLogger.userAction('Refresh membres');
|
||||
context.read<MembresBloc>().add(const LoadMembres(refresh: true));
|
||||
},
|
||||
onSearch: (query) {
|
||||
context.read<MembresBloc>().add(LoadMembres(page: 0, recherche: query));
|
||||
},
|
||||
onAddMember: () async {
|
||||
await showDialog<void>(
|
||||
context: context,
|
||||
builder: (_) => const AddMemberDialog(),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
// État d'erreur réseau
|
||||
if (state is MembresNetworkError) {
|
||||
AppLogger.error('MembersPageConnected: Erreur réseau', error: state.message);
|
||||
return Container(
|
||||
color: const Color(0xFFF8F9FA),
|
||||
child: NetworkErrorWidget(
|
||||
onRetry: () {
|
||||
AppLogger.userAction('Retry load membres after network error');
|
||||
context.read<MembresBloc>().add(const LoadMembres());
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// État d'erreur générale
|
||||
if (state is MembresError) {
|
||||
AppLogger.error('MembersPageConnected: Erreur', error: state.message);
|
||||
return Container(
|
||||
color: const Color(0xFFF8F9FA),
|
||||
child: AppErrorWidget(
|
||||
message: state.message,
|
||||
onRetry: () {
|
||||
AppLogger.userAction('Retry load membres after error');
|
||||
context.read<MembresBloc>().add(const LoadMembres());
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// État par défaut (ne devrait jamais arriver)
|
||||
AppLogger.warning('MembersPageConnected: État non géré: ${state.runtimeType}');
|
||||
return Container(
|
||||
color: const Color(0xFFF8F9FA),
|
||||
child: const Center(
|
||||
child: AppLoadingWidget(message: 'Chargement...'),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Convertit une liste de MembreCompletModel en List<Map<String, dynamic>>
|
||||
/// pour compatibilité avec l'UI existante
|
||||
List<Map<String, dynamic>> _convertMembersToMapList(List<MembreCompletModel> membres) {
|
||||
return membres.map((membre) => _convertMembreToMap(membre)).toList();
|
||||
}
|
||||
|
||||
/// Convertit un MembreCompletModel en Map<String, dynamic>
|
||||
Map<String, dynamic> _convertMembreToMap(MembreCompletModel membre) {
|
||||
return {
|
||||
'id': membre.id ?? '',
|
||||
'name': membre.nomComplet,
|
||||
'email': membre.email,
|
||||
'role': _mapRoleToString(membre.role),
|
||||
'status': _mapStatutToString(membre.statut),
|
||||
'joinDate': membre.dateAdhesion,
|
||||
'lastActivity': membre.derniereActivite ?? DateTime.now(),
|
||||
'avatar': membre.photo,
|
||||
'phone': membre.telephone ?? '',
|
||||
'department': membre.profession ?? '',
|
||||
'location': '${membre.ville ?? ''}, ${membre.pays ?? ''}',
|
||||
'permissions': 15, // Valeurs par défaut tant que l'API ne fournit pas permissions
|
||||
'contributionScore': 0, // Valeurs par défaut tant que l'API ne fournit pas contributionScore
|
||||
'eventsAttended': membre.nombreEvenementsParticipes,
|
||||
'projectsInvolved': 0, // Valeurs par défaut tant que l'API ne fournit pas projectsInvolved
|
||||
|
||||
// Champs supplémentaires du modèle
|
||||
'prenom': membre.prenom,
|
||||
'nom': membre.nom,
|
||||
'dateNaissance': membre.dateNaissance,
|
||||
'genre': membre.genre?.name,
|
||||
'adresse': membre.adresse,
|
||||
'ville': membre.ville,
|
||||
'codePostal': membre.codePostal,
|
||||
'region': membre.region,
|
||||
'pays': membre.pays,
|
||||
'profession': membre.profession,
|
||||
'nationalite': membre.nationalite,
|
||||
'organisationId': membre.organisationId,
|
||||
'membreBureau': membre.membreBureau,
|
||||
'responsable': membre.responsable,
|
||||
'fonctionBureau': membre.fonctionBureau,
|
||||
'numeroMembre': membre.numeroMembre,
|
||||
'cotisationAJour': membre.cotisationAJour,
|
||||
|
||||
// Propriétés calculées
|
||||
'initiales': membre.initiales,
|
||||
'age': membre.age,
|
||||
'estActifEtAJour': membre.estActifEtAJour,
|
||||
};
|
||||
}
|
||||
|
||||
/// Mappe le rôle du modèle vers une chaîne lisible
|
||||
String _mapRoleToString(String? role) {
|
||||
if (role == null) return 'Membre Simple';
|
||||
|
||||
switch (role.toLowerCase()) {
|
||||
case 'superadmin':
|
||||
return 'Super Administrateur';
|
||||
case 'orgadmin':
|
||||
return 'Administrateur Org';
|
||||
case 'moderator':
|
||||
return 'Modérateur';
|
||||
case 'activemember':
|
||||
return 'Membre Actif';
|
||||
case 'simplemember':
|
||||
return 'Membre Simple';
|
||||
case 'visitor':
|
||||
return 'Visiteur';
|
||||
default:
|
||||
return role;
|
||||
}
|
||||
}
|
||||
|
||||
/// Mappe le statut du modèle vers une chaîne lisible
|
||||
String _mapStatutToString(StatutMembre? statut) {
|
||||
if (statut == null) return 'Actif';
|
||||
|
||||
switch (statut) {
|
||||
case StatutMembre.actif:
|
||||
return 'Actif';
|
||||
case StatutMembre.inactif:
|
||||
return 'Inactif';
|
||||
case StatutMembre.suspendu:
|
||||
return 'Suspendu';
|
||||
case StatutMembre.enAttente:
|
||||
return 'En attente';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user