Hey,
Great example and thanks for that!
I am thinking how could I implement the same functionality without using Firebase. My authRepositoryProvider uses dio and hive that are initialized asynchronously in appStartupProvider.
@Riverpod(keepAlive: true)
AuthRepository authRepository(AuthRepositoryRef ref) {
final dio = ref.watch(dioControllerProvider).requireValue;
final hiveBox = ref.watch(hiveBoxProvider).requireValue;
return AuthRepository(hiveBox, dio);
}
@Riverpod(keepAlive: true)
Future<void> appStartup(AppStartupRef ref) async {
ref.onDispose(() {
ref.invalidate(pathControllerProvider);
ref.invalidate(dioControllerProvider);
ref.invalidate(hiveBoxProvider);
});
await ref.watch(pathControllerProvider.future);
await ref.watch(dioControllerProvider.future);
await ref.watch(hiveBoxProvider.future);
}
However my application crashes because those dependencies aren't ready at this point:
@riverpod
GoRouter goRouter(GoRouterRef ref) {
final appStartupState = ref.watch(appStartupProvider);
// THIS LINE BLINKS ERROR BECAUSE DIO AND HIVE ARE STILL BEING INITIALIZED
final authRepository = ref.watch(authRepositoryProvider);
...
}
Any ideas how could I refactor this so that I can listen authRepository changes like your example does?
Hey,
Great example and thanks for that!
I am thinking how could I implement the same functionality without using Firebase. My authRepositoryProvider uses dio and hive that are initialized asynchronously in appStartupProvider.
However my application crashes because those dependencies aren't ready at this point:
Any ideas how could I refactor this so that I can listen authRepository changes like your example does?