fix: autocompletado de direcciones
- Quitar replaceAll(' ', '_') que rompia la query
- Pasar coordenadas actuales del mapa como location bias
- Soportar formatted_address y description en respuesta
- Manejar results o predictions como clave raiz
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
1fd29bbfdd
commit
d5be8d6f6b
@@ -165,11 +165,14 @@ class _DashboardViewState extends State<DashboardView> {
|
|||||||
}
|
}
|
||||||
_debounce = Timer(const Duration(milliseconds: 450), () async {
|
_debounce = Timer(const Duration(milliseconds: 450), () async {
|
||||||
final uri = Uri.https('admin.prosapp.co', '/autocomplete', {
|
final uri = Uri.https('admin.prosapp.co', '/autocomplete', {
|
||||||
'input': value.replaceAll(' ', '_'),
|
'input': value,
|
||||||
|
'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) {
|
||||||
setState(() => _suggestions = jsonDecode(response)['results'] ?? []);
|
final decoded = jsonDecode(response);
|
||||||
|
final results = decoded['results'] ?? decoded['predictions'] ?? [];
|
||||||
|
setState(() => _suggestions = results is List ? results : []);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -388,7 +391,8 @@ class _DashboardViewState extends State<DashboardView> {
|
|||||||
),
|
),
|
||||||
child: Column(
|
child: Column(
|
||||||
children: _suggestions.take(5).toList().asMap().entries.map((e) {
|
children: _suggestions.take(5).toList().asMap().entries.map((e) {
|
||||||
final addr = e.value['formatted_address'] as String? ?? '';
|
final item = e.value as Map<String, dynamic>;
|
||||||
|
final addr = (item['formatted_address'] ?? item['description'] ?? item['name'] ?? '').toString();
|
||||||
final isLast = e.key == (_suggestions.length - 1).clamp(0, 4);
|
final isLast = e.key == (_suggestions.length - 1).clamp(0, 4);
|
||||||
return Column(
|
return Column(
|
||||||
children: [
|
children: [
|
||||||
|
|||||||
Reference in New Issue
Block a user