[英]Error: The method 'map' isn't defined for the class 'Object?'
var questions = [
{
'questionText' : 'What\'s your favorite colour? ',
'answers' : [ 'Green', 'Red', 'Yellow', 'Black'],
},
];
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('My second app'),
),
body: Column(
children: [
Question(
questions[_questionIndex]['questionText'] as String
),
**questions[_questionIndex]['answers'].map((answer){
return Answer('', answer);
}),**
I tried to put "as String" but nothing worked, the compiler always returns the same error
我试图把“作为字符串”,但没有任何效果,编译器总是返回相同的错误
You need to let dart know what questions[_questionIndex]['answers']
is, you can use as
to do this:您需要让 dart 知道
questions[_questionIndex]['answers']
是什么,您可以使用as
来执行此操作:
(questions[_questionIndex]['answers'] as List<String>).map((answer){
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.