diff --git a/lib/main.dart b/lib/main.dart index c378ee5..c472894 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -50,7 +50,7 @@ class AppState extends StatelessWidget { ChangeNotifierProvider(create: (_) => ProfessionalFormProvider()), ChangeNotifierProxyProvider( create: (_) => ProfessionalsProvider(), - update: (_, auth, prev) => prev!..updateCity(auth.user?.city), + update: (_, auth, prev) => prev!..updateCity(auth.user?.city, userId: auth.user?.id), ), ChangeNotifierProvider(create: (_) => ServicesProvider()), ChangeNotifierProvider(create: (_) => CalendarServicesProvider()), diff --git a/lib/providers/professionals_provider.dart b/lib/providers/professionals_provider.dart index 36e3d85..6e9282b 100644 --- a/lib/providers/professionals_provider.dart +++ b/lib/providers/professionals_provider.dart @@ -6,12 +6,24 @@ class ProfessionalsProvider extends ChangeNotifier { List professionals = []; bool isLoading = true; bool _initialized = false; + String? _currentUserId; String? _locationCity; double? _locationLat; double? _locationLng; + String? _lastSearch; final _api = ApiService.instance; - void updateCity(String? city) { + void updateCity(String? city, {String? userId}) { + // Reset state when a different user logs in (prevents cross-user data leak) + if (_currentUserId != userId) { + _currentUserId = userId; + _initialized = false; + _locationCity = null; + _locationLat = null; + _locationLng = null; + _lastSearch = null; + professionals = []; + } if (!_initialized) { _initialized = true; _locationCity = city; @@ -23,15 +35,16 @@ class ProfessionalsProvider extends ChangeNotifier { if (city != null && city.isNotEmpty) _locationCity = city; _locationLat = lat; _locationLng = lng; - getProfessionals(); + getProfessionals(search: _lastSearch); } Future getProfessionals({String? search}) async { + if (search != null) _lastSearch = search.trim().isEmpty ? null : search.trim(); isLoading = true; notifyListeners(); try { final params = {}; - if (search != null && search.trim().isNotEmpty) params['search'] = search.trim(); + if (_lastSearch != null && _lastSearch!.isNotEmpty) params['search'] = _lastSearch!; if (_locationCity != null && _locationCity!.isNotEmpty) params['city'] = _locationCity!.trim(); if (_locationLat != null) params['lat'] = _locationLat.toString(); if (_locationLng != null) params['lng'] = _locationLng.toString(); diff --git a/lib/ui/views/dashboard_view.dart b/lib/ui/views/dashboard_view.dart index c5ca888..af53296 100644 --- a/lib/ui/views/dashboard_view.dart +++ b/lib/ui/views/dashboard_view.dart @@ -178,7 +178,8 @@ class _DashboardViewState extends State { .replaceAll(RegExp(r'[úù]'), 'u'); final na = normalize(a); final nb = normalize(b); - return na.contains(nb) || nb.contains(na); + // Exact match, or one is a full-word prefix of the other (handles "Bogotá D.C." vs "Bogotá") + return na == nb || na.startsWith('$nb ') || nb.startsWith('$na '); } Future _geocodeAndMoveMap(String address) async { @@ -440,6 +441,8 @@ class _DashboardViewState extends State { setState(() { _suggestions = []; _currentAddress = ''; + _detectedCity = ''; + _cityMismatch = false; }); }, )