I have the following List of Maps:
var questions = [
{
'questionText': 'What is your favorite color?',
'answers': ['Black', 'Green', 'Red', 'White'],
},
{
'questionText': 'What is your favorite animal?',
'answers': ['Pig', 'Goat', 'Lion', 'Baboon'],
},
{
'questionText': 'What is your favorite number?',
'answers': ['1', '2', '3', '4'],
},
{
'questionText': 'What is your favorite game console?',
'answers': ['Xbox', 'Playstation', 'Nintendo', 'PC'],
},
{
'questionText': 'What is your favorite car model?',
'answers': ['Nissan', 'Toyota', 'Ford', 'Honda'],
},
];
I have an Example function that takes String type Arguments. If I wanted to use the keys one of the maps as that argument as such:
ExampleFunction(questions[1]['questionText']);
I get the following error:
The argument type 'Object?' can't be assigned to the parameter type 'String'.
I understand that using the map operator "[ ]" produces a nullable type according to documentation. It says to use an exclamation mark as follow to make it non-nullable:
ExampleFunction(questions[1]['questionText']!);
But this just produces the following error, this time without the explanation "?" mark:
The argument type 'Object' can't be assigned to the parameter type 'String'.
When I hover over the list it gives me:
List<Map<String, Object>>
Why are the keys appearing as an object when the only types I have in each map is String Keys, and List Answers?