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

Issue

How to fix this error.

enter image description here

My code

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

Solution

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.

Answered By – DHRUV BADAYA

Answer Checked By – Candace Johnson (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published.