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});
Author by
Krishna
Updated on December 07, 2022Comments
-
Krishna over 1 year
i 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.
-
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'.
-
The parameter 'answerQuestion' can't have a value of 'null' because of its type 'Function', but the implicit default value is 'null'.
-
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 -
Thanks for help
-
jamesdlin over 2 yearsYou need to replace the old
@required
annotation with the newrequired
keyword (which was added for null-safety). See dart.dev/null-safety/… -
jamesdlin over 2 years
-
jamesdlin over 2 yearsVS Code seems to be confused, thinking that you're trying to use
required
frompackage:meta
instead of therequired
language keyword. That shouldn't happen. Perhaps try restarting VS Code. -
Krishna over 2 years@jamesdlin no sir this didn't helped, did restart many times
-
t00n over 2 yearsadd full Quiz code
-
jamesdlin over 2 yearsPost your
pubspec.yaml
file. Did you somehow change thesdk
constraint before changing@required
torequired
? Thesdk
constraint should besdk: '>=2.12.0 < 3.0.0'
-
Krishna over 2 years@t00n check the link sir
-
Krishna over 2 years@jamesdlin it is unchanged ..
-
Krishna over 2 yearsctxt.io/2/AACgi48TEg @jamesdlin see here
-
jamesdlin over 2 yearsDo 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 over 2 years@jamesdlin ctxt.io/2/AACgN1wyEw
-
Krishna over 2 yearsyes it also shows same error
-
jamesdlin over 2 yearsNo, I mean do you have problems running your application and running
flutter analyze
after replacing@required
withrequired
. -
jamesdlin over 2 yearsLet us continue this discussion in chat.
-
Krishna over 2 years@jamesdlin yes sir the above screenshot is after doing
@required
to required
-
-
Krishna over 2 yearssir check the image i have added in the question just now..
-
Krishna over 2 yearssir check the image i have added in the question just now.