Member-only story
Immutable Entities And Object Models In Flutter Clean Architecture
The relationship between the domain API and the implementation as the data layer are implemented by an entity interface and often a data layer model. By making the underlying atomic units immutable, we can avoid concurrency headaches and get one step closer to clean architecture in flutter application implementations.
Let me show you how to use the built value package to achieve this.
Why Built Value
Two reasons for built value. Let’s do reason one first.
Dart was designed conservatively as they had to fit it into a small VM that could run in a browser as the use case was the Google webapps everyone uses. Thus, it unlike languages like haskell does not have immutables by default.
But, immutables are preferred as they are less expensive performance-wise than mutables.
The reason the package is called built value instead of just immutable values is that those values have to be built so that the immutableness of the data structure underlying it is maintained.
Let’s See Built Value In Action
I am just using the plain flutter counter app, and you can find the source in this repo: