Home > OS >  Adding functions inside model breaks MVVM or SOLID principles in Dart / Flutter
Adding functions inside model breaks MVVM or SOLID principles in Dart / Flutter

Time:11-24

In Dart we add methods like toJson() and Model.fromJson() inside model, does this breaks MVVM or SOLID principles?

CodePudding user response:

No, it doesn't, it's totally the opposite, it's recommended to set model JSON converters factories and methods of a model inside its implementation.

check this:

JSON and serialization

the goal of those methods is to handle serializing your model, to make your life easier when working with APIs, and external data...

I would say that what's not a good practice, is to try to handle JSON serialization inside your business logic.

  • Related