- getProfessionals() now accepts optional search param sent to ?search= - updateCity only triggers the initial load (city no longer used as filter) - Search field debounces 450ms before firing API call - TextEditingController added so clear button also resets the field - Client-side filtering removed (API now handles it and returns top 7) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
39 lines
1.2 KiB
Dart
39 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;
|
|
bool _initialized = false;
|
|
final _api = ApiService.instance;
|
|
|
|
void updateCity(String? city) {
|
|
// Only used to trigger the initial load when auth becomes available.
|
|
if (!_initialized) {
|
|
_initialized = true;
|
|
getProfessionals();
|
|
}
|
|
}
|
|
|
|
Future<void> getProfessionals({String? search}) async {
|
|
isLoading = true;
|
|
notifyListeners();
|
|
try {
|
|
final path = (search != null && search.trim().isNotEmpty)
|
|
? '/professionals?search=${Uri.encodeComponent(search.trim())}'
|
|
: '/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();
|
|
}
|
|
}
|
|
}
|