From b2e70802657d5f2501d7a7e0f997d715019e8e77 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Sat, 28 Dec 2024 15:03:55 +0100 Subject: [PATCH] change suggestions list for input geo --- covas_mobile/lib/pages/ListItemMenu.dart | 28 ++++++++++++------------ 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/covas_mobile/lib/pages/ListItemMenu.dart b/covas_mobile/lib/pages/ListItemMenu.dart index 7f42243..da85d5c 100644 --- a/covas_mobile/lib/pages/ListItemMenu.dart +++ b/covas_mobile/lib/pages/ListItemMenu.dart @@ -46,7 +46,7 @@ class _MyHomePageState extends State { String itemName = ''; String itemTags = ''; String query = ''; - List> suggestions = []; + List> suggestionsGeo = []; List> suggestionsItem = []; List> suggestionsTags = []; TextEditingController inputGeo = TextEditingController(); @@ -249,7 +249,7 @@ class _MyHomePageState extends State { return ''; } - Future searchSuggestions(String input) async { + Future searchSuggestionsGeo(String input) async { await dotenv.load(fileName: ".env"); // Load .env file final mapboxAccessToken = dotenv.env['MAPBOX_ACCESS_TOKEN'] ?? ''; @@ -260,14 +260,14 @@ class _MyHomePageState extends State { if (response.statusCode == 200) { final data = json.decode(response.body); setState(() { - suggestions = (data['features'] as List) + suggestionsGeo = (data['features'] as List) .map((feature) => { 'place_name': feature['place_name'], 'geometry': feature[ 'geometry'], // Include geometry for latitude/longitude }) .toList(); - if (suggestions.isNotEmpty) { + if (suggestionsGeo.isNotEmpty) { showArrow = false; showInputSearch = false; showInputTag = false; @@ -501,7 +501,7 @@ class _MyHomePageState extends State { inputGeo.clear(); // Clear the text field geographicalZone = ''; // Reset the geographical zone state - suggestions.clear(); + suggestionsGeo.clear(); showArrow = true; showInputSearch = true; // Optionally clear suggestions @@ -516,7 +516,7 @@ class _MyHomePageState extends State { if (value.isNotEmpty) { setState(() { geographicalZone = value; - searchSuggestions(value); + searchSuggestionsGeo(value); }); } else { SharedPreferences prefs = await SharedPreferences.getInstance(); @@ -525,7 +525,7 @@ class _MyHomePageState extends State { setState(() { inputGeo.clear(); // Clear the text field geographicalZone = ''; // Reset the geographical zone state - suggestions.clear(); // Optionally clear suggestions + suggestionsGeo.clear(); // Optionally clear suggestions showArrow = true; showInputSearch = true; showInputTag = true; @@ -536,7 +536,7 @@ class _MyHomePageState extends State { } }, ), - if (suggestions.isNotEmpty) + if (suggestionsGeo.isNotEmpty) Container( height: 200, decoration: BoxDecoration( @@ -545,20 +545,20 @@ class _MyHomePageState extends State { ), child: ListView.builder( shrinkWrap: true, - itemCount: suggestions.length, + itemCount: suggestionsGeo.length, itemBuilder: (context, index) { return ListTile( - title: Text(suggestions[index]['place_name']), + title: Text(suggestionsGeo[index]['place_name']), onTap: () async { final latitude = - suggestions[index]['geometry']['coordinates'][1]; + suggestionsGeo[index]['geometry']['coordinates'][1]; final longitude = - suggestions[index]['geometry']['coordinates'][0]; + suggestionsGeo[index]['geometry']['coordinates'][0]; setState(() { - geographicalZone = suggestions[index]['place_name']; + geographicalZone = suggestionsGeo[index]['place_name']; inputGeo.text = geographicalZone; - suggestions.clear(); + suggestionsGeo.clear(); showArrow = true; showInputSearch = true; showInputTag = true;