I´m trying to acess the score of a given question:
main() {
final questions = const [
{
"question": "Your favorite animal?",
"answer": [
{"text": "Lion", "score": 4},
{"text": "Tiger", "score": 6},
]
}
];
print(questions[0]["answer"]["score"]);
}
Here´s how i´m trying to acess it: print(questions[0]["answer"]["score"]);
But it´s showing me an error:
Error: The operator '[]' isn't defined for the class 'Object?'.
- 'Object' is from 'dart:core'.
Try correcting the operator to an existing operator, or defining a '[]' operator.
print(questions[0]["answer"]["pontuacao"]);
How can I fix this?
questions[0]["answer"]gives you a list of elements, you need to index into it before calling["score"].