Co-authored-by: MENDOZA BALLARDO GAEL RICARDO <gael-meb123@users.noreply.github.com> Co-authored-by: Azareth-Tr <Azareth-Tr@users.noreply.github.com> modificacion de vistas panel admin, login, animaciones y implementacion de mascota
50 lines
1.9 KiB
Dart
50 lines
1.9 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 'package:recolecta_app/features/eta/eta_model.dart';
|
|
import 'package:recolecta_app/features/eta/eta_service.dart';
|
|
|
|
// ──────────────────────────────────────────
|
|
// Provider del addressId activo del ciudadano
|
|
// (se puebla en el provider de auth/session)
|
|
// ──────────────────────────────────────────
|
|
class ActiveAddressIdNotifier extends Notifier<String?> {
|
|
@override
|
|
String? build() => null;
|
|
}
|
|
|
|
final activeAddressIdProvider =
|
|
NotifierProvider<ActiveAddressIdNotifier, String?>(
|
|
ActiveAddressIdNotifier.new,
|
|
);
|
|
|
|
// ──────────────────────────────────────────
|
|
// 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,
|
|
);
|