Repository navigation
Prevent looking up inherited widget values from initState() - #5609
Merged
HansMuller merged 5 commits intoAug 26, 2016
Merged
Conversation
Contributor
Author
|
cc @Hixie |
Contributor
|
Let's talk tomorrow about how to still enable this for the rare cases where it's done right for a good reason... |
HansMuller
force-pushed
the
inherited_widget_initstate
branch
from
August 26, 2016 17:39
f25f0f2 to
a0971ad
Compare
| // changes to the inherited widgets that _resolveImage depends on, notably | ||
| // DefaultAssetBundle, are handle by the dependenciesChanged() method. We're | ||
| // doing it here instead to avoid the assert that disallows references to | ||
| // inherited widgets at initState() time. |
Contributor
There was a problem hiding this comment.
"...because we have found that asserts catches bugs frequently, and is therefore worth this minor inconvenience here."
| // DefaultAssetBundle, are handle by the dependenciesChanged() method. We're | ||
| // doing it here instead to avoid the assert that disallows references to | ||
| // inherited widgets at initState() time. We've found that assert to be a reliable | ||
| // source of real bugs, and is therefore worth this minor inconvenience here. |
Contributor
There was a problem hiding this comment.
nitty nit nit: oops, my grammar was bad. "and that it is" rather than "and is".
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Looking up an inherited widget with
BuildContext.inheritFromWidgetOfExactType()from an initState() method now causes an assert.Static methods like Theme.of() use inheritFromWidgetOfExactType(). Using it at initState() time is ill-advised because updates to the inherited widget only cause the dependent widget to rebuild. Initializations based on the inherited widget that occur in initState() will not rerun when the widget is rebuilt.
There were a handful of cases like this in the code base.
Fixes #5491