You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
I'm trying to implement IsarLinks with Freezed. This requires a field to be instantiated and initialised during the construction, which is not allowed by Freezed.
Currently the only way to define a default value is by using the @default(literal) annotation. I've searched through issues around this which dated back to 2 years - #64, #82, #149. These issues imply that the problem is gated by JsonSerializable. Which it is, if we are looking at it from the perspective of "default" values.
Describe the solution you'd like
What about an initial value? Why not add an @initial(value) annotation?
So the generated code would then become something like this:
Constructor({Class? field}) : field = field ?? intialValue, super._();
I tried using this hack by by adding a JsonKey() to the field. But this doesn't work because we are still working in the realm of Default value which only accepts const literal.
Additional context
This problem is not related to JsonSerializable as far as I'm concerned because I've been able to address this issue by using a combination of packages to replace Freezed - Equatable, CopyWithExtension, and JsonSerialiazable. Not ideal because of the convenience of Freezed having all the features in one package. However, I've come up with this problem too many times needing an initial value which Freezed does not support.
The text was updated successfully, but these errors were encountered:
Is your feature request related to a problem? Please describe.
I'm trying to implement IsarLinks with Freezed. This requires a field to be instantiated and initialised during the construction, which is not allowed by Freezed.
Currently the only way to define a default value is by using the @default(literal) annotation. I've searched through issues around this which dated back to 2 years - #64, #82, #149. These issues imply that the problem is gated by JsonSerializable. Which it is, if we are looking at it from the perspective of "default" values.
Describe the solution you'd like
What about an initial value? Why not add an @initial(value) annotation?
So the generated code would then become something like this:
Constructor({Class? field}) : field = field ?? intialValue, super._();
instead of this:
Constructor({this.field = defaultValue}) : super._();
Describe alternatives you've considered
I tried using this hack by by adding a JsonKey() to the field. But this doesn't work because we are still working in the realm of Default value which only accepts const literal.
Additional context
This problem is not related to JsonSerializable as far as I'm concerned because I've been able to address this issue by using a combination of packages to replace Freezed - Equatable, CopyWithExtension, and JsonSerialiazable. Not ideal because of the convenience of Freezed having all the features in one package. However, I've come up with this problem too many times needing an initial value which Freezed does not support.
The text was updated successfully, but these errors were encountered: