The parameter 'questions' can't have a value of 'null' because of its type 'List<Map<String, Object>>', but the implicit default value is 'null'

327

The problem is in the Quiz constructor

Instead of this

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

Declare it like this

const Quiz(
      {required this.questions,
      required this.answerQuestion,
      required this.index});
Share:
327
Krishna
Author by

Krishna

Updated on December 07, 2022

Comments

  • Krishna
    Krishna over 1 year

    enter image description herei am new to flutter using VS Code and flutter version - 2.12.0 <3.0.0

    My problem is i am passing a list, a function and an int value from one dart class to another using contructor , but getting error in all of them.

    1. The parameter 'questions' can't have a value of 'null' because of its type 'List<Map<String, Object>>', but the implicit default value is 'null'.

    2. The parameter 'answerQuestion' can't have a value of 'null' because of its type 'Function', but the implicit default value is 'null'.

    3. The parameter 'index' can't have a value of 'null' because of its type 'int', but the implicit default value is 'null'.

    here is my code -

    main.dart

    quiz.dart

    Thanks for help

    • jamesdlin
      jamesdlin over 2 years
      You need to replace the old @required annotation with the new required keyword (which was added for null-safety). See dart.dev/null-safety/…
    • jamesdlin
      jamesdlin over 2 years
    • jamesdlin
      jamesdlin over 2 years
      VS Code seems to be confused, thinking that you're trying to use required from package:meta instead of the required language keyword. That shouldn't happen. Perhaps try restarting VS Code.
    • Krishna
      Krishna over 2 years
      @jamesdlin no sir this didn't helped, did restart many times
    • t00n
      t00n over 2 years
      add full Quiz code
    • jamesdlin
      jamesdlin over 2 years
      Post your pubspec.yaml file. Did you somehow change the sdk constraint before changing @required to required? The sdk constraint should be sdk: '>=2.12.0 < 3.0.0'
    • Krishna
      Krishna over 2 years
      @t00n check the link sir
    • Krishna
      Krishna over 2 years
      @jamesdlin it is unchanged ..
    • Krishna
      Krishna over 2 years
      ctxt.io/2/AACgi48TEg @jamesdlin see here
    • jamesdlin
      jamesdlin over 2 years
      Do you actually have a problem when running your application? Does manually running flutter analyze report the same problems? If no, then again, the problem is that the Dart plug-in for VS Code is confused.
    • Krishna
      Krishna over 2 years
    • Krishna
      Krishna over 2 years
      yes it also shows same error
    • jamesdlin
      jamesdlin over 2 years
      No, I mean do you have problems running your application and running flutter analyze after replacing @required with required.
    • jamesdlin
      jamesdlin over 2 years
    • Krishna
      Krishna over 2 years
      @jamesdlin yes sir the above screenshot is after doing @required to required
  • Krishna
    Krishna over 2 years
    sir check the image i have added in the question just now..
  • Krishna
    Krishna over 2 years
    sir check the image i have added in the question just now.