Answers for "dependOnInheritedWidgetOfExactType<_InheritedProviderScope<>>() or dependOnInheritedElement() was called before .initState() completed."

0

dependOnInheritedWidgetOfExactType<_InheritedProviderScope<>>() or dependOnInheritedElement() was called before .initState() completed.

Issue is Provider.of(context) is supposed to be used inside the widget tree, 
and anything that is outside of the build() method, is not in the widget tree.
But if you still want to use it, then you need to set the listen parameter to 
false.

Example:
@override
void initState() {
  final _searchProvider = Provider.of<SearchProvider>(context, listen: false);
  super.initState();
}
Posted by: Guest on July-11-2021

Code answers related to "dependOnInheritedWidgetOfExactType<_InheritedProviderScope<>>() or dependOnInheritedElement() was called before .initState() completed."

Browse Popular Code Answers by Language