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.
- Screen will contain all the Widgets (View)
- 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.