felangel / equatable

A Dart package that helps to implement value based equality without needing to explicitly override == and hashCode.
https://pub.dev/packages/equatable
MIT License
920 stars 102 forks source link

feat request: add `stringifyProps` #145

Closed narcodico closed 11 months ago

narcodico commented 2 years ago

Is your feature request related to a problem? Please describe. Currently there's no way to easily specify a sub-set of props you want stringified.

Describe the solution you'd like Would be useful to have another getter similar to props, which would allow to override the props you want stringified.

Describe alternatives you've considered Manually overriding toString.

devpawann commented 1 year ago

163 Supports this.

felangel commented 11 months ago

I would recommend just overriding toString in the classes where you want to customize this behavior as it's fairly straightforward and ends up being easier to understand imo.

narcodico commented 11 months ago

By that logic you should remove stringify getters and EquatableConfig.stringify and allow users to manually override toString, cause why do things halfway? Right now for consistency people need to remember that your library is overriding toString using a specific format $runtimeType(prop1, prop2, ...).

@override
List<Object?> get stringifyProps => [prop1, prop2];

vs

@override
String toString() => 'ClassName($prop1, $prop2)';

Pretty obvious which one is easier to use and scales better.

devpawann commented 8 months ago

@felangel I believe it is more convenient to modify an array than a string in toString() override and this pattern matches with get props so I think this can get a consideration, WDYT?