skip to Main Content

Trying to pass null in a list.add(null) call but unable to do this since migrating to the null safety update.

this is the error on bloc

image

this is the model

I have tried adding ?. to the List but having no luck in fixing this.

3

Answers


  1. You need to change 1 line in your model class…

    List<ProductCategory> categoryController;
    

    TO

    List<ProductCategory?> categoryController;
    

    Add question mark after ProductCategory will make that list item nullable.

    Login or Signup to reply.
  2. try to make your list like this

    List< yourObject ? > categoryController;
    
    Login or Signup to reply.
  3. You need to make StreamController‘s dataType nullable, to add null.

    final StreamController<List<ProductCategory>?> categoriesController;
    

    Find more about understanding-null-safety.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search