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

the argument type object cann't be assigned to parameter like string in flutter while accessing the map inside the list

//my code:
var _index = 0;
  var question = [
    {
      'Questionkey': "which cryptocurrency do you like",
      'Answer': ['bitcoin', 'etherium']
    },
    {
      'Questionkey': "and why do you like that?",
      'Answer': ['stable', 'acutally i don\'t know ']
    },
  ];



question[_index]['Questionkey']//accessing the question but I am getting error while accessing

//question is the list that consists of maps and I want to access the question which is pointed questionkey key

>Solution :

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

Wherever you use

question[_index]['Questionkey']

write

question[_index]['Questionkey'] as String

instead. It’s able to access the map just fine, it’s just that it can’t determine the type at compile time. And I assume you are using it at a spot where it requires to be a String. Knowing that it is a String you can safely cast it like this

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