This is more of a question as I am still learning, but I see that we are using the Provider for DI which is great. However, I see in some places like here:
class HomeHeader extends StatelessWidget
that we do this:
LogoutButton(
viewModel: LogoutViewModel(
authRepository: context.read(),
itineraryConfigRepository: context.read(),
),
),
We are creating a new LogoutViewModel instead of using a singleton like the one used with the Provider.
Isn't this view model going to lose its' state across widget rebuilds? Shouldn't there be strictly one ViewModel of the same type existing in the app context?
|
LogoutButton( |
|
viewModel: LogoutViewModel( |
|
authRepository: context.read(), |
|
itineraryConfigRepository: context.read(), |
|
), |
|
), |
This is more of a question as I am still learning, but I see that we are using the Provider for DI which is great. However, I see in some places like here:
class HomeHeader extends StatelessWidgetthat we do this:
We are creating a new
LogoutViewModelinstead of using a singleton like the one used with the Provider.Isn't this view model going to lose its' state across widget rebuilds? Shouldn't there be strictly one ViewModel of the same type existing in the app context?
samples/compass_app/app/lib/ui/home/widgets/home_title.dart
Lines 40 to 45 in 5a7decd