Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Invalid constant value when passing custom object as a screen parameter in flutter

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

how can i solve it

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading