felangel / equatable

A Dart package that helps to implement value based equality without needing to explicitly override == and hashCode.

Home Page:https://pub.dev/packages/equatable

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Equatable doesn't work with nested custom Iterable objects

nxtSwitch opened this issue · comments

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 ==