diff --git a/lib/ui/views/dashboard_view.dart b/lib/ui/views/dashboard_view.dart index 3a70e41..b0deec6 100644 --- a/lib/ui/views/dashboard_view.dart +++ b/lib/ui/views/dashboard_view.dart @@ -7,6 +7,7 @@ import 'package:http/http.dart' as http; import 'package:intl/intl.dart'; import 'package:prosapp_web_app/models/schedules_entity.dart'; import 'package:prosapp_web_app/models/service.dart'; +import 'package:prosapp_web_app/models/location_preferences.dart'; import 'package:prosapp_web_app/models/service_location_preferences.dart'; import 'package:prosapp_web_app/models/service_status.dart'; import 'package:prosapp_web_app/models/usuario.dart'; @@ -118,9 +119,65 @@ class _DashboardViewState extends State { } } + static const Map _colombiaCityCoords = { + 'bucaramanga': LatLng(7.1198, -73.1227), + 'bogota': LatLng(4.7110, -74.0721), + 'medellin': LatLng(6.2442, -75.5812), + 'cali': LatLng(3.4516, -76.5320), + 'barranquilla': LatLng(10.9639, -74.7964), + 'cartagena': LatLng(10.3932, -75.4832), + 'cucuta': LatLng(7.8939, -72.5078), + 'pereira': LatLng(4.8087, -75.6906), + 'manizales': LatLng(5.0703, -75.5138), + 'santa marta': LatLng(11.2408, -74.1990), + 'ibague': LatLng(4.4389, -75.2322), + 'villavicencio': LatLng(4.1420, -73.6266), + 'pasto': LatLng(1.2136, -77.2811), + 'monteria': LatLng(8.7575, -75.8845), + 'neiva': LatLng(2.9273, -75.2819), + 'armenia': LatLng(4.5339, -75.6811), + 'sincelejo': LatLng(9.3047, -75.3978), + 'tunja': LatLng(5.5353, -73.3678), + 'floridablanca': LatLng(7.0640, -73.0868), + 'giron': LatLng(7.0730, -73.1701), + 'piedecuesta': LatLng(6.9907, -73.0494), + 'soledad': LatLng(10.9200, -74.7647), + 'bello': LatLng(6.3367, -75.5572), + 'soacha': LatLng(4.5797, -74.2172), + 'buenaventura': LatLng(3.8833, -77.0311), + 'valledupar': LatLng(10.4779, -73.2536), + 'palmira': LatLng(3.5394, -76.3035), + 'popayan': LatLng(2.4448, -76.6147), + 'riohacha': LatLng(11.5444, -72.9072), + 'quibdo': LatLng(5.6940, -76.6583), + }; + + LatLng? _cityFallbackCoords(String city) { + String norm(String s) => s.toLowerCase().trim() + .replaceAll(RegExp(r'[áà]'), 'a').replaceAll(RegExp(r'[éè]'), 'e') + .replaceAll(RegExp(r'[íì]'), 'i').replaceAll(RegExp(r'[óò]'), 'o') + .replaceAll(RegExp(r'[úù]'), 'u').replaceAll('.', '').replaceAll(',', ''); + final normalized = norm(city); + for (final entry in _colombiaCityCoords.entries) { + if (normalized == entry.key || normalized.startsWith('${entry.key} ') || entry.key.startsWith('$normalized ')) { + return entry.value; + } + } + return null; + } + Future _centerOnUserCity() async { final city = user?.city; if (city == null || city.isEmpty) return; + + // Apply hardcoded fallback immediately so the map never loads on the wrong city + final fallback = _cityFallbackCoords(city); + if (fallback != null && mounted) { + setState(() { _mapCenter = fallback; _mapPositioned = true; }); + _mapController?.animateCamera(CameraUpdate.newLatLngZoom(fallback, 14)); + } + + // Then try geocoding for a more precise position await _geocodeAndMoveMap(city); } @@ -255,6 +312,21 @@ class _DashboardViewState extends State { _geocodeAndMoveMap(address); } + Future _selectProfessionalFromMarker(UsuarioProfesional prof) async { + try { + final result = await NavigationService.navigateToFuture( + '/dashboard/calendar/${prof.user.id}', + ); + if (result is List && result.length >= 2) { + setState(() { + _professional = prof; + _selectedDay = result[0] as DateTime; + _selectedHour = result[1] as TimeOfDay; + }); + } + } catch (_) {} + } + Future _selectProfessional() async { try { // Pass current location context to professionals list before navigating @@ -361,6 +433,27 @@ class _DashboardViewState extends State { final hintColor = isDark ? Colors.white38 : Colors.grey; final inputFill = isDark ? const Color(0xFF0F172A) : Colors.white; + // Marcadores de consultorios: profesionales con coordenadas reales y atención presencial + final professionalsProvider = context.watch(); + final officeMarkers = {}; + for (final prof in professionalsProvider.professionals) { + final lat = prof.professionalInfo.latitude; + final lng = prof.professionalInfo.longitude; + if (lat == 0.0 && lng == 0.0) continue; + final prefs = prof.professionalInfo.locationPreferences; + if (prefs == LocationPreferences.delivery) continue; + officeMarkers.add(Marker( + markerId: MarkerId(prof.professionalInfo.id), + position: LatLng(lat, lng), + icon: BitmapDescriptor.defaultMarkerWithHue(BitmapDescriptor.hueAzure), + infoWindow: InfoWindow( + title: prof.user.name, + snippet: prof.professionalInfo.profession, + ), + onTap: () => _selectProfessionalFromMarker(prof), + )); + } + return MediaQuery( // Prevent keyboard from shifting the map+card layout on tablets data: MediaQuery.of(context).copyWith(viewInsets: EdgeInsets.zero), @@ -381,6 +474,7 @@ class _DashboardViewState extends State { myLocationEnabled: true, myLocationButtonEnabled: false, zoomControlsEnabled: false, + markers: officeMarkers, ) else Container(