fix: autocomplete muestra resultados de Medellín para usuario en Bucaramanga

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 <noreply@anthropic.com>
This commit is contained in:
Lizandro Guarnizo
2026-07-21 21:06:11 -05:00
co-authored by Claude Sonnet 4.6
parent 495502cfc1
commit cfd1c23fe3
+14 -12
View File
@@ -59,6 +59,9 @@ class _DashboardViewState extends State<DashboardView> {
// 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<DashboardView> {
);
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<DashboardView> {
(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<DashboardView> {
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 = <String, String>{'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);