Co-authored-by: eddgranados12 <eddgranados12@users.noreply.github.com>
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
This commit is contained in:
49
recolecta_app/lib/features/eta/eta_provider.dart
Normal file
49
recolecta_app/lib/features/eta/eta_provider.dart
Normal file
@@ -0,0 +1,49 @@
|
||||
// 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,
|
||||
);
|
||||
Reference in New Issue
Block a user