bizz84 / bizz84/starter_architecture_flutter_firebase

AuthRepository that depends on asynchronous providers

Open
#153 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Dart
Stars
1.8k
Forks
488
PR merge metrics
No merged PRs in 30d

Description

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 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?

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by tracing appStartupProvider, dioControllerProvider, hiveBoxProvider, authRepositoryProvider, and goRouter to understand their initialization order. Refactor the provider relationships so goRouter does not read unavailable dependencies during startup, then verify the application starts without the crash and authRepository changes remain listenable.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart, firebase, flutter
Domain
authentication, mobile
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.