Here's a nice simple article explaining enhanced enums that have been around for a while but may be something overlooked. Between these and sealed classes I think Dart has an excellent story for pattern matching.
Everything you need to know about Enum with Flutter and Dart
https://lyabs.hashnode.dev/everything-you-need-to-know-about-enum-with-flutter-and-dart
8 Comments
anlumo@feddit.de · 1 pts · 2y
I've yet to find a single use case for enhanced enums. It also doesn’t help that freezed doesn’t support them.
samus7070@programming.dev · 1 pts · 2y
Prior to sealed classes, I wished they were more like swift enums that could carry dynamic data and have different associated types per case. Now if I want that, I can do that with a sealed class. It’s still nice to have smarter enums if I need a little extra smarts and want to keep the logic close to the enum.
Rexios@lemm.ee · 1 pts · 2y
How exactly does freezed not support them? All data on an enhanced enum is static.
samus7070@programming.dev · 1 pts · 2y
Maybe the code generator? I have no idea. It seems like there shouldn’t be an issue.
anlumo@feddit.de · 1 pts · 2y
Freezed generates sealed classes, not enums.
Rexios@lemm.ee · 1 pts · 2y
I’m not sure enhanced enums do what you think they do if you expect freezed to generate anything for them besides what json_serializable generates for regular enums
anlumo@feddit.de · 1 pts · 2y
The whole point of the discussion is that enhanced enums don't do anything in practice.
problematicconsumer@lemmy.world · 1 pts · 2y
Instead of writing verbose extensions and functions all over the place you can use enhanced enums. I mean what else are they supposed to do?