0

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

patriece
  • 25
  • 4

1 Answers1

1

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

enter image description here

chunhunghan
  • 51,087
  • 5
  • 102
  • 120