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);