recherche par tags terminé

This commit is contained in:
Valentin CZERYBA 2024-12-28 14:47:39 +01:00
parent 48c785c586
commit 0df538ef46

View File

@ -325,6 +325,10 @@ class _MyHomePageState extends State<ListItemMenu> {
stringParameter = stringParameter + "&item=${inputItem.text}";
endpoint = "events/search";
}
if (inputTags.text.isNotEmpty) {
stringParameter = stringParameter + "&tags=${inputTags.text}";
endpoint = "events/search";
}
if (stringParameter.isNotEmpty) {
stringParameter = "$stringParameter&$dateParameter";
} else {
@ -370,20 +374,22 @@ class _MyHomePageState extends State<ListItemMenu> {
"Content-Type": "application/json",
HttpHeaders.cookieHeader: "access_token=$accessToken"
});
print("status code tags : ${response.statusCode}");
if (response.statusCode == 200) {
final data = json.decode(utf8.decode(response.bodyBytes));
print("tags ${data}");
setState(() {
suggestionsTags = (data as List)
.map((feature) => {'name': feature['name']})
.toList();
print("suggesttion tag : ${suggestionsTags}");
if (suggestionsTags.isNotEmpty) {
showInputGeo = false;
showInputSearch = false;
showArrow = false;
}
});
print("status code : ${response.statusCode}");
}
}
}
@ -398,6 +404,7 @@ class _MyHomePageState extends State<ListItemMenu> {
"Content-Type": "application/json",
HttpHeaders.cookieHeader: "access_token=$accessToken"
});
print("status code : ${response.statusCode}");
if (response.statusCode == 200) {
final List<dynamic> body = json.decode(utf8.decode(response.bodyBytes));
@ -595,9 +602,17 @@ class _MyHomePageState extends State<ListItemMenu> {
),
onChanged: (value) {
if (value.isNotEmpty) {
setState(() {
itemTags = value;
searchSuggestionsByTag(value);
});
} else {
setState(() {
inputTags.clear(); // Clear the text field
inputTags.clear();
showArrow = true;
showInputSearch = true;
showInputGeo = true; // Optionally clear suggestions
itemTags = ''; // Clear the text field
/// Clear the filted posts
});
@ -613,7 +628,7 @@ class _MyHomePageState extends State<ListItemMenu> {
),
child: ListView.builder(
shrinkWrap: true,
itemCount: suggestions.length,
itemCount: suggestionsTags.length,
itemBuilder: (context, index) {
return ListTile(
title: Text(suggestionsTags[index]['name']),
@ -626,6 +641,7 @@ class _MyHomePageState extends State<ListItemMenu> {
showInputSearch = true;
showInputGeo = true;
});
await fetchPostsByLocation();
},
);
},