Equatable doesn't work with nested custom Iterable objects
nxtSwitch opened this issue · comments
nxtSwitch commented
Describe the bug
Equatable doesn't work with class that override iterator
like so:
To Reproduce
class SomeObject with EquatableMixin {
final CustomList list;
const SomeObject(this.list);
@override
List<Object> get props => [list];
}
class CustomList extends Iterable<String> with EquatableMixin {
final bool flag;
final List<String> list;
const CustomList({this.list, this.flag});
@override
List<Object> get props => [flag, list];
@override
Iterator<String> get iterator => list.iterator;
}
const list1 = CustomList(list: ['1', '2'], flag: true);
const list2 = CustomList(list: ['1', '2'], flag: false);
print(const SomeObject(list1) == const SomeObject(list2)); // true
Additional context
As a partial solution, if the object inherits from the Equatable
, then compare via ==