This would be very hacky and I don't really know how to do it. Somehow getting the container and manually disposing the providers. Ideally, all current state of the providers should be invalidated, and then remade when the user navigates to each of the pages again.Ī way to call ref.dispose() on the providers that have invalidated state, so the state is only recomputed when needed, not immediately. The problem is that if I do ref.refresh() for all providers when this event happens, all API calls for the providers refreshed will be remade simultaneously, causing each to take way longer. There are some events that can happen that require me to remake all calls, to update the info shown. The app has many different pages, and the first time each page is entered, the API call is made to get the data and then kept so it doesn't have to be remade next time the user enters the same page (the providers are NOT auto-dispose). In my app, I have a lot of providers that make relatively expensive API calls to compute their state. How about if we reverse the "event flow" and have the top-level board provide an event such as a future that is completed when closed.Is your feature request related to a problem? Please describe. Thanks for the feedback about the above "anti-pattern". Yes watch mostly handles this but we have encountered edge cases. When the display is completed this "scope" is disposed. All of our U/I state providers are created "under" this scope. For us, this is the beginning of a display "scope". valid for "go back") are held in an unmounted state.Īt the "top" of each of our displays we have a ProviderScope that overrides a few display specific providers. What is autoDispose App entry point The Model class and ChangeNotifier Wrapping state. Also the above mentioned previous cards (i.e. A Brief Look at the Flutter Provider Library. During a few frames of a transition display Riverpod will dispose of our providers. value constructor, it is impossible for provider to know if the object is no longer used. It is your job to do so (with a typical StatefulWidget), as using the. We've had to watch out on some of our asynchronous processing that display a busy screen. ChangeNotifierProvider.value will not dispose the ChangeNotifier. Several of the comments in #1329 show concern with the provider behavior combined with users opening/closing/transitioning screens. Time-based solutions are not deterministic. We want providers to live throughout the lifetime of a given display and not beyond - i.e. definitive provider lifetime management. This request is inspired by the lively discussion in #1329 which has many references to Flutter-based user actions and screens.Īnd what is it that this issue is requesting? Possibly something like Provider.scopedDispose() instead of the 3 lines of keepAlive code we currently add. The providers that want to be so managed would need to indicate this. Yes, there would need to be another form/mode of ProviderScope to be added to the Flutter tree that manages these provider lifetimes. We currently manage these provider lifetimes using keepAlive (we're migrating to 2.0-dev), storing the keepAliveLinks in a scope-aware data structure, and close() the links on the user finalizing action.įor us, a Flutter "scoped" autoDispose would handle the provider lifetime management that we currently need to code. Prior provider states are needed when going back. One problem task flow for us is a prompted multi-card dialog that supports a "go back" feature. A time-based solution is not reliable since we don't know when the user will "get a coffee". The end of the "scope" is a user finalizing action such as closing a dialog or navigating to another view. On the Flutter side of our app we basically have global providers and what are effectively Flutter scoped providers (i.e.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |