- Professionals filtered by user city + proximity (lat/lng) to selected address - ProfessionalsProvider: setLocationContext(city, lat, lng) updates filter and reloads - Dashboard: detect city mismatch after reverse geocode, block booking if wrong city - Dashboard: autocomplete biased toward user's city - Dashboard: setLocationContext called before navigating to professionals list - Dashboard: keyboard no longer shifts map layout on tablet (MediaQuery viewInsets=0) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
55 lines
1.8 KiB
Dart
55 lines
1.8 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:prosapp_web_app/models/usuario_profesional.dart';
|
|
import 'package:prosapp_web_app/services/api_service.dart';
|
|
|
|
class ProfessionalsProvider extends ChangeNotifier {
|
|
List<UsuarioProfesional> professionals = [];
|
|
bool isLoading = true;
|
|
bool _initialized = false;
|
|
String? _locationCity;
|
|
double? _locationLat;
|
|
double? _locationLng;
|
|
final _api = ApiService.instance;
|
|
|
|
void updateCity(String? city) {
|
|
if (!_initialized) {
|
|
_initialized = true;
|
|
_locationCity = city;
|
|
getProfessionals();
|
|
}
|
|
}
|
|
|
|
void setLocationContext({required String? city, required double lat, required double lng}) {
|
|
if (city != null && city.isNotEmpty) _locationCity = city;
|
|
_locationLat = lat;
|
|
_locationLng = lng;
|
|
getProfessionals();
|
|
}
|
|
|
|
Future<void> getProfessionals({String? search}) async {
|
|
isLoading = true;
|
|
notifyListeners();
|
|
try {
|
|
final params = <String, String>{};
|
|
if (search != null && search.trim().isNotEmpty) params['search'] = search.trim();
|
|
if (_locationCity != null && _locationCity!.isNotEmpty) params['city'] = _locationCity!.trim();
|
|
if (_locationLat != null) params['lat'] = _locationLat.toString();
|
|
if (_locationLng != null) params['lng'] = _locationLng.toString();
|
|
|
|
final query = params.isEmpty
|
|
? ''
|
|
: '?${params.entries.map((e) => '${e.key}=${Uri.encodeComponent(e.value)}').join('&')}';
|
|
final res = await _api.get('/professionals$query');
|
|
final list = (res is Map ? res['data'] : res) as List;
|
|
professionals = list
|
|
.map((e) => UsuarioProfesional.fromDocument(e as Map<String, dynamic>))
|
|
.toList();
|
|
} catch (e) {
|
|
print('Error obteniendo profesionales: $e');
|
|
} finally {
|
|
isLoading = false;
|
|
notifyListeners();
|
|
}
|
|
}
|
|
}
|