Error: The method 'map' isn't defined for the class 'Object?'
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
你需要让dart知道questions[_questionIndex]['answers']
是什么,你可以使用as
来做到这一点:
(questions[_questionIndex]['answers'] as List<String>).map((answer){
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
你需要让dart知道questions[_questionIndex]['answers']
是什么,你可以使用as
来做到这一点:
(questions[_questionIndex]['answers'] as List<String>).map((answer){