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
Assignees
Labels
enhancement New feature or request
Projects

Comments

@phamnhuvu-dev
Copy link
Contributor

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
Copy link
Owner

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 added the enhancement New feature or request label 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
Labels
enhancement New feature or request
Projects
equatable
  
Done
Development

No branches or pull requests

2 participants