I am new to flutter and when I want to call my context in InitState it throws an error :
which is about
BuildContext.inheritFromWidgetOfExactType
but then I use did
You cannot use
BuildContext.inheritFromWidgetOfExactType
from this method. However,didChangeDependencies
will be called immediately following this method, andBuildContext.inheritFromWidgetOfExactType
can be used there.
So you need to use BuildContext.inheritFromWidgetOfExactType
in didChangeDependencies
.
context
. That is why you have access to context outside build method. Regarding build(BuildContext context)
, build
method accepts context
from the parent widget. It means this parameter BuildContext context
is not current widget's context but its parent's context.