skip to Main Content

i am trying to pass a custom object called "Lesson" to a screen called "ExamScreen"
here is the call:

goStepScreen(int statusId, Lesson lesson, BuildContext context) {
  if (statusId == SessionStates.Revision.getStatus()) {
    navigateTo(context, const ExamScreen(lesson: lesson,));

and the exam screen:

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 {

i get error Invalid constant value

how can i solve it

2

Answers


  1. Remove the const keyword from the ExamScreen constructor like this:

    class ExamScreen extends StatefulWidget {
      final Lesson? lesson;
      ExamScreen({super.key,  this.lesson}); // Here
    
      @override
      State<ExamScreen> createState() => _ExamScreenState();
    }
    
    Login or Signup to reply.
  2. Remove the const keyword from the navigateTo

    navigateTo(context, const ExamScreen(lesson: lesson,));
    

    You receive this error because lesson isn’t a constant value, so you cannot create a constant instance.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search