Bloc: Bloc : For a Bloc we need to have dispose or we need to do stuff on dispose.

Created on 7 Sep 2019  路  4Comments  路  Source: felangel/bloc

we have a Location bloc for current location, and we run a location subscription as far after every specific interval we receive current location values.
When we move on to another screen where we don't want to have location of user, or some how improve the usability we need to close service.
We can't dispatch an event for this in dispose of the Bloc.

@override void dispose() { _dispose(); super.dispose(); }

question

Most helpful comment

Hi @dev-shanghai 馃憢
Thanks for opening an issue!

Regarding your question, as @bigworld12 mentioned, if you're using BlocProvider to provide your LocationBloc like:

BlocProvider(
  builder: (context) => LocationBloc(),
  child: MyChild(),
)

then BlocProvider will handle automatically disposing the bloc for you so you don't need to do anything.

Hope that helps 馃憤

All 4 comments

if you have your bloc provider around the specific area where you need it, then it already disposes of the bloc once that area is disposed

Hi @dev-shanghai 馃憢
Thanks for opening an issue!

Regarding your question, as @bigworld12 mentioned, if you're using BlocProvider to provide your LocationBloc like:

BlocProvider(
  builder: (context) => LocationBloc(),
  child: MyChild(),
)

then BlocProvider will handle automatically disposing the bloc for you so you don't need to do anything.

Hope that helps 馃憤

Thank you guys for providing correct and in accordance information.

@felangel Thanks for such useful information!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hivesey picture hivesey  路  3Comments

ricktotec picture ricktotec  路  3Comments

rsnider19 picture rsnider19  路  3Comments

shawnchan2014 picture shawnchan2014  路  3Comments

krusek picture krusek  路  3Comments