Closed xsahil03x closed 4 years ago
suggest a name for the said property, I am struggling to find a good name :P
shouldEquate
maybe? @passsy any suggestions.
Instead of blindly adding this feature I'd like to see a real-world example where this is useful.
sealed classes
should definitely not have a custom equals method. Every member counts.And I've never seen a good example where a partially equals method implementation actually made sense. It might only be used for a special use case and might be better implemented using a custom comparison method, not the operator ==()
.
void main() {
final itemA = Item("A");
final itemB = Item("B")..added = false;
final itemB2 = Item("B")..added = true;
print(itemA == itemB); // false
print(itemB == itemB2); // false
print(itemA.customEquals(itemB)); // false
print(itemB.customEquals(itemB2)); // true
}
class Item {
Item(this.name);
final String name;
// mutable property
bool added;
}
extension ItemEquality on Item {
/// Only checks for the name
bool customEquals(dynamic other) => (other is Item) && name == other.name;
}
My recommendation: Add a property to skip generating the equals method at all. It could be useful for mutable super_enums. Users of such classes then could implement an extension
for that type to implement their own equals method. (Sadly overriding operator ==()
doesn't work with extensions).
@passsy yes, makes sense to me.
Currently, we don't have any option or property to mark a
DataField
to be ignored fromequatable props
. We should add a property for the same.