Co-authored-by: Azareth-Tr <Azareth-Tr@users.noreply.github.com> Co-authored-by: eddgranados12 <eddgranados12@users.noreply.github.com> implementacion de login, vistas, correcion de errores en vista registro, domicilios
41 lines
1.7 KiB
Dart
41 lines
1.7 KiB
Dart
// lib/features/eta/eta_provider.dart
|
|
// Riverpod AsyncNotifier: carga ETA al abrir la app y al recibir push FCM.
|
|
// No hace polling continuo.
|
|
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'eta_model.dart';
|
|
import 'eta_service.dart';
|
|
|
|
// ──────────────────────────────────────────
|
|
// Provider del addressId activo del ciudadano
|
|
// (se puebla en el provider de auth/session)
|
|
// ──────────────────────────────────────────
|
|
final activeAddressIdProvider = StateProvider<String?>((ref) => null);
|
|
|
|
// ──────────────────────────────────────────
|
|
// AsyncNotifier principal de ETA
|
|
// ──────────────────────────────────────────
|
|
class EtaNotifier extends AsyncNotifier<EtaResponse> {
|
|
@override
|
|
Future<EtaResponse> build() async {
|
|
final addressId = ref.watch(activeAddressIdProvider);
|
|
if (addressId == null) {
|
|
throw Exception('No hay domicilio verificado');
|
|
}
|
|
return ref.read(etaServiceProvider).fetchEta(addressId);
|
|
}
|
|
|
|
/// Llamar desde la UI (botón refrescar) o desde el handler de FCM.
|
|
Future<void> refresh() async {
|
|
state = const AsyncLoading();
|
|
final addressId = ref.read(activeAddressIdProvider);
|
|
if (addressId == null) return;
|
|
state = await AsyncValue.guard(
|
|
() => ref.read(etaServiceProvider).fetchEta(addressId),
|
|
);
|
|
}
|
|
}
|
|
|
|
final etaProvider = AsyncNotifierProvider<EtaNotifier, EtaResponse>(
|
|
EtaNotifier.new,
|
|
); |