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