-
-
Notifications
You must be signed in to change notification settings - Fork 153
Register lazy singleton that depends on async lazy singleton #126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
use registerSingletonWithDependencies for the two latter ones |
Thanks for hint get.registerSingletonAsync<SharedPreferences>(
() => SharedPreferences.getInstance());
get.registerSingletonWithDependencies<IPreferences>(
() => Preferences(get<SharedPreferences>()),
dependsOn: [SharedPreferences]);
get.registerSingletonWithDependencies<UserPreferences>(
() => UserPreferences(get<IPreferences>()),
dependsOn: [IPreferences]);
then later: void _checkToshowOnboardingPage(BuildContext context) async {
await getIt.isReady<UserPreferences>();
final userPreferences = getIt.get<UserPreferences>();
.
.
.
}
so this way I ensure |
Great that this worked for you.
final userPreferences = getIt<UserPreferences>(); |
👍 Thanks for supporting this great library 😉 |
Ok will make this more clear! |
Uh oh!
There was an error while loading. Please reload this page.
OK, the title maybe is confusing but here it is the dependency:
UserPreferences --> IPreferences __> Preferences --> SharedPreferences
I have setup this in main function:
But when when I try to access
getIt<UserPreferences>()
get_it
complains I tried to access an instance ofSharedPreferences
that was not easy yet.how can I solve this async dependency?
The text was updated successfully, but these errors were encountered: