如何访问问题和答案?
var questions = [
{
'questionText': 'What's your favorite color?',
'answers': ['Black', 'Red', 'Green', 'White'],
},
{
'questionText': 'What's your favorite animal?',
'answers': ['Rabbit', 'Snake', 'Elephant', 'Lion'],
},
{
'questionText': 'Who's your favorite instructor?',
'answers': ['Max', 'Max', 'Max', 'Max'],
},
];
我试着:
questions.elementAt(1)['questionText']
questions[_questionIndex]['questionText']
但两者都不起作用。它说:参数类型是Object?'不能分配给参数类型'String'。
就像这样使用索引。
String question = questions[1]['questionText'].toString();