Reputation: 763
Widget build(BuildContext context) {
final blocData = WeatherBlocProvider.of(context).bloc;
if (WeatherBloc.permission == true) {
blocData.forceRefreshAll();
return Container(
child: StreamBuilder(
stream: blocData.zipAll,
builder: (scontext, snapshot){
//to do
}
now i am using bloc pattern with streambuilder
and when i refresh parent widget i can see blocData.forceRefreshAll()
this line is requested twice.(i mean build method is requested twice) how can i make only one?
i saw unwanted rebuild subject
and they said use instance or initstate but with bloc pattern i think using initstate is not possible and const value is not working with
blocData.forceRefreshAll()
Upvotes: 0
Views: 1381
Reputation: 2711
build
method is meant to build widget tree, it can be called multiple times for various reasons. This is why should not fetch data in build
.
If you can't access bloc in initState
because there is no context
yet - override another method, didChangeDependencies
. It's called right after initState
and it can use context
, so you can access bloc provider with it.
Upvotes: 2