From cfd1c23fe3c34655d9710e7b4de80bd90ccb73fd Mon Sep 17 00:00:00 2001 From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com> Date: Tue, 21 Jul 2026 21:06:11 -0500 Subject: [PATCH] =?UTF-8?q?fix:=20autocomplete=20muestra=20resultados=20de?= =?UTF-8?q?=20Medell=C3=ADn=20para=20usuario=20en=20Bucaramanga?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Default _mapCenter era Medellín (nuevo fallback neutro) pero se usaba como bias de coordenadas en el autocomplete antes de que GPS/geocoding terminara. Ahora: - _mapPositioned=false hasta que GPS o _centerOnUserCity actualice el centro - Autocomplete omite parámetro location hasta que _mapPositioned=true - Mientras tanto, la ciudad del usuario se agrega al query de texto para biasear Co-Authored-By: Claude Sonnet 4.6 --- lib/ui/views/dashboard_view.dart | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/lib/ui/views/dashboard_view.dart b/lib/ui/views/dashboard_view.dart index bccf8e9..6206074 100644 --- a/lib/ui/views/dashboard_view.dart +++ b/lib/ui/views/dashboard_view.dart @@ -59,6 +59,9 @@ class _DashboardViewState extends State { // Throttle reverse geocode on camera idle DateTime _lastGeocode = DateTime(0); + // Indica si _mapCenter ya fue fijado por GPS o geocoding (no el default) + bool _mapPositioned = false; + // Ciudad detectada, disponibilidad y coincidencia con perfil String _detectedCity = ''; bool _cityAvailable = true; @@ -105,7 +108,7 @@ class _DashboardViewState extends State { ); final latlng = LatLng(pos.latitude, pos.longitude); - if (mounted) setState(() => _mapCenter = latlng); + if (mounted) setState(() { _mapCenter = latlng; _mapPositioned = true; }); _mapController?.animateCamera(CameraUpdate.newLatLngZoom(latlng, 16)); _reverseGeocode(latlng); } catch (_) { @@ -207,7 +210,7 @@ class _DashboardViewState extends State { (loc['lat'] as num).toDouble(), (loc['lng'] as num).toDouble(), ); - if (mounted) setState(() => _mapCenter = pos); + if (mounted) setState(() { _mapCenter = pos; _mapPositioned = true; }); _mapController?.animateCamera(CameraUpdate.newLatLngZoom(pos, 16)); } } @@ -221,17 +224,16 @@ class _DashboardViewState extends State { return; } _debounce = Timer(const Duration(milliseconds: 450), () async { - // Bias autocomplete toward user's city when not already mentioned + // Bias toward user's city: if map not yet positioned, append city to query + // and skip the coordinates bias (which would be a wrong default location) final userCity = user?.city; - final input = (userCity != null && - userCity.isNotEmpty && - !value.toLowerCase().contains(userCity.toLowerCase())) - ? '$value $userCity' - : value; - final uri = Uri.https('admin.prosapp.co', '/autocomplete', { - 'input': input, - 'location': '${_mapCenter.latitude},${_mapCenter.longitude}', - }); + final cityMissing = userCity != null && + userCity.isNotEmpty && + !value.toLowerCase().contains(userCity.toLowerCase()); + final input = cityMissing ? '$value $userCity' : value; + final params = {'input': input}; + if (_mapPositioned) params['location'] = '${_mapCenter.latitude},${_mapCenter.longitude}'; + final uri = Uri.https('admin.prosapp.co', '/autocomplete', params); final response = await NetworkUtility.fetchUrl(uri); if (response != null && mounted) { final decoded = jsonDecode(response);