i am using flutter_bloc, and i am wondering which method should i use and what is the difference between these two ways?: i read that the first one with (value) the bloc will not automatically closed, but actually i don't understand what is mean?
BlocProvider<LoginBloc>.value(
value: (LoginBloc(LoginInitialState(), AuthRepository())),
),
BlocProvider<ProfileBloc>(
create: (context) => ProfileBloc(ProfileInitialState(), AuthRepository()),
),
As far as I understand it, you would use:
when you have already created a
bloc
in a differentBlocProvider
and you just want that same bloc to be available somewhere else in the widget tree.I'm assuming that because this
bloc
wasn't created by theBlocProvider
you're currently using (withBlocProvider.value
) it won't handle closing thebloc
- that will be done by the originalBlocProvider
.So unless the
bloc
that you want to use doesn't exist somewhere else already, you can probably just use the normal method withcreate
.