FilledStacks / provider_architecture

A set of widgets to help with the implementation of the Provider architecture as shown by FilledStacks
86 stars 15 forks source link

What is the best practice for using the ViewModelProvider as a singleton #7

Closed kauaicreative closed 4 years ago

kauaicreative commented 4 years ago

Usually I want to keep the state of my ViewModelProvider for the life of the app. I recall in your filledstacks tutorals you would use Get_it, locator.registerLazySingleton(() => MyViewModelProvider()); to solve this. Is that what you would recommend?

kauaicreative commented 4 years ago

I think the answer is essentially yes and can be found here. https://medium.com/p/c14c3bdc2478/responses/show

FilledStacks commented 4 years ago

@kauaicreative yes :) If you require it to be alive the entire app then you can do that. I have used it like that before. You have to ensure you don't dispose the viewmodel by either using ChangeNotifierProvider.value or the "not recommended one" override dispose in the viewmodel and never call super.dispose