Home > Enterprise >  How to use indexWhere in dart when the list contains a map and I want to find the index of a certain
How to use indexWhere in dart when the list contains a map and I want to find the index of a certain

Time:01-05

I have this list

[
  {game29HakakianSchopf: {assists: 0, points: 0, rebounds: 0, fouls: 3}},
  {game30HakakianSchopf: {assists: 0, points: 0, rebounds: 0, fouls: 3}}
]

How can I use indexWhere in dart to find the index that contains the key (for example, find the index that has the key 'game29HakakianSchopf')

CodePudding user response:

Try something like this,

 var a = [
   {game29HakakianSchopf: {assists: 0, points: 0, rebounds: 0, fouls: 3}},
   {game30HakakianSchopf: {assists: 0, points: 0, rebounds: 0, fouls: 3}}
 ];

 final index = a.indexWhere((item){
   return item.keys.first.toString() == "game29HakakianSchopf";
 });
  • Related