I was looking in your example and I saw in https://github.com/felangel/bloc/blob/master/examples/flutter_todos/lib/screens/home_screen.dart
_filteredTodosBloc = FilteredTodosBloc(
todosBloc: BlocProvider.of<TodosBloc>(context),
);
Is this safe to use the context in initState? Reading the all the documentation around everybody is saying not to use context in initState. Can you explain why is ok using as you did.
I am doing always in didChangeDependencies something like _filteredTodosBloc ??= ...
Hi @cosinus84 馃憢
Thanks for opening an issue!
Great observation and normally I would recommend accessing inheritedWidgets in didChangeDependencies but with BlocProvider it works in initState because it uses ancestorInheritedElementForWidgetOfExactType combined withupdateShouldNotify(BlocProvider oldWidget) => false;
Normally if you're using inheritFromWidgetOfExactType and support notifying on updates then you wouldn't be able to access it in initState as you mentioned.
Hope that helps and great question 馃挴
Most helpful comment
Hi @cosinus84 馃憢
Thanks for opening an issue!
Great observation and normally I would recommend accessing inheritedWidgets in
didChangeDependenciesbut with BlocProvider it works ininitStatebecause it usesancestorInheritedElementForWidgetOfExactTypecombined withupdateShouldNotify(BlocProvider oldWidget) => false;Normally if you're using
inheritFromWidgetOfExactTypeand support notifying on updates then you wouldn't be able to access it ininitStateas you mentioned.Hope that helps and great question 馃挴