Recently was working with dart multi-dimensional list, i have tried to remove a row(list) from a 2 dimensional list but the remove
has no effect neither contains
method has a match.
List<List<int>> list = [[1, 2], [3, 4]];
print(list.contains([1,2])); // prints false also removing will not has an effect
while
List<List<int>> list = [[1, 2], [3, 4]];
print(list.contains(list[0])); // prints true and successful remove
Why passing a list doesn’t have a match, I know that comparison here is based on reference not the value, but shouldn’t lists be canonicalized just like String and other numerical data types.
2
Answers
It seems correct,[1,2] != list[0].
you can see the implement of the contains function:
In your case,you can use listEquals such as :
You can use listEqual() to compare list
Output