Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Equatable doesn't work with nested custom Iterable objects #101

Closed
nxtSwitch opened this issue Feb 4, 2021 · 0 comments · Fixed by #103
Closed

Equatable doesn't work with nested custom Iterable objects #101

nxtSwitch opened this issue Feb 4, 2021 · 0 comments · Fixed by #103
Assignees
Labels
bug Something isn't working
Projects

Comments

@nxtSwitch
Copy link

nxtSwitch commented Feb 4, 2021

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

@felangel felangel self-assigned this Feb 6, 2021
@felangel felangel added the investigating Investigating a reported issue label Feb 6, 2021
@felangel felangel added this to To do in equatable Feb 7, 2021
@felangel felangel added the bug Something isn't working label Feb 8, 2021
@felangel felangel moved this from To do to In progress in equatable Feb 8, 2021
@felangel felangel removed the investigating Investigating a reported issue label Feb 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
equatable
  
In progress
Development

Successfully merging a pull request may close this issue.

2 participants