Closed aspiringant closed 4 years ago
The issue I see here is that whenever the build of HomeView will be called, it can be that BaseWidget
Ideally, view models are initialized inside the builder method of ChangeNotifierProvider. The code you have will work fine, but if it is extended by others ( which happened to our teammate ) it would create complications.
@aspiringant I usually use the singleton pattern for ViewModels that I don't want to be constructed everytime. This can be done by manually implementing the singleton pattern or using a singleton registration in get it and getting your viewmodel from there like i've shown in some other tutorials.
https://github.com/FilledStacks/flutter-tutorials/blob/de32c20bc8573e549269be5d949e146acf8ed987/031-responsive-architecture-provider/02-final-state-implementation/lib/views/home/home_view.dart#L15