You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
In my use case, I want to share state between each PageView children, similar to how ActivityViewModel works in native apps. Currently, there is no built-in way to share a ViewModel between a parent widget like PageView and its child widgets, making communication and state management between pages difficult.
Describe the solution you would like
I would like a way for the PageView's ViewModel to be shared with its descdendants widgets (pages) so they can communicate and share state easily.
Alternatively, a service that lives as long as a specific widget exists could also solve this problem. This is similar to how dependency injection works in native development using Hilt. For example, in native Android, you can scope a service to an Activity, Fragment, or NavigationGraph using Hilt, and the service will live as long as that scope exists.
In Flutter, this could translate to a service scoped to a specific widget's lifecycle, that it is created and destroyed with that widget. This would allow for managing shared state between pages or routes, for example, using GoRouter for navigation or widgets with a well-defined lifecycle.
Additional Context
I expect ViewModels to behave similarly to how Providers work in many state management systems, such as Native Android or React Contexts. I'm not sure why Stacked enforces the rule of "1 view, 1 view model" when other systems allow descendants to access higher scope Providers or ViewModels.
The text was updated successfully, but these errors were encountered:
Put the state in a shared service, then read the state in the viewmodel that you want.
ViewModels is for managing the UI state of the specific view on screen. By making it strictly 1-to-1, it's very hard to create spaghetti code.
And since stacked is built for maintainability and testability, allowing the fetching of viewModels within other viewModels will make it hard to stick to that rule.
Is your feature request related to a problem? Please describe.
In my use case, I want to share state between each
PageView
children, similar to howActivityViewModel
works in native apps. Currently, there is no built-in way to share aViewModel
between a parent widget likePageView
and its child widgets, making communication and state management between pages difficult.Describe the solution you would like
I would like a way for the
PageView
'sViewModel
to be shared with its descdendants widgets (pages) so they can communicate and share state easily.Alternatively, a service that lives as long as a specific widget exists could also solve this problem. This is similar to how dependency injection works in native development using Hilt. For example, in native Android, you can scope a service to an
Activity
,Fragment
, orNavigationGraph
using Hilt, and the service will live as long as that scope exists.In Flutter, this could translate to a service scoped to a specific widget's lifecycle, that it is created and destroyed with that widget. This would allow for managing shared state between pages or routes, for example, using
GoRouter
for navigation or widgets with a well-defined lifecycle.Additional Context
I expect ViewModels to behave similarly to how Providers work in many state management systems, such as Native Android or React Contexts. I'm not sure why Stacked enforces the rule of "1 view, 1 view model" when other systems allow descendants to access higher scope Providers or ViewModels.
The text was updated successfully, but these errors were encountered: