freezed
freezed copied to clipboard
Disable "when" generation by default
Related to https://github.com/rrousselGit/freezed/issues/924
In a "Freezed 3.0" version, we could disable "when" by default (and enable its generation through build.yaml).
In general, I am in favor of this however I am also a big fan of this pattern here which AFAIK there's no equivalent behavior in Dart's pattern matching syntax:
return Scaffold(
appBar: /* ... */,
body: state.when(
// ...
),
);
This pattern is commonly used in riverpod with AsyncValue
which I know isn't really related to freezed but it is the same exact syntax. Are you going to be pushing for that to change too?
AFAIK there's no equivalent behavior in Dart's pattern matching syntax:
return Scaffold( appBar: /* ... */, body: state.when( // ... ), );
You can dk:
body: switch (state) {
...
}
This pattern is commonly used in riverpod with
AsyncValue
which I know isn't really related to freezed but it is the same exact syntax. Are you going to be pushing for that to change too?
Yes, the same logic will be applied.
Alright, though I do have a specific case where I need a block body so a switch expression won't work there, but I'll just force-enable when
generation for that class since IMO it looks nicer than making 4 methods for each case just to make an expression work.
I have already disabled when/map generation globally across my project in preparation for the next update and I only have to enable when generation manually on one class so I think that's pretty good overall.