>',但隐含的默认值为'null',flutter,null,implicit"/>

首页 > 解决方案 > 参数“问题”的值不能为“空”,因为它的类型为“列表”>',但隐含的默认值为'null'

问题描述

在此处输入图像描述我是使用 VS Code 和颤振版本颤振的新手 - 2.12.0 <3.0.0

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

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

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

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

这是我的代码 -

主要.dart

测验.dart

感谢帮助

标签: flutternullimplicit

解决方案


问题出在 Quiz 构造函数中

而不是这个

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

像这样声明

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

推荐阅读