freezed icon indicating copy to clipboard operation
freezed copied to clipboard

Disable "when" generation by default

Open rrousselGit opened this issue 1 year ago • 3 comments

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).

rrousselGit avatar May 24 '23 14:05 rrousselGit

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?

Reprevise avatar Jun 28 '23 00:06 Reprevise

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.

rrousselGit avatar Jun 28 '23 05:06 rrousselGit

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.

Reprevise avatar Jun 28 '23 13:06 Reprevise