Home > Enterprise >  The argument type 'Null' can't be assigned to the parameter type 'PatientPrescri
The argument type 'Null' can't be assigned to the parameter type 'PatientPrescri

Time:03-25

How to fix this error.

enter image description here

My code

_patientDocument, patientDocument: [], patientPrescription: null,); //NULL ERROR

CodePudding user response:

Make patientPrescription a nullable variable. Here is how to create a nullable variable in dart- "Put a question mark after the datatype". For example, let us create a String variable called "apple" as follows-

main(){
   String apple="hello";
   apple=null;
  print(apple);
}

Now, dart will give an error. However, if I replace String with String?, the error will be gone.


main(){
   String? apple="hello";
   apple=null;
  print(apple);
}

Similarly, int can be replaced with int?, double can be replaced with double? I hope this helped.

  • Related