【发布时间】:2023-02-04 20:50:58
【问题描述】:
我试图为问题创建一个类,以便我可以在我的测验应用程序的 main.dart 文件中使用它,但我遇到了一些错误。请告诉我为什么会出现这些错误,我该如何解决?
类问题:
class Question {
String questionText;
bool questionAnswer;
Question({String q, bool a}) {
questionText = q;
questionAnswer = a;
}
}
错误:
Non-nullable instance field 'questionAnswer' must be initialized.
Non-nullable instance field 'questionText' must be initialized.
The parameter 'q' can't have a value of 'null' because of its type, but the implicit default value is 'null'.
The parameter 'a' can't have a value of 'null' because of its type, but the implicit default value is 'null'.
【问题讨论】: