【问题标题】:The parameter 'questions' can't have a value of 'null' because of its type 'List<Map<String, Object>>', but the implicit default value is 'null'参数“questions”的值不能为“null”,因为它的类型为“List<Map<String, Object>>”,但隐含的默认值为“null”
【发布时间】:2021-10-26 04:55:56
【问题描述】:

我是 Flutter 的新手 使用 VS Code 和颤振版本 - 2.12.0

我的问题是我正在使用 contructor 将一个列表、一个函数和一个 int 值从一个 dart 类传递到另一个类,但是它们都出错了。

  1. 参数“questions”的值不能为“null”,因为它的类型为“List>”,但隐含的默认值为“null”。

  2. 参数“answerQuestion”的值不能为“null”,因为它的类型为“Function”,但隐含的默认值为“null”。

  3. 参数'index'不能有'null'的值,因为它的类型是'int',但是隐含的默认值是'null'。

这是我的代码 -

main.dart

quiz.dart

感谢您的帮助

【问题讨论】:

标签: flutter null implicit


【解决方案1】:

问题出在 Quiz 构造函数中

不是这个

const Quiz(
  {@required this.questions,
  @required this.answerQuestion,
  @required this.index});

这样声明

const Quiz(
      {required this.questions,
      required this.answerQuestion,
      required this.index});

【讨论】:

  • 先生,请检查我刚才在问题中添加的图像。
猜你喜欢
  • 2021-06-24
  • 2021-10-28
  • 2021-11-12
  • 2022-01-03
  • 2022-01-20
  • 1970-01-01
  • 2022-08-13
  • 2021-09-05
  • 2021-08-19
相关资源
最近更新 更多