1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Flutter] Using Multiple ViewModels per Model and Directly Integrating an Analytics Service in...

Discussão em 'Mobile' iniciado por Stack, Outubro 1, 2024 às 09:13.

  1. Stack

    Stack Membro Participativo

    I am working on MVVM architecture in Flutter using Cubit state management.

    I have a few doubts regarding the implementation of the following, adhering to MVVM:

    1. Having multiple ViewModels per Model

    For example, I have a PostModel:

    PostModel can either represent a single PostModel or a list of PostModel. To handle such scenario i'm creating two different viewModel using cubit as below

    i. class PostModelVM extends Cubit<PostModel> {}

    ii. class PostModelListVM extends Cubit<List<PostModel>> {}

    Is the above approach correct?

    2. Using an Analytics Service in the UI

    I have an analytics service that is used inside repositories. Now, I want to use the analytics service in the UI for collecting information such as button clicks, page opens, etc.

    Is it okay to use the analytics service directly in the UI? Does this need to go through the ViewModel, as the UI should not contain any repositories or services directly?

    Example: using below inside initState of StatefulWidget

    AnalyticService().saveEvent('clicked');

    Continue reading...

Compartilhe esta Página