suggestion search by item

This commit is contained in:
Valentin CZERYBA 2024-11-30 18:45:41 +01:00
parent 559b35c7c2
commit 0977389695

View File

@ -53,6 +53,7 @@ class _MyHomePageState extends State<ListItemMenu> {
bool showDateFields = false; // State to toggle date fields bool showDateFields = false; // State to toggle date fields
bool showArrow = true; bool showArrow = true;
bool showInputSearch = true;
// Fetching events from API // Fetching events from API
static Future<List<Events>> getPosts() async { static Future<List<Events>> getPosts() async {
PermissionStatus status = await Permission.location.status; PermissionStatus status = await Permission.location.status;
@ -262,6 +263,7 @@ class _MyHomePageState extends State<ListItemMenu> {
.toList(); .toList();
if (suggestions.isNotEmpty) { if (suggestions.isNotEmpty) {
showArrow = false; showArrow = false;
showInputSearch = false;
} }
}); });
} else { } else {
@ -336,11 +338,15 @@ class _MyHomePageState extends State<ListItemMenu> {
}); });
if (response.statusCode == 200) { if (response.statusCode == 200) {
final data = json.decode(response.body); final data = json.decode(utf8.decode(response.bodyBytes));
setState(() { setState(() {
suggestionsItem = (data as List) suggestionsItem = (data as List)
.map((feature) => {'name': feature['name']}) .map((feature) => {'name': feature['name']})
.toList(); .toList();
if (suggestionsItem.isNotEmpty) {
showDateFields = false;
showArrow = false;
}
}); });
print("status code : ${response.statusCode}"); print("status code : ${response.statusCode}");
} }
@ -449,7 +455,8 @@ class _MyHomePageState extends State<ListItemMenu> {
inputGeo.clear(); // Clear the text field inputGeo.clear(); // Clear the text field
geographicalZone = ''; // Reset the geographical zone state geographicalZone = ''; // Reset the geographical zone state
suggestions.clear(); suggestions.clear();
showArrow = true; // Optionally clear suggestions showArrow = true;
showInputSearch = true; // Optionally clear suggestions
/// Clear the filtered posts /// Clear the filtered posts
}); });
fetchPostsByLocation(); fetchPostsByLocation();
@ -471,6 +478,7 @@ class _MyHomePageState extends State<ListItemMenu> {
geographicalZone = ''; // Reset the geographical zone state geographicalZone = ''; // Reset the geographical zone state
suggestions.clear(); // Optionally clear suggestions suggestions.clear(); // Optionally clear suggestions
showArrow = true; showArrow = true;
showInputSearch = true;
/// Clear the filted posts /// Clear the filted posts
}); });
@ -502,6 +510,7 @@ class _MyHomePageState extends State<ListItemMenu> {
inputGeo.text = geographicalZone; inputGeo.text = geographicalZone;
suggestions.clear(); suggestions.clear();
showArrow = true; showArrow = true;
showInputSearch = true;
}); });
SharedPreferences prefs = SharedPreferences prefs =
await SharedPreferences.getInstance(); await SharedPreferences.getInstance();
@ -534,7 +543,9 @@ class _MyHomePageState extends State<ListItemMenu> {
setState(() { setState(() {
inputItem.clear(); inputItem.clear();
itemName = ''; // Reset the geographical zone state itemName = ''; // Reset the geographical zone state
suggestionsItem.clear(); // suggestionsItem.clear();
showDateFields = true;
showArrow = true;
}); });
fetchPostsByLocation(); fetchPostsByLocation();
}, },
@ -550,7 +561,9 @@ class _MyHomePageState extends State<ListItemMenu> {
setState(() { setState(() {
inputItem.clear(); // Clear the text field inputItem.clear(); // Clear the text field
itemName = ''; // Reset the geographical zone state itemName = ''; // Reset the geographical zone state
suggestionsItem.clear(); // Optionally clear suggestions suggestionsItem.clear();
showDateFields = true;
showArrow = true; // Optionally clear suggestions
/// Clear the filted posts /// Clear the filted posts
}); });
@ -575,6 +588,8 @@ class _MyHomePageState extends State<ListItemMenu> {
itemName = suggestionsItem[index]['name']; itemName = suggestionsItem[index]['name'];
inputItem.text = itemName; inputItem.text = itemName;
suggestionsItem.clear(); suggestionsItem.clear();
showDateFields = true;
showArrow = true;
}); });
await fetchPostsByLocation(); await fetchPostsByLocation();
}, },
@ -602,7 +617,7 @@ class _MyHomePageState extends State<ListItemMenu> {
), ),
body: Column( body: Column(
children: [ children: [
if (showArrow) _buildItemZoneSearchField(), if (showInputSearch) _buildItemZoneSearchField(),
if ((showDateFields) && (showArrow)) if ((showDateFields) && (showArrow))
Row( Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,