[英]NoSuchMethodError while using map in flutter
由于您的questions[_questionIndex]['answers']
即将成为null
,因此您无法在其上调用map
function 。 这就是错误来的原因。
因此,在您尝试使用map
访问它之前,请检查List
是否确实存在。
您可以在您的情况下使用集合来执行此操作,如果,
children: [
Question(questions[_questionIndex]['questionText']),
if (questions[_questionIndex]['answers'] != null)
...(questions[_questionIndex]['answers'] as List<String>)
.map((answer) => Answer(_answerQuestion, answer)).toList(),
],
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.