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

The class has the collection variable is not the "List" object. #17

Closed
phamnhuvu-dev opened this issue May 24, 2019 · 1 comment
Closed

The class has the collection variable is not the "List" object. #17

phamnhuvu-dev opened this issue May 24, 2019 · 1 comment
Assignees
Labels
Projects

Comments

@phamnhuvu-dev
Copy link
Contributor

@phamnhuvu-dev phamnhuvu-dev commented May 24, 2019

Describe the bug
If the class has the collection variable is not the "List" object. Comparing is always return true.

To Reproduce
Steps to reproduce the behavior:

class E extends Equatable {
  final Map<String, int> map;

  E(this.map);
}

E e1 = E({"A": 1});
E e2 = E({"B": 2});
assert(e1 == e2); // return true

Expected behavior
assert(e1 != e2) //return true

Problem
https://github.com/felangel/equatable/blob/master/lib/src/equatable_utils.dart#L18-L24

Solution
Compare between 2 collections(List, Map, Set, v.v…) have to use Equality object(ListEquality, MapEquality, SetEquality, v.v…) in package:collection/collection.dart.
Don’t use “==” operator.

MapEquality mapEquality = MapEquality();
Map map1 = {"A": 1};
Map map2 = {"A": 1};
Map map3 = {"B": 2};
assert(mapEquality.equals(map1, map2)); //map1 == map2
assert(!mapEquality.equals(map2, map3)); //map2 != map3
@felangel

This comment has been minimized.

Copy link
Owner

@felangel felangel commented May 24, 2019

@phamnhuvu-dev in your example I noticed you aren't passing the properties to the Equatable superclass.

class E extends Equatable {
  final Map<String, int> map;

  E(this.map) : super([map]); // missing call to super
}
@felangel felangel added this to In progress in equatable May 24, 2019
@felangel felangel closed this May 24, 2019
@felangel felangel moved this from In progress to Done in equatable May 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
equatable
  
Done
2 participants
You can’t perform that action at this time.