-
-
Notifications
You must be signed in to change notification settings - Fork 152
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Scope race conditions #316
Comments
GetIt.I.getIt.registerSingleton(YetAnotherController()); isn't there one getIt to much in there? |
Oh, that's a typo. |
have you checked the get_it_mixin with it's pushScope method? |
No, I didn't. Could it solve my problem? |
not 100% sure. are you aware, that all the pop functions are async and return a Future? |
As far as I can see, pushScope method of GoRoute(
path: '/profile',
builder: (context, state) => const ProfileScreen(),
onInit: () => GetIt.pushNewScope(init: (getIt) { getIt.registerSingleton(ProfileController());} )
onDispose: () => GetIt.popScope();
), Also, |
yes, you are right. I think the problem is that |
OK, sometimes it takes time to fully understand the problem that people have. The obvious solution is #292. |
Included in just pushed V7.5.0 |
@escamoteur I checked out the new function. GoRoute(
path: '/profile',
builder: (context, state) => const ProfileScreen(),
onInit: () {
getIt.pushNewScope(scopeName: 'scope1');
getIt.registerSingleton(Foo());
}
onDispose: () {
getIt.dropScope('scope1')
}),
GoRoute(
path: '/details',
builder: (context, state) => const DetailsScreen(),
onInit: () => getIt.registerSingleton(Bar());
} On navigating from /profile screen to the /details screen: |
I pop scope on widget dispose and register a new singleton on a new screen open.
But the new singleton gets into the old scope which would got disposed in a next frame. That's because of screens transitions which has not finished, thus old screen's dispose function has called a bit later than new screen's initState.
I couldn't figure out for a long time why my new singleton disappears!
Proposal:
GetIt.pushNewScope()
andGetIt.popScope()
shouldn't be imperative.Force user to register singletons inside of pushNewScope callback
User should pop scope only by name or by instance:
also related issues #313, #303
The text was updated successfully, but these errors were encountered: