Reputation: 25
Please help me out,
i have a multilist with a type of string:
List<List<String>> mergedList = [["39", "Green"], ["40", "Blue"], ["39", "Blue"], ["40", "Green"]]
i want to find the index of ["39", "Green"] by using indexOf like this:
mergedList.indexOf(["39","Green"])
but instead it always return -1.
please help where did i do wrong
Upvotes: 0
Views: 97
Reputation: 54367
In your case, you can use indexWhere
and compare with element.toString()
full code
void main() {
List<List<String>> mergedList = [["39", "Green"], ["40", "Blue"], ["39", "Blue"], ["40", "Green"]];
var pos = mergedList.indexWhere((element) => element.toString() == ["39","Green"].toString());
print(pos);
var pos1 = mergedList.indexWhere((element) => element.toString() == ["39","Blue"].toString());
print(pos1);
}
output
0
2
working demo
Upvotes: 1