Add a displayableProps
LefebvreIlyas opened this issue ยท 1 comments
LefebvreIlyas commented
Hello @felangel,
Thank you very much for your work on all the packages. ๐
Sometimes you need to compare objects on certain fields, but to display others using the toString
.
abstract class Equatable {
List<Object> get props;
List<Object> get displayableProps => props;
}
Display all the props.
This is the default behavior.
class Foo extends Equatable {
// Fields
@override
List<Object> get props => <Object>[
foo,
bar,
baz,
foobar,
];
}
Display and compare different fields.
class Foo extends Equatable {
// Fields
@override
List<Object> get props => <Object>[
foo,
bar,
];
@override
List<Object> get displayableProps => <Object>[
baz,
foobar,
];
}
Display all properties except one
class Foo extends Equatable {
// Fields
@override
List<Object> get props => <Object>[
foo,
bar,
baz,
foobar,
];
@override
List<Object> get displayableProps => props.removeAt(0);
}
felangel commented
Hi @LefebvreIlyas ๐
Thanks for opening an issue!
If you would like custom toString
behavior, I would recommend just overriding toString
manually for the one-off cases.
class Foo extends Equatable {
// Fields
@override
List<Object> get props => <Object>[
foo,
bar,
baz,
foobar,
];
@override
String toString() => 'Foo($bar, $baz, $foobar)`;
}
Hope that helps! Closing for now but feel free to comment with additional comments/questions and I'm happy to continue the conversation ๐