Skip to content

[Compass app] Viewmodels being rebuild on state change #2604

@stdNullPtr

Description

@stdNullPtr

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(),
),
),

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions