Freezed: Hard to use.

Created on 3 Jul 2020  路  9Comments  路  Source: rrousselGit/freezed

Why don't you generate code based on an existing class like json_serializable do, instead of creating an abstract class?

I just want to build it based on an existing class with the benefit of the copyWith method, so I can control my class more flexibly.

Most helpful comment

Freezed is not made to be flexible but to have a concise syntax.

All 9 comments

The way copyWith works requires a factory constructor, for the null support.

The syntax is also shorted (no duplicate between properties and the constructor).

And it support union types.

If you don't like it, you can use built_value

I think there is a simpler way to solve the null case. that is to use setters.
like this:
state = state.copyWith(name: 'guest', avatar: 'empty').setToken(null);

The classes are immutable.
They don't have setters.

And the syntax is not as intuitive as copyWith(token: null)

I think I should wait until the dart can distinguish between passing a null parameter and a non-passed parameter.馃槙

@rrousselGit What do you think if I wrap parameters with Value?
like this

state = state.copyWith(token: Value(null));

state.copyWith(token: null) already works with the current syntax.

I don't see a reason to do a downgrade on that aspect

but current. It requires a abstract class to generate code and reduced flexibility

Freezed is not made to be flexible but to have a concise syntax.

Yes. Thanks !

Was this page helpful?
0 / 5 - 0 ratings