Skip to content
Snippets Groups Projects
Commit 85101819 authored by RENAULT Juliette's avatar RENAULT Juliette
Browse files

modif recherche profil pour que ce soit plus utilisable

parent 383ab573
No related branches found
No related tags found
No related merge requests found
......@@ -25,6 +25,7 @@ class SearchBar extends StatefulWidget {
class _SearchBarState extends State<SearchBar> {
TextEditingController _controller = TextEditingController();
bool _isError = false; // Variable pour suivre l'état de l'erreur
List<Map<String, dynamic>> _profiles = []; // Liste des profils trouvés
void _search() async {
// Récupération des données
......@@ -33,21 +34,26 @@ class _SearchBarState extends State<SearchBar> {
// Récupération du profil
DatabaseService recherche = DatabaseService();
Future<List<Map<String, dynamic>>> profil = recherche.searchProfiles(searchText);
List<Map<String, dynamic>> profil = await recherche.searchProfiles(searchText);
// Vérifier si le profil est vide
final isEmpty = (await profil).isEmpty;
if (isEmpty) {
if (profil.isEmpty) {
setState(() {
_isError = true; // Définir l'état de l'erreur sur true
_profiles = []; // Vider la liste des profils
});
return; // Sortir de la méthode si le profil est vide
} else {
setState(() {
_isError = false; // Définir l'état de l'erreur sur false
_profiles = profil; // Mettre à jour la liste des profils
});
}
}
// Affichage du profil en utilisant Navigator pour naviguer vers une nouvelle page
void _navigateToProfile(Map<String, dynamic> profile) {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => Profil(profil: profil)),
MaterialPageRoute(builder: (context) => Profil(profil: Future.value([profile]))),
);
}
......@@ -60,7 +66,10 @@ class _SearchBarState extends State<SearchBar> {
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
const Text('Rechercher un profil', style: TextStyle(color: AppColor.violetBlue, fontSize: 30, fontWeight: FontWeight.bold),),
const Text(
'Rechercher un profil',
style: TextStyle(color: AppColor.violetBlue, fontSize: 30, fontWeight: FontWeight.bold),
),
SizedBox(height: 8.0), // Espacement entre le texte et la case de recherche
Row(
mainAxisAlignment: MainAxisAlignment.center,
......@@ -90,8 +99,25 @@ class _SearchBarState extends State<SearchBar> {
),
],
),
SizedBox(height: 16.0), // Espacement entre la barre de recherche et la liste de résultats
Expanded(
child: _profiles.isEmpty && !_isError
? Center(child: Text('Aucun profil trouvé'))
: ListView.builder(
itemCount: _profiles.length,
itemBuilder: (context, index) {
final profile = _profiles[index];
final nom = profile['nom'] ?? 'Nom inconnu';
final prenom = profile['prenom'] ?? 'Prénom inconnu';
return ListTile(
title: Text('$nom $prenom'),
onTap: () => _navigateToProfile(profile),
);
},
),
),
],
)
),
),
);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment