fix: corregir flujo completo de servicio y geocodificación

- Service.fromJson: lat/lng con Decimal de Prisma llegaban como string y
  el cast 'as num?' lanzaba TypeError silencioso → lista de servicios vacía.
  Mismo patrón que average_score, fix: double.tryParse(?.toString())
- service_status: agregar enumToStringService que mapea el enum de Flutter
  al string que espera el DTO del backend ('pending','accepted', etc.).
  changeServiceStatus enviaba el índice entero → @IsEnum rechazaba → el
  profesional no podía aceptar ni rechazar solicitudes
- maps_service: agregar MapsService.reverseGeocode que usa el Geocoder del
  Maps JS SDK ya cargado, sin requerir la Geocoding API habilitada por separado
- dashboard_view: _reverseGeocode usa el JS Geocoder en vez del endpoint HTTP

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Lizandro Guarnizo
2026-07-22 09:15:59 -05:00
co-authored by Claude Sonnet 4.6
parent 8296b5a3ea
commit 735d8c2ba0
5 changed files with 103 additions and 44 deletions
+23 -35
View File
@@ -182,47 +182,35 @@ class _DashboardViewState extends State<DashboardView> {
}
Future<void> _reverseGeocode(LatLng pos) async {
if (_mapsApiKey == null || _mapsApiKey!.isEmpty) return;
final now = DateTime.now();
if (now.difference(_lastGeocode).inMilliseconds < 800) return;
_lastGeocode = now;
setState(() => _geocoding = true);
if (mounted) setState(() => _geocoding = true);
try {
final res = await http.get(Uri.parse(
'https://maps.googleapis.com/maps/api/geocode/json'
'?latlng=${pos.latitude},${pos.longitude}'
'&key=$_mapsApiKey&language=es',
));
if (res.statusCode == 200) {
final data = jsonDecode(res.body);
final results = data['results'] as List?;
if (results != null && results.isNotEmpty) {
final address = results[0]['formatted_address'] as String;
final components = results[0]['address_components'] as List? ?? [];
final city = _extractCity(components);
// Use Maps JS SDK Geocoder — works with the same API key as the map,
// no separate Geocoding API billing required
final result = await MapsService.reverseGeocode(pos.latitude, pos.longitude);
if (result != null && mounted) {
final city = _extractCity(result.addressComponents);
final citiesProvider = Provider.of<CitiesProvider>(context, listen: false);
final available = city.isEmpty || citiesProvider.isCityAvailable(city);
final userCity = user?.city ?? '';
final mismatch = userCity.isNotEmpty && city.isNotEmpty && !_citiesMatch(city, userCity);
final citiesProvider = Provider.of<CitiesProvider>(context, listen: false);
final available = city.isEmpty || citiesProvider.isCityAvailable(city);
final userCity = user?.city ?? '';
final mismatch = userCity.isNotEmpty && city.isNotEmpty && !_citiesMatch(city, userCity);
if (mounted) {
setState(() {
_currentAddress = address;
_searchController.text = address;
_detectedCity = city;
_cityAvailable = available;
_cityMismatch = mismatch;
});
if (!mismatch && city.isNotEmpty) {
context.read<ProfessionalsProvider>().setLocationContext(
city: city,
lat: pos.latitude,
lng: pos.longitude,
);
}
}
setState(() {
_currentAddress = result.formattedAddress;
_searchController.text = result.formattedAddress;
_detectedCity = city;
_cityAvailable = available;
_cityMismatch = mismatch;
});
if (!mismatch && city.isNotEmpty) {
context.read<ProfessionalsProvider>().setLocationContext(
city: city,
lat: pos.latitude,
lng: pos.longitude,
);
}
}
} catch (_) {}