Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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’)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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";
 });
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading