【发布时间】:2021-09-24 18:17:48
【问题描述】:
她的部分来自 code.dart:
final List<Map< String,Object>> question = [
{
'questionText': 'what\'s your favorite\'s color?',
'answers': [
'Black',
'Green',
'Blue',
'Yellow',
]
},
{
'questionText': 'Select a true fact about Paulo Maldini!',
'answers': [
'He is dead',
'He is alive',
'He killed',
'He is single',
]
},
];
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
centerTitle: true,
title: MyText("Quiz Bahlol", fontstyle2),
),
body: Container(
width: double.infinity,
child: Column(
children: <Widget>[
Question(question[_questionIndex]['questionText']),
// in this line error
question[_questionIndex]['answers'].map((answer) {
return Answer(answerQuestion, answer);
}).toList(),
],
),
)),
);
并在运行应用程序时给我这个错误:
需要一个“小部件”类型的值,但得到一个“列表”类型的值
但在旧版本中工作正常。 参数类型“对象?”不能分配给参数类型“字符串”。
【问题讨论】:
-
请提供完整的错误信息。它还应该解释问题出在哪一行。
-
如果您的代码还没有准备好进行更严格的空安全类型检查,请不要启用空安全。将
pubspec.yaml中的 Dart SDK 最低版本设置为 2.12 之前的版本。 -
展示你的问答类