'The argument type 'Null' can't be assigned to the parameter type 'PatientPrescription'

How to fix this error.

enter image description here

My code

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



Solution 1:[1]

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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 lightlessdays