Home > Net >  Does MVVM require to remove all logic from the Widgets?
Does MVVM require to remove all logic from the Widgets?

Time:10-12

I'm having confusion regarding the correct implementation of MVVM architecture in a flutter.

Does MVVM require separating just the UI calls from the UI or separating the complete logic of the widgets, even if it is to update a CheckBox?

If using setState does not raise performance issues, should we use it when following MVVM architecture?

If it is okay to have some logic inside of widgets, to what extent should we do that?

CodePudding user response:

Yes obviously , I suggest you to study Clean Architecture, Basically concept is that, You have to create ViewModel for every screen.

  1. Screen will contain all the Widgets (View)
  2. View Model will contain all functionality and variable which will be hold value which used in Screen (View)

CodePudding user response:

It is perfectly okay for the widget to manage its state internally. It wouldn't make sense e.g. ListView not to manage its scrolling state. The same obviously applies to custom widgets.

See Differentiate between ephemeral state and app state for more information.

  • Related