Bloc: Close instances of `dart.core.Sink`. warning by IDE

Created on 18 Nov 2020  路  3Comments  路  Source: felangel/bloc

Documentation
Screenshot 2020-11-18 at 5 44 48 PM

My implementation
Screenshot 2020-11-18 at 5 44 37 PM

Got a warning by my IDE saying
Close instances ofdart.core.Sink``

The implementation should be correct based on the docs but there is waring.
Is the code violating anything? and if not, is there any plans to refactor to get rid of the warning?

Cheers

question

All 3 comments

In this way, you're manually accessing your bloc. To solve this, dispose your provider by calling customerBloc?.close() in your dispose().

@momoDragon what you鈥檙e doing is perfectly fine and the warning is a false positive from the dart linter. There鈥檚 an open issue for this but in the meantime you can disable close_sinks in your analysis_options.yaml. You shouldn鈥檛 need to call close because BlocProvider does that for you.

See https://github.com/felangel/bloc/issues/587 for more details.

Thanks for the info @felangel

I found that getting state just once this would be ideal for my case.
CustomerState customerState = BlocProvider.of<CustomerBloc>(context).state;

@shaan-saz Calling .close() actually closes my bloc. so to get the bloc once and close it was not wise in my case.

Anyway thanks for the help

Was this page helpful?
0 / 5 - 0 ratings