I am new to dart so sorry if I’m missing something obvious
I’m writing a code to add elements to this Set<List> which works fine, but when I try to check if the element exists or to delete it does not work.
here’s the code
void main(List<String> args) {
Set<List<double>> level1barriers = {};
print(level1barriers);
level1barriers.add([1, 1]);
level1barriers.add([0.5, 0.3]);
print(level1barriers);
print(level1barriers.contains([1, 1]));
level1barriers.remove([1, 1]);
print(level1barriers);
}
3
Answers
I used a variable instead and it worked
Console :
Contains checks if one item is identically to another, so if you use the same exact object it will return true but if only the values is the same it wont.
So, you have to options if you want a Set, one is instead of making a Set<List> make a Set and make that class have as an only object a List. And make it Equalable.
As @Agustin Pazos included
[1,1]==[1,1]
will return false. It is checking reference instead of list items. You can use some packages,equatable
is handle while working with model class.For this list issue I am using
ListEquality
.Will return
Check this question for list equality