feat(unionflow): ajout Spec-Kit, constitution, mission mutuelles
- Config Spec-Kit pour Spec-Driven Development - CONSTITUTION.md + .specify/memory/constitution.md - Commandes Cursor /speckit.*, règles projet - Mission: associations + mutuelles d'épargne et de financement - .gitignore: versionner config spec-kit unionflow Made-with: Cursor
This commit is contained in:
@@ -0,0 +1,579 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
import '../../../../shared/models/membre_search_criteria.dart';
|
||||
import '../../../../shared/models/membre_search_result.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;
|
||||
final MembreSearchService _searchService = GetIt.instance<MembreSearchService>();
|
||||
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;
|
||||
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;
|
||||
|
||||
@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!,
|
||||
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;
|
||||
});
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,956 @@
|
||||
/// Page des membres avec données injectées depuis le BLoC
|
||||
///
|
||||
/// Cette version de MembersPage accepte les données en paramètre
|
||||
/// au lieu d'utiliser des données mock hardcodées.
|
||||
library members_page_connected;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
import '../../../../features/authentication/presentation/bloc/auth_bloc.dart';
|
||||
import '../../../../features/authentication/data/models/user_role.dart';
|
||||
import '../../../../core/utils/logger.dart';
|
||||
import '../widgets/add_member_dialog.dart';
|
||||
import '../../bloc/membres_bloc.dart';
|
||||
import '../../bloc/membres_event.dart';
|
||||
|
||||
/// Page de gestion des membres avec données injectées
|
||||
class MembersPageWithData extends StatefulWidget {
|
||||
/// Liste des membres à afficher
|
||||
final List<Map<String, dynamic>> members;
|
||||
|
||||
/// Nombre total de membres (pour la pagination)
|
||||
final int totalCount;
|
||||
|
||||
/// Page actuelle
|
||||
final int currentPage;
|
||||
|
||||
/// Nombre total de pages
|
||||
final int totalPages;
|
||||
|
||||
/// Taille de la page
|
||||
final int pageSize;
|
||||
|
||||
const MembersPageWithData({
|
||||
super.key,
|
||||
required this.members,
|
||||
required this.totalCount,
|
||||
required this.currentPage,
|
||||
required this.totalPages,
|
||||
this.pageSize = 20,
|
||||
});
|
||||
|
||||
@override
|
||||
State<MembersPageWithData> createState() => _MembersPageWithDataState();
|
||||
}
|
||||
|
||||
class _MembersPageWithDataState extends State<MembersPageWithData>
|
||||
with TickerProviderStateMixin {
|
||||
// Controllers et état
|
||||
final TextEditingController _searchController = TextEditingController();
|
||||
late TabController _tabController;
|
||||
|
||||
// État de l'interface
|
||||
String _searchQuery = '';
|
||||
|
||||
|
||||
bool _isGridView = false;
|
||||
|
||||
|
||||
// Filtres avancés
|
||||
|
||||
final List<String> _selectedStatuses = ['Actif', 'Inactif', 'Suspendu', 'En attente'];
|
||||
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_tabController = TabController(length: 4, vsync: this);
|
||||
AppLogger.info('MembersPageWithData initialisée avec ${widget.members.length} membres');
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_searchController.dispose();
|
||||
_tabController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<AuthBloc, AuthState>(
|
||||
builder: (context, state) {
|
||||
if (state is! AuthAuthenticated) {
|
||||
return Container(
|
||||
color: const Color(0xFFF8F9FA),
|
||||
child: const Center(child: CircularProgressIndicator()),
|
||||
);
|
||||
}
|
||||
|
||||
return Container(
|
||||
color: const Color(0xFFF8F9FA),
|
||||
child: _buildMembersContent(state),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/// Contenu principal de la page membres
|
||||
Widget _buildMembersContent(AuthAuthenticated state) {
|
||||
return SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(12),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// Header avec titre et actions
|
||||
_buildMembersHeader(state),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// Statistiques et métriques
|
||||
_buildMembersMetrics(),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// Barre de recherche et filtres
|
||||
_buildSearchAndFilters(),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// Onglets de catégories
|
||||
_buildCategoryTabs(),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// Liste/Grille des membres
|
||||
_buildMembersDisplay(),
|
||||
|
||||
// Pagination
|
||||
if (widget.totalPages > 1) ...[
|
||||
const SizedBox(height: 16),
|
||||
_buildPagination(),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Header avec titre et actions principales
|
||||
Widget _buildMembersHeader(AuthAuthenticated state) {
|
||||
final canManageMembers = _canManageMembers(state.effectiveRole);
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
gradient: const LinearGradient(
|
||||
colors: [Color(0xFF6C5CE7), Color(0xFF5A4FCF)],
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: const Color(0xFF6C5CE7).withOpacity(0.3),
|
||||
blurRadius: 20,
|
||||
offset: const Offset(0, 8),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withOpacity(0.2),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.people,
|
||||
color: Colors.white,
|
||||
size: 28,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'Gestion des Membres',
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 24,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'${widget.totalCount} membres au total',
|
||||
style: TextStyle(
|
||||
color: Colors.white.withOpacity(0.9),
|
||||
fontSize: 14,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (canManageMembers) ...[
|
||||
IconButton(
|
||||
icon: const Icon(Icons.add_circle, color: Colors.white, size: 28),
|
||||
onPressed: () {
|
||||
AppLogger.userAction('Add new member button clicked');
|
||||
_showAddMemberDialog();
|
||||
},
|
||||
tooltip: 'Ajouter un membre',
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.file_download, color: Colors.white),
|
||||
onPressed: () {
|
||||
AppLogger.userAction('Export members button clicked');
|
||||
_exportMembers();
|
||||
},
|
||||
tooltip: 'Exporter',
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Métriques et statistiques des membres
|
||||
Widget _buildMembersMetrics() {
|
||||
final filteredMembers = _getFilteredMembers();
|
||||
final activeMembers = filteredMembers.where((m) => m['status'] == 'Actif').length;
|
||||
final inactiveMembers = filteredMembers.where((m) => m['status'] == 'Inactif').length;
|
||||
final pendingMembers = filteredMembers.where((m) => m['status'] == 'En attente').length;
|
||||
|
||||
return Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: _buildMetricCard(
|
||||
'Actifs',
|
||||
activeMembers.toString(),
|
||||
Icons.check_circle,
|
||||
const Color(0xFF00B894),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: _buildMetricCard(
|
||||
'Inactifs',
|
||||
inactiveMembers.toString(),
|
||||
Icons.pause_circle,
|
||||
const Color(0xFFFFBE76),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: _buildMetricCard(
|
||||
'En attente',
|
||||
pendingMembers.toString(),
|
||||
Icons.pending,
|
||||
const Color(0xFF74B9FF),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/// Carte de métrique individuelle
|
||||
Widget _buildMetricCard(String label, String value, IconData icon, Color color) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.05),
|
||||
blurRadius: 10,
|
||||
offset: const Offset(0, 4),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
Icon(icon, color: color, size: 32),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
value,
|
||||
style: TextStyle(
|
||||
fontSize: 24,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: color,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
label,
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
color: Color(0xFF636E72),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Barre de recherche et filtres
|
||||
Widget _buildSearchAndFilters() {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.05),
|
||||
blurRadius: 10,
|
||||
offset: const Offset(0, 4),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: _searchController,
|
||||
decoration: InputDecoration(
|
||||
hintText: 'Rechercher un membre...',
|
||||
prefixIcon: const Icon(Icons.search),
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
borderSide: BorderSide.none,
|
||||
),
|
||||
filled: true,
|
||||
fillColor: const Color(0xFFF8F9FA),
|
||||
),
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
_searchQuery = value;
|
||||
});
|
||||
AppLogger.userAction('Search members', data: {'query': value});
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
IconButton(
|
||||
icon: Icon(
|
||||
_isGridView ? Icons.view_list : Icons.grid_view,
|
||||
color: const Color(0xFF6C5CE7),
|
||||
),
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
_isGridView = !_isGridView;
|
||||
});
|
||||
AppLogger.userAction('Toggle view mode', data: {'isGrid': _isGridView});
|
||||
},
|
||||
tooltip: _isGridView ? 'Vue liste' : 'Vue grille',
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Onglets de catégories
|
||||
Widget _buildCategoryTabs() {
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: TabBar(
|
||||
controller: _tabController,
|
||||
labelColor: const Color(0xFF6C5CE7),
|
||||
unselectedLabelColor: const Color(0xFF636E72),
|
||||
indicatorColor: const Color(0xFF6C5CE7),
|
||||
tabs: const [
|
||||
Tab(text: 'Tous'),
|
||||
Tab(text: 'Actifs'),
|
||||
Tab(text: 'Équipes'),
|
||||
Tab(text: 'Analytics'),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Affichage principal des membres
|
||||
Widget _buildMembersDisplay() {
|
||||
final filteredMembers = _getFilteredMembers();
|
||||
|
||||
if (filteredMembers.isEmpty) {
|
||||
return _buildEmptyState();
|
||||
}
|
||||
|
||||
return SizedBox(
|
||||
height: 600,
|
||||
child: TabBarView(
|
||||
controller: _tabController,
|
||||
children: [
|
||||
_buildMembersList(filteredMembers),
|
||||
_buildMembersList(filteredMembers.where((m) => m['status'] == 'Actif').toList()),
|
||||
_buildTeamsView(filteredMembers),
|
||||
_buildAnalyticsView(filteredMembers),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Liste des membres
|
||||
Widget _buildMembersList(List<Map<String, dynamic>> members) {
|
||||
if (_isGridView) {
|
||||
return _buildMembersGrid(members);
|
||||
}
|
||||
|
||||
return ListView.builder(
|
||||
itemCount: members.length,
|
||||
padding: const EdgeInsets.all(8),
|
||||
itemBuilder: (context, index) {
|
||||
final member = members[index];
|
||||
return _buildMemberCard(member);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/// Carte d'un membre
|
||||
Widget _buildMemberCard(Map<String, dynamic> member) {
|
||||
return Card(
|
||||
margin: const EdgeInsets.only(bottom: 12),
|
||||
elevation: 2,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: ListTile(
|
||||
leading: CircleAvatar(
|
||||
backgroundColor: const Color(0xFF6C5CE7),
|
||||
child: Text(
|
||||
_getInitials(member['name']),
|
||||
style: const TextStyle(color: Colors.white),
|
||||
),
|
||||
),
|
||||
title: Text(
|
||||
member['name'],
|
||||
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
subtitle: Text(member['email']),
|
||||
trailing: _buildStatusChip(member['status']),
|
||||
onTap: () {
|
||||
AppLogger.userAction('View member details', data: {'memberId': member['id']});
|
||||
_showMemberDetails(member);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Grille des membres
|
||||
Widget _buildMembersGrid(List<Map<String, dynamic>> members) {
|
||||
return GridView.builder(
|
||||
padding: const EdgeInsets.all(8),
|
||||
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: 2,
|
||||
crossAxisSpacing: 12,
|
||||
mainAxisSpacing: 12,
|
||||
childAspectRatio: 0.85,
|
||||
),
|
||||
itemCount: members.length,
|
||||
itemBuilder: (context, index) {
|
||||
final member = members[index];
|
||||
return _buildMemberGridCard(member);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/// Carte membre pour la grille
|
||||
Widget _buildMemberGridCard(Map<String, dynamic> member) {
|
||||
return Card(
|
||||
elevation: 2,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
AppLogger.userAction('View member details (grid)', data: {'memberId': member['id']});
|
||||
_showMemberDetails(member);
|
||||
},
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(12),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
CircleAvatar(
|
||||
radius: 30,
|
||||
backgroundColor: const Color(0xFF6C5CE7),
|
||||
child: Text(
|
||||
_getInitials(member['name']),
|
||||
style: const TextStyle(color: Colors.white, fontSize: 20),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
member['name'],
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 14,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
member['role'],
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
color: Color(0xFF636E72),
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
_buildStatusChip(member['status']),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Chip de statut
|
||||
Widget _buildStatusChip(String status) {
|
||||
Color color;
|
||||
switch (status) {
|
||||
case 'Actif':
|
||||
color = const Color(0xFF00B894);
|
||||
break;
|
||||
case 'Inactif':
|
||||
color = const Color(0xFFFFBE76);
|
||||
break;
|
||||
case 'Suspendu':
|
||||
color = const Color(0xFFFF7675);
|
||||
break;
|
||||
case 'En attente':
|
||||
color = const Color(0xFF74B9FF);
|
||||
break;
|
||||
default:
|
||||
color = const Color(0xFF636E72);
|
||||
}
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: color.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Text(
|
||||
status,
|
||||
style: TextStyle(
|
||||
color: color,
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Vue des équipes (placeholder)
|
||||
Widget _buildTeamsView(List<Map<String, dynamic>> members) {
|
||||
return const Center(
|
||||
child: Text('Vue des équipes - À implémenter'),
|
||||
);
|
||||
}
|
||||
|
||||
/// Vue analytics (placeholder)
|
||||
Widget _buildAnalyticsView(List<Map<String, dynamic>> members) {
|
||||
return const Center(
|
||||
child: Text('Vue analytics - À implémenter'),
|
||||
);
|
||||
}
|
||||
|
||||
/// État vide
|
||||
Widget _buildEmptyState() {
|
||||
return const Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(Icons.people_outline, size: 64, color: Color(0xFF636E72)),
|
||||
SizedBox(height: 16),
|
||||
Text(
|
||||
'Aucun membre trouvé',
|
||||
style: TextStyle(fontSize: 18, color: Color(0xFF636E72)),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Pagination
|
||||
Widget _buildPagination() {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.chevron_left),
|
||||
onPressed: widget.currentPage > 0
|
||||
? () {
|
||||
AppLogger.userAction('Previous page', data: {'page': widget.currentPage - 1});
|
||||
context.read<MembresBloc>().add(LoadMembres(
|
||||
page: widget.currentPage - 1,
|
||||
size: widget.pageSize,
|
||||
));
|
||||
}
|
||||
: null,
|
||||
),
|
||||
Text('Page ${widget.currentPage + 1} / ${widget.totalPages}'),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.chevron_right),
|
||||
onPressed: widget.currentPage < widget.totalPages - 1
|
||||
? () {
|
||||
AppLogger.userAction('Next page', data: {'page': widget.currentPage + 1});
|
||||
context.read<MembresBloc>().add(LoadMembres(
|
||||
page: widget.currentPage + 1,
|
||||
size: widget.pageSize,
|
||||
));
|
||||
}
|
||||
: null,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Obtenir les membres filtrés
|
||||
List<Map<String, dynamic>> _getFilteredMembers() {
|
||||
var filtered = widget.members;
|
||||
|
||||
// Filtrer par recherche
|
||||
if (_searchQuery.isNotEmpty) {
|
||||
filtered = filtered.where((m) {
|
||||
final name = m['name'].toString().toLowerCase();
|
||||
final email = m['email'].toString().toLowerCase();
|
||||
final query = _searchQuery.toLowerCase();
|
||||
return name.contains(query) || email.contains(query);
|
||||
}).toList();
|
||||
}
|
||||
|
||||
// Filtrer par statut
|
||||
if (_selectedStatuses.isNotEmpty) {
|
||||
filtered = filtered.where((m) => _selectedStatuses.contains(m['status'])).toList();
|
||||
}
|
||||
|
||||
return filtered;
|
||||
}
|
||||
|
||||
/// Obtenir les initiales d'un nom
|
||||
String _getInitials(String name) {
|
||||
final parts = name.split(' ');
|
||||
if (parts.length >= 2) {
|
||||
return '${parts[0][0]}${parts[1][0]}'.toUpperCase();
|
||||
}
|
||||
return name.substring(0, 1).toUpperCase();
|
||||
}
|
||||
|
||||
/// Vérifier si l'utilisateur peut gérer les membres
|
||||
bool _canManageMembers(UserRole role) {
|
||||
return role.level >= UserRole.moderator.level;
|
||||
}
|
||||
|
||||
/// Afficher les détails d'un membre
|
||||
void _showMemberDetails(Map<String, dynamic> member) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: Text(member['name']),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text('Email: ${member['email']}'),
|
||||
Text('Rôle: ${member['role']}'),
|
||||
Text('Statut: ${member['status']}'),
|
||||
if (member['phone'] != null) Text('Téléphone: ${member['phone']}'),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('Fermer'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Afficher le dialogue d'ajout de membre
|
||||
void _showAddMemberDialog() {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => BlocProvider.value(
|
||||
value: context.read<MembresBloc>(),
|
||||
child: const AddMemberDialog(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Exporter les membres
|
||||
void _exportMembers() {
|
||||
// Export non encore implémenté côté mobile
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('Export des membres en cours...'),
|
||||
backgroundColor: Colors.blue,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Version améliorée de MembersPageWithData avec support de la pagination
|
||||
class MembersPageWithDataAndPagination extends StatefulWidget {
|
||||
final List<Map<String, dynamic>> members;
|
||||
final int totalCount;
|
||||
final int currentPage;
|
||||
final int totalPages;
|
||||
final Function(int page) onPageChanged;
|
||||
final VoidCallback onRefresh;
|
||||
|
||||
const MembersPageWithDataAndPagination({
|
||||
super.key,
|
||||
required this.members,
|
||||
required this.totalCount,
|
||||
required this.currentPage,
|
||||
required this.totalPages,
|
||||
required this.onPageChanged,
|
||||
required this.onRefresh,
|
||||
});
|
||||
|
||||
@override
|
||||
State<MembersPageWithDataAndPagination> createState() => _MembersPageWithDataAndPaginationState();
|
||||
}
|
||||
|
||||
class _MembersPageWithDataAndPaginationState extends State<MembersPageWithDataAndPagination> {
|
||||
final TextEditingController _searchController = TextEditingController();
|
||||
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
// Note: TabController nécessite un TickerProvider, on utilise un simple state sans mixin pour l'instant
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_searchController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return RefreshIndicator(
|
||||
onRefresh: () async {
|
||||
widget.onRefresh();
|
||||
// Attendre un peu pour l'animation
|
||||
await Future.delayed(const Duration(milliseconds: 500));
|
||||
},
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(12),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_buildHeader(),
|
||||
const SizedBox(height: 16),
|
||||
_buildMetrics(),
|
||||
const SizedBox(height: 16),
|
||||
_buildMembersList(),
|
||||
if (widget.totalPages > 1) ...[
|
||||
const SizedBox(height: 16),
|
||||
_buildPagination(),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildHeader() {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
gradient: const LinearGradient(
|
||||
colors: [Color(0xFF6C5CE7), Color(0xFF5A4FCF)],
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.people, color: Colors.white, size: 28),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'Gestion des Membres',
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 24,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'${widget.totalCount} membres au total',
|
||||
style: const TextStyle(color: Colors.white70, fontSize: 14),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildMetrics() {
|
||||
final activeCount = widget.members.where((m) => m['status'] == 'Actif').length;
|
||||
final inactiveCount = widget.members.where((m) => m['status'] == 'Inactif').length;
|
||||
|
||||
return Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: _buildMetricCard('Actifs', activeCount.toString(), Icons.check_circle, const Color(0xFF00B894)),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: _buildMetricCard('Inactifs', inactiveCount.toString(), Icons.pause_circle, const Color(0xFFFFBE76)),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildMetricCard(String label, String value, IconData icon, Color color) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
Icon(icon, color: color, size: 32),
|
||||
const SizedBox(height: 8),
|
||||
Text(value, style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold, color: color)),
|
||||
Text(label, style: const TextStyle(fontSize: 12, color: Color(0xFF636E72))),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildMembersList() {
|
||||
if (widget.members.isEmpty) {
|
||||
return const Center(
|
||||
child: Padding(
|
||||
padding: EdgeInsets.all(32.0),
|
||||
child: Text('Aucun membre trouvé'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return ListView.builder(
|
||||
shrinkWrap: true,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
itemCount: widget.members.length,
|
||||
itemBuilder: (context, index) {
|
||||
final member = widget.members[index];
|
||||
return Card(
|
||||
margin: const EdgeInsets.only(bottom: 12),
|
||||
child: ListTile(
|
||||
leading: CircleAvatar(
|
||||
backgroundColor: const Color(0xFF6C5CE7),
|
||||
child: Text(
|
||||
_getInitials(member['name']),
|
||||
style: const TextStyle(color: Colors.white),
|
||||
),
|
||||
),
|
||||
title: Text(member['name']),
|
||||
subtitle: Text(member['email']),
|
||||
trailing: _buildStatusChip(member['status']),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildStatusChip(String status) {
|
||||
Color color;
|
||||
switch (status) {
|
||||
case 'Actif':
|
||||
color = const Color(0xFF00B894);
|
||||
break;
|
||||
case 'Inactif':
|
||||
color = const Color(0xFFFFBE76);
|
||||
break;
|
||||
default:
|
||||
color = const Color(0xFF636E72);
|
||||
}
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: color.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Text(
|
||||
status,
|
||||
style: TextStyle(color: color, fontSize: 12, fontWeight: FontWeight.w500),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPagination() {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.chevron_left),
|
||||
onPressed: widget.currentPage > 0
|
||||
? () => widget.onPageChanged(widget.currentPage - 1)
|
||||
: null,
|
||||
),
|
||||
Text('Page ${widget.currentPage + 1} / ${widget.totalPages}'),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.chevron_right),
|
||||
onPressed: widget.currentPage < widget.totalPages - 1
|
||||
? () => widget.onPageChanged(widget.currentPage + 1)
|
||||
: null,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
String _getInitials(String name) {
|
||||
final parts = name.split(' ');
|
||||
if (parts.length >= 2) {
|
||||
return '${parts[0][0]}${parts[1][0]}'.toUpperCase();
|
||||
}
|
||||
return name.substring(0, 1).toUpperCase();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,267 @@
|
||||
/// 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 '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) {
|
||||
// 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());
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Message de succès après création
|
||||
if (state is MembresLoaded && state.membres.isNotEmpty) {
|
||||
// Note: On pourrait ajouter un flag dans le state pour savoir si c'est après une création
|
||||
// Pour l'instant, on ne fait rien ici
|
||||
}
|
||||
},
|
||||
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...'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// É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) {
|
||||
AppLogger.userAction('Load page', data: {'page': newPage});
|
||||
context.read<MembresBloc>().add(LoadMembres(page: newPage));
|
||||
},
|
||||
onRefresh: () {
|
||||
AppLogger.userAction('Refresh membres');
|
||||
context.read<MembresBloc>().add(const LoadMembres(refresh: true));
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
// É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, // Calcul permissions non implémenté côté backend
|
||||
'contributionScore': 0, // Pas de champ backend correspondant
|
||||
'eventsAttended': membre.nombreEvenementsParticipes,
|
||||
'projectsInvolved': 0, // Pas de champ backend correspondant
|
||||
|
||||
// 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