updateCity skipped getProfessionals() when both _city and the incoming city were null (null != null = false). Added _initialized flag so the first call always triggers the load regardless of city value. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
41 lines
1.2 KiB
Dart
41 lines
1.2 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;
|
|
String? _city;
|
|
bool _initialized = false;
|
|
final _api = ApiService.instance;
|
|
|
|
void updateCity(String? city) {
|
|
// Always load on first auth event; afterwards only reload when city changes.
|
|
if (!_initialized || _city != city) {
|
|
_initialized = true;
|
|
_city = city;
|
|
getProfessionals();
|
|
}
|
|
}
|
|
|
|
getProfessionals() async {
|
|
isLoading = true;
|
|
notifyListeners();
|
|
try {
|
|
final path = (_city != null && _city!.isNotEmpty)
|
|
? '/professionals?city=${Uri.encodeComponent(_city!)}'
|
|
: '/professionals';
|
|
final res = await _api.get(path);
|
|
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();
|
|
}
|
|
}
|
|
}
|