Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Error when using Flutter "list":: Field 'students' should be initialized because its type 'List<Student>' doesn't allow null

I’m new to flutter and I ran into a problem while writing on my own computer because my instructor was using an old version.

class StudentAdd extends StatefulWidget {
 List<Student> students;
 StudentAdd(List<Student> students){
  this.students=students;

Error: Field ‘students’ should be initialized because its type
‘List’ doesn’t allow null.

I am getting the above error and could not fix it. As far as I looked through the documents, I couldn’t find any results.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

StudentAdd(List students){

I get an error where I bold it and the error I get is: Non-nullable instance field ‘students’ must be initialized.

>Solution :

initialize ot as empty list instead of leaving it with null value

List<Student> students = <Student>[];
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading