-
-
Notifications
You must be signed in to change notification settings - Fork 231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom toString methods for data classes #33
Comments
That's hardly feasible. The closest we can get is: @immutable
abstract class ClubId with _$ClubId {
const ClubId._();
const factory ClubId(String value) = _ClubIdDataClass;
@override
String toString() {
return 'ClubId#$value';
}
} and then Freezed would try to extend this class |
It looks ugly with additional 'const ClubId._();' line What if about freezedNoToString attribute for example: @freezedNoToString
abstract class ClubId with _$ClubId {
const factory ClubId(String value) = _ClubIdDataClass;
@override
String toString() {
return 'ClubId#$value';
}
} |
That's still not feasible. As I said, the class is implemented not extended. This doesn't allow user defined methods. |
And what about use different attribute for the different generation to extend this class as I told about? toString methods became unreadable with lists and complex objects.. |
I would very much prefer working on the readability instead. The toString could be made to be multi-line instead |
How it could be readable with hundred items |
It can be shown last in the toString, or truncated like |
|
Closing in favor of #83 |
I'd love to be able to define custom
toString
methods for data classes.It should skip generation of
toString
in_$_ClubIdDataClass
and rely on the implementation inClubId
.Should be only possible for
@immutable
annotated classes with one factory constructor. Alternatively with a custom@freezedDataClass
annotation which only allows one factory constructorThe text was updated successfully, but these errors were encountered: