From edd2cd15811dd2e24d68bc6c0adb885c86ae733f Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Thu, 28 Nov 2024 23:44:11 +0100 Subject: [PATCH] add suggesstion item wip --- covas_mobile/lib/pages/ListItemMenu.dart | 27 ++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/covas_mobile/lib/pages/ListItemMenu.dart b/covas_mobile/lib/pages/ListItemMenu.dart index 0e17203..6671630 100644 --- a/covas_mobile/lib/pages/ListItemMenu.dart +++ b/covas_mobile/lib/pages/ListItemMenu.dart @@ -44,6 +44,7 @@ class _MyHomePageState extends State { String geographicalZone = ''; String query = ''; List> suggestions = []; + List> suggestionsItem = []; TextEditingController inputGeo = TextEditingController(); TextEditingController startDatepicker = TextEditingController(); TextEditingController endDatepicker = TextEditingController(); @@ -267,6 +268,32 @@ class _MyHomePageState extends State { } } + Future searchSuggestionsByItem(String input) async { + SharedPreferences prefs = await SharedPreferences.getInstance(); + var accessToken = prefs.getString("access_token") ?? ""; + + if (accessToken.isNotEmpty) { + final url = + 'https://api.mapbox.com/geocoding/v5/mapbox.places/${input}.json?access_token=${mapboxAccessToken}&proximity=ip'; + final response = await http.get(Uri.parse(url)); + + if (response.statusCode == 200) { + final data = json.decode(response.body); + setState(() { + suggestions = (data['features'] as List) + .map((feature) => { + 'place_name': feature['place_name'], + 'geometry': feature[ + 'geometry'], // Include geometry for latitude/longitude + }) + .toList(); + }); + } else { + throw Exception('Failed to load suggestions'); + } + } + } + Future fetchPostsByLocation() async { SharedPreferences prefs = await SharedPreferences.getInstance(); var accessToken = prefs.getString("access_token") ?? "";