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
If you require sealed classes, genq already supports the following:
import'package:genq/genq.dart';
part'input.genq.dart';
sealedclassState {}
@genqclassLoadingStateextendsStatewith_$LoadingState {
constfactoryLoadingState() =_LoadingState;
}
@genqclassSuccessStateextendsStatewith_$SuccessState {
constfactorySuccessState({
requiredString name,
requiredint age,
}) =_SuccessState;
}
voidmain() {
finalState state =LoadingState();
final result =switch(state) {
LoadingState() =>'Loading',
SuccessState(name:'John', age:30) =>'A 30 year old John',
SuccessState(name:final name, age:1) =>'$name is just 1 year old',
SuccessState(name:final name, age:final age) =>'$name is $age years old',
};
print(result);
}
It definetly is not as pretty as the requested syntax, but works if you need sealed classes.
Regarding the requested syntax, #30 tracks this feature request. So I will close this for now.
One change that would make genq an excellent freezed replacement would be to support unions with sealed classes.
Example
It would be great if this was able to generate a sealed classes that could be used with dart's pattern matching. Here is more details on how this would be useful:
https://medium.com/@aliammariraq/sealed-classes-in-dart-unlocking-powerful-features-d8dba185925f
The text was updated successfully, but these errors were encountered: