【发布时间】:2021-10-18 11:34:02
【问题描述】:
这就是我定义我的列表的方式:
final _question = [
{
'questionText': ' what\'s your favourite color?',
'answers': [
{'text': 'Black', 'score': '10'},
{'text': 'Green', 'score': '80'},
{'text': 'Blue', 'score': '147'},
{'text': 'Yellow', 'score': '60'},
]
},
{
'questionText': 'what\'s your favourite animal?',
'answers': [
{'text': 'Rabbit', 'score': '10'},
{'text': 'Tiger', 'score': '10'},
{'text': 'Elephant', 'score': '10'},
{'text': 'Lion', 'score': '10'},
]
},
];
然后我调用列表,通过将地图转换为列表来提取“文本”和“分数”
Question(question[questionindex]['questionText']),
...(question[questionindex]['answers'] as List<Map<String,Object>>).map((answer) {
return Answer(() => answerQuestion(answer['Score']), answer['text']);
}).toList(),
但我得到了这个错误“参数类型'对象?'不能分配给参数类型'String'"。
【问题讨论】: