Open mindthefish opened 4 years ago
This has a strong overlap with Issue #7 but instead is using the ViewModel and not the ViewModelProvider as a singleton.
Has this been added yet? If not could you add it and push the code for it?
Finally found some minutes to do so! https://github.com/FilledStacks/provider_architecture/pull/13
Hi, first of all, thank you very much for this fantastic package, it makes my MVVM life much easier.
I am holding my data models in a List inside of my view model. I do not want to dispose the view model and recreate my data every time I navigate away and back to a certain screen, which is why I hold my view model as a lazy singleton using get_it. This works fine but throws an error when the ChangeNotifierProvider constructor is called within the ViewModelProvider built function with a reused view model.
What I am currently doing is a reimplementation of the ViewModelProvider class where I call the ChangeNotifierProvider.value constructor inside the built function, which gives me the opportunity to reuse my view model.
My suggestion is to provide an additional parameter in the ViewModelProvider.withConsumer and .withoutConsumer constructor bool reuse = false, which will be looked for in the build function. If reuse == true, the alternative ChangeNotifierProvider.value constructor could be called.
Or, alternatively, what would be the disadvantage of always using the .value constructor?
Thank you very much for your feedback!