Skip to content
Snippets Groups Projects
Commit 240d0fb6 authored by DAI Leslie's avatar DAI Leslie
Browse files
parents 0155ebf3 85101819
Branches
No related tags found
No related merge requests found
......@@ -7,12 +7,12 @@ class RechercheProfil extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.transparent,
elevation: 0, // Pas d'ombre
iconTheme: IconThemeData(color: AppColor.deepBlue),
),
body: SearchBar(), // Affichage de la barre de recherche
appBar: AppBar(
backgroundColor: Colors.transparent,
elevation: 0, // Pas d'ombre
iconTheme: IconThemeData(color: AppColor.deepBlue),
),
body: SearchBar(), // Affichage de la barre de recherche
);
}
}
......@@ -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
});
} else {
setState(() {
_isError = false; // Définir l'état de l'erreur sur false
_profiles = profil; // Mettre à jour la liste des profils
});
return; // Sortir de la méthode si le profil est vide
}
}
// 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,9 +99,26 @@ 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),
);
},
),
),
],
)
),
),
);
}
}
\ No newline at end of file
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment