freezed icon indicating copy to clipboard operation
freezed copied to clipboard

Less verbose toString() method for sealed classes

Open kaciula opened this issue 5 years ago • 1 comments

Take the following class.

@freezed
abstract class DataEvent with _$DataEvent {
  factory DataEvent.versionNameRefreshed(String versionName) =
      VersionNameRefreshed;
  factory DataEvent.userRefreshed({@required User user}) = UserRefreshed;
  factory DataEvent.signedOut() = SignedOut;
}

One of the generated toString() method looks like the following.

@override
String toString() {
    return 'DataEvent.userRefreshed(user: $user)';
 }

I think that is is better if the toString() method would return 'UserRefreshed(user: $user)'. That is, use the name on the right hand instead of the entire factory name.

kaciula avatar Apr 01 '20 11:04 kaciula

On the contrary, if UserRefreshed was a private class i.e. _ UserRefreshed, then I'd prefer keeping the factory name.

britannio avatar Sep 12 '20 23:09 britannio

I have no plan to implement this.

rrousselGit avatar May 24 '23 14:05 rrousselGit