freezed 0.0.0 copy "freezed: ^0.0.0" to clipboard
freezed: ^0.0.0 copied to clipboard

outdated

Code generation for immutable classes that has a simple syntax/API without compromising on the features.

Build Status pub package

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 such copyWith to assign null 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

Index #

How to use #

3969
likes
0
pub points
99%
popularity

Publisher

verified publisherdash-overflow.net

Code generation for immutable classes that has a simple syntax/API without compromising on the features.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

analyzer, build, build_config, meta, source_gen

More

Packages that depend on freezed