你好,我是新手。我已经对其进行了搜索,但是找不到适合我情况的解决方案。
我想给3个参数提供来自地图的Answer小部件值并分别列出。如果我从下面以及从Answer小部件构造函数中删除颜色,则下面的代码运行完美。
...(questions[_questionIndex]['answers'] as List<String>).map((answer) {
return Answer(_answerQuestion, answer, color);
}).toList()
我要添加Answer小部件和下面的地图。如何在上述语句中映射3个参数?
class Answer extends StatelessWidget {
final Function selectHandler;
final String answerText;
final Color color;
Answer(this.selectHandler, this.answerText,this.color);
@override
Widget build(BuildContext context) {
return Container(
width: double.infinity,
child: RaisedButton(
color: color,
textColor: Colors.white70,
child: Text(answerText),
onPressed: selectHandler,
),
);
}
}
final questions = [
{
'questionText': 'What\'s your favorite color?',
'answers': ['Black', 'Red', 'Green', 'White'],
'colors': [Colors.black, Colors.red, Colors.green, Colors.white]
},
{
'questionText': 'What\'s your favorite animal?',
'answers': ['Rabbit', 'Snake', 'Elephant', 'Lion'],
},
{
'questionText': 'Who\'s your favorite instructor?',
'answers': ['Max', 'Max', 'Max', 'Max'],
},
];
答案 0 :(得分:0)
List>类型更改解决了该问题。