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:
co-authored by
Claude Sonnet 4.6
parent
495502cfc1
commit
cfd1c23fe3
@@ -59,6 +59,9 @@ class _DashboardViewState extends State<DashboardView> {
|
|||||||
// Throttle reverse geocode on camera idle
|
// Throttle reverse geocode on camera idle
|
||||||
DateTime _lastGeocode = DateTime(0);
|
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
|
// Ciudad detectada, disponibilidad y coincidencia con perfil
|
||||||
String _detectedCity = '';
|
String _detectedCity = '';
|
||||||
bool _cityAvailable = true;
|
bool _cityAvailable = true;
|
||||||
@@ -105,7 +108,7 @@ class _DashboardViewState extends State<DashboardView> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
final latlng = LatLng(pos.latitude, pos.longitude);
|
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));
|
_mapController?.animateCamera(CameraUpdate.newLatLngZoom(latlng, 16));
|
||||||
_reverseGeocode(latlng);
|
_reverseGeocode(latlng);
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
@@ -207,7 +210,7 @@ class _DashboardViewState extends State<DashboardView> {
|
|||||||
(loc['lat'] as num).toDouble(),
|
(loc['lat'] as num).toDouble(),
|
||||||
(loc['lng'] 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));
|
_mapController?.animateCamera(CameraUpdate.newLatLngZoom(pos, 16));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -221,17 +224,16 @@ class _DashboardViewState extends State<DashboardView> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_debounce = Timer(const Duration(milliseconds: 450), () async {
|
_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 userCity = user?.city;
|
||||||
final input = (userCity != null &&
|
final cityMissing = userCity != null &&
|
||||||
userCity.isNotEmpty &&
|
userCity.isNotEmpty &&
|
||||||
!value.toLowerCase().contains(userCity.toLowerCase()))
|
!value.toLowerCase().contains(userCity.toLowerCase());
|
||||||
? '$value $userCity'
|
final input = cityMissing ? '$value $userCity' : value;
|
||||||
: value;
|
final params = <String, String>{'input': input};
|
||||||
final uri = Uri.https('admin.prosapp.co', '/autocomplete', {
|
if (_mapPositioned) params['location'] = '${_mapCenter.latitude},${_mapCenter.longitude}';
|
||||||
'input': input,
|
final uri = Uri.https('admin.prosapp.co', '/autocomplete', params);
|
||||||
'location': '${_mapCenter.latitude},${_mapCenter.longitude}',
|
|
||||||
});
|
|
||||||
final response = await NetworkUtility.fetchUrl(uri);
|
final response = await NetworkUtility.fetchUrl(uri);
|
||||||
if (response != null && mounted) {
|
if (response != null && mounted) {
|
||||||
final decoded = jsonDecode(response);
|
final decoded = jsonDecode(response);
|
||||||
|
|||||||
Reference in New Issue
Block a user