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

listEquals returns true when it should be false

Macacoazul01 opened this issue · comments

I'm having problems comparing lists of objects in flutter and searching for some solutions on the web i've found this library, but when i try to use it on a class that isn't final it doesn't work as expected:

The new person class:

import 'package:equatable/equatable.dart';

class Person extends Equatable {
   Person(this.name);

   String name;

  @override
  List<Object> get props => [name];

}

The test vars:

Person p = Person("name");

Person p2 = Person("name2");

Person p3 = Person("tobias");


List<Person> ListA = [p, p2];

List<Person> ListB = [p, p2..name = "teste"];

List<Person> ListC = [p, p3];

the test:

var filtered_lst =
    List.from(ListA.where((value) => !ListB.contains(value)));
print(filtered_lst);
print(listEquals(ListA , ListB));
print(listEquals(ListA , ListC));

the console log:

I/flutter (12746): []
I/flutter (12746): true
I/flutter (12746): false

The first print should show that the ListB[1] isn't on ListA
The second should show false
The last is ok