Home > OS >  Pass 'Null' to a list. Null Safety
Pass 'Null' to a list. Null Safety

Time:01-13

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.

CodePudding user response:

You need to make StreamController's dataType nullable, to add null.

final StreamController<List<ProductCategory>?> categoriesController;

Find more about understanding-null-safety.

CodePudding user response:

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.

CodePudding user response:

try to make your list like this

List< yourObject ? > categoryController;
  • Related