-
-
Notifications
You must be signed in to change notification settings - Fork 153
Widget Lifecycle and Scope Disposal Navigation Issue #247
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
Hi, indeed, GetIt scopes are not ideal for what you are trying to do. for me, Scopes are not so much to be used in the connection of UI states but with states of your business logic. Like "no user logged in" -> "user logged in" or "new shopping cart created" Maybe my talk on get_it might be helpful https://www.youtube.com/watch?v=YJ52kSfSMyM&list=PL-BFoWYMGZ2TvwY0uf1fBJB1358utBlAz&index=10 Can you elaborate why you register objects just for the the livetime of one Screen? Maybe I have a better approach? |
So my goal is to register scopes by feature and not necessarily for each screen. For example, one of my features is a buy transaction workflow composed of multiple screens. Each screen in the workflow is injected with a store that makes sharing data across screens easier. When the user completes the workflow, I'd like to pop the scope to dispose of any dependencies registered within it. I'm currently using the initState/dispose methods of the first screen in the feature to manage the scope. I realize this probably isn't a great way to go about scope management. Another idea I had was to potentially use a hook on Flutter navigation routes but wasn't sure if this approach would work either. Sorry, I realize now the example I gave when I opened the ticket didn't make it clear I was trying to scope by feature. Do you have an approach you can recommend for scoping by feature? Also, thanks for linking your talk (and your library)! Lots of valuable information in there. |
I would probably push a new scope the moment the user selects the button that creates a new transaction and pop it when the transaction is finished. |
Uh oh!
There was an error while loading. Please reload this page.
I'm having trouble disposing of scopes when poping and pushing from one screen to another.
In my application, I have two screens and each screen has an associated module. The module is responsible for registering the scope and disposing of it.
The following use-case is where I'm running into the issue:
FirstScreen
Navigator.popAndPushNamed(..)
is invoked to navigate toSecondScreen
initState
method is invoked onSecondScreen
register
method is invoked onSecondModule
which pushes a new scope and registers dependenciesdispose
method is invoked onFirstScreen
dispose
method is invoked onFirstModule
which pops the current scopeSecondScreen
becausescope_b
doesn't existThe issue here is that the
dispose
method of theFirstScreen
is being invoked after the registration ofSecondModule
. This causesscope_b
to be destroyed before it can be used.Any advice on a recommended approach to scoping and disposing of dependencies by screen? Any help would be greatly appreciated!
FirstScreen
FirstModule:
SecondScreen:
SecondModule:
The text was updated successfully, but these errors were encountered: