Contain method can not detect the object inside of list
What is the reason of that?
I expected to get the result of if block
enter image description hereLook at this picture as well.In the second picture it works
Contain method can not detect the object inside of list
What is the reason of that?
I expected to get the result of if block
enter image description hereLook at this picture as well.In the second picture it works
2
Answers
You can override the
==
operator onCountry
like so to get it to work:Alternatively, there’s this package https://pub.dev/packages/equatable, and you can use it like so:
As pointed about by jamesdlin, it’s not because of
call by value
From Effective dart, it says:
it’s because your
Contact
object has no==
relation between its instances,so trying to compare two instances like this:
And the
contains
method follows the same comparison I did to find if a list contains that object.It would help if you told
Dart
when two objects of that class should be considered equal to each other, by overriding the==
operator like this:now trying this:
and so on now the
contains
method will work as you expect