Repository navigation
Description
Confusing error message is :
'When an inherited widget changes, for example if the value of Theme.of() changes, '
"its dependent widgets are rebuilt. If the dependent widget's reference to "
'the inherited widget is in a constructor or an initState() method, '
'then the rebuilt dependent widget will not reflect the changes in the '
'inherited widget.'
In fact , when similar usage of inherited widget (example: Theme.of()) is in constructor indeed will not reflect the changes .
when in initState()indeed will reflect the changes .
Cause,state.initState() and state.didChangeDependencies() are both in _firstBuild which indeed after super.mount when element first mount, So "If the dependent widget's reference to the inherited widget is in an initState() method then the rebuilt dependent widget will reflect the changes in the inherited widget"
OverAll , I think the _StateLifecycle should make a litte change :
Before chagne :

After chagne :
enum _StateLifecycle {
/// The [State] object has been created. [State.initState] is called at this
/// time.
created,
/// ------- Add -----------
beforeInitialized;
/// The [State.initState] method has been called but the [State] object is
/// not yet ready to build. [State.didChangeDependencies] is called at this time.
initialized,
/// The [State] object is ready to build and [State.dispose] has not yet been
/// called.
ready,
/// The [State.dispose] method has been called and the [State] object is
/// no longer able to build.
defunct,
}
_firstBuild code flow should be :
_firstBuild {
assert(state._debugLifecycleState == _StateLifecycle.created);
assert(() {
state._debugLifecycleState = _StateLifecycle.beforeInitialized;
return true;
}());
...
state.initState();
...
assert(() {
state._debugLifecycleState = _StateLifecycle.initialized;
return true;
}());
...
state.didChangeDependencies();
...
assert(() {
state._debugLifecycleState = _StateLifecycle.ready;
return true;
}());
...
}

Activity
maheshj01 commentedon Jun 10, 2022
Hi @Stitch-Taotao, Thanks for filing the issue. Labeling this issue for further insights from the team
Fold the two initState-dependency tests into one
Fold the two initState-dependency tests into one
Explain why initState() is too early to depend on an inherited widget (…
github-actions commentedon Oct 27, 2026
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.Explain why initState() is too early to depend on an inherited widget (…