freezed 0.0.0 freezed: ^0.0.0 copied to clipboard
Code generation for immutable classes that has a simple syntax/API without compromising on the features.
Welcome to Freezed
, yet another code generator for immutable classes / sealed classes / union types / copy.
Motivation #
While there are many code-generators available to help you deal with immutable objects, they usually come with a trade-off.
Either they have a simple syntax but lack in feature, or they have very advanced
features but with a complex syntax.
A typical example would be a "clone" method.
Current generators have two approaches:
-
a
copyWith
, usually implemented using??
:MyClass copyWith({ int a, String b }) { return MyClass(a: a ?? this.a, b: b ?? this.b); }
The syntax is very simple to use, but doesn't support some use-cases: nullable values.
We cannot use suchcopyWith
to assignnull
to a property like so:person.copyWith(location: null)
-
a builder method combined with a temporary mutable object, usually used this way:
person.rebuild((person) { return person ..b = person; })
The benefits of this approach is that it does support nullable values.
On the other hand, the syntax is not very readable and fun to use.
Say hello to Freezed
~, with a support for advanced use-cases without compromising on the syntax.
See the example or the index for a preview on what's available