我正在尝试将名为“Lesson”的自定义对象传递到名为“ExamScreen”的屏幕 这是电话:
goStepScreen(int statusId, Lesson lesson, BuildContext context) {
if (statusId == SessionStates.Revision.getStatus()) {
navigateTo(context, const ExamScreen(lesson: lesson,));
和考试屏幕:
class ExamScreen extends StatefulWidget {
final Lesson? lesson;
const ExamScreen({super.key, this.lesson});
@override
State<ExamScreen> createState() => _ExamScreenState();
}
class _ExamScreenState extends State<ExamScreen> with WidgetsBindingObserver {
我收到错误
Invalid constant value
我该如何解决
从 ExamScreen 构造函数中删除 const 关键字,如下所示:
class ExamScreen extends StatefulWidget {
final Lesson? lesson;
ExamScreen({super.key, this.lesson}); // Here
@override
State<ExamScreen> createState() => _ExamScreenState();
}