繁体   English   中英

在 flutter 中使用 map 时出现 NoSuchMethodError

[英]NoSuchMethodError while using map in flutter

请帮助..在模拟器上运行应用程序时发生错误....NoSuchMethodError我的代码和模拟器的屏幕截图

由于您的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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM