Search code examples
flutterdartdart-null-safety

Pass 'Null' to a list. Null Safety


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.


Solution

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

    final StreamController<List<ProductCategory>?> categoriesController;
    

    Find more about understanding-null-safety.