Open guilhermearaujo opened 4 months ago
It is not possible as of now.
I'm a bit torn on this feature - I think the syntactic sugar would be a very nice addition, as the alternative for sealed classes is quite verbose.
I'm not sure though if we should generate the map
, maybeMap
etc. As of Dart 3.0, the necessity for these methods is questionable, as pattern matching & sealed classes exists now. If we include it, it will definetly be an opt in feature.
I personally don't see a need for map, maybeMap, maybeWhen... freezed is already going away from those. But being able to generate sealed classes and unions with the freezed syntax would be huge.
That example is from an older project I started working on recently, I honestly don't even know if all that generated code is really necessary or if just a piece of it should be enough.
Interesting, I was not familiar with sealed classes. That may actually work, but I need to test it.
Today we use freezed to generate some class methods like this:
and freezed outputs:
```dart // coverage:ignore-file // GENERATED CODE - DO NOT MODIFY BY HAND // ignore_for_file: type=lint // ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark part of 'something_state.dart'; // ************************************************************************** // FreezedGenerator // ************************************************************************** T _$identityIs it possible to use genq to do the same?