Bloc: get Value from BlocProvider in InitState

Created on 11 Apr 2020  路  2Comments  路  Source: felangel/bloc

hi sorry i just new and still learning your package.
in provider to get value on initstate as simple like below :
initState() {
super.initState();
print(Provider.of(context).value);
}

how on flutter_package to get the value?

if i have class like below

class idcompanybloc extends Bloc{

@override
String get initialState => '';

@override
Stream mapEventToState(String idcompany) async* {
yield idcompany.toString();
}
}

thank you

i have put on stackoverflow : https://stackoverflow.com/questions/61043649/blocprovider-inside-initstate-that-receive-value-from-blocbuilder

question

Most helpful comment

THANKS ALOT BRO!!! you r a live saver!!
it work so good right now. thanks alot!

All 2 comments

Hi @kartzhai 馃憢
Thanks for opening an issue!

You can access the current state of the bloc like:

BlocProvider.of<MyBloc>(context).state;

or via the shorthand

context.bloc<MyBloc>().state;

Hope that helps 馃憤

THANKS ALOT BRO!!! you r a live saver!!
it work so good right now. thanks alot!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

timtraversy picture timtraversy  路  3Comments

craiglabenz picture craiglabenz  路  3Comments

krusek picture krusek  路  3Comments

clicksocial picture clicksocial  路  3Comments

1AlexFix1 picture 1AlexFix1  路  3Comments