Skip to content

Improve dependOnInheritedWidgetOfExactType documentation to explain why it is bad to use it in initState#186216

Merged
auto-submit[bot] merged 7 commits into
flutter:masterfrom
AbdeMohlbi:issue_73423
Jun 1, 2026
Merged

Improve dependOnInheritedWidgetOfExactType documentation to explain why it is bad to use it in initState#186216
auto-submit[bot] merged 7 commits into
flutter:masterfrom
AbdeMohlbi:issue_73423

Conversation

@AbdeMohlbi

@AbdeMohlbi AbdeMohlbi commented May 7, 2026

Copy link
Copy Markdown
Member

Fixes #73423

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

If this change needs to override an active code freeze, provide a comment explaining why. The code freeze workflow can be overridden by code reviewers. See pinned issues for any active code freezes with guidance.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label May 7, 2026
@github-actions github-actions Bot added the framework flutter/packages/flutter repository. See also f: labels. label May 7, 2026
@AbdeMohlbi AbdeMohlbi changed the title Improve dependOnInheritedWidgetOfExactType documentation to explain why it is bad to use it in iniState Improve dependOnInheritedWidgetOfExactType documentation to explain why it is bad to use it in iniState May 7, 2026
@AbdeMohlbi AbdeMohlbi marked this pull request as ready for review May 7, 2026 21:35
@github-actions github-actions Bot removed the CICD Run CI/CD label May 7, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the documentation in framework.dart to clarify the behavior of BuildContext methods when called from initState and didChangeDependencies. The review feedback suggests improving the documentation's readability and formality by using standard terminology and ensuring grammatical parallelism in the descriptions.

Comment thread packages/flutter/lib/src/widgets/framework.dart Outdated
Comment thread packages/flutter/lib/src/widgets/framework.dart Outdated
@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label May 7, 2026
@AbdeMohlbi AbdeMohlbi marked this pull request as draft May 7, 2026 21:46
/// Calling this method is O(1) with a small constant factor, but will lead to
/// the widget being rebuilt more often.
///
/// Once a widget registers a dependency on a particular type by calling this

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm still not sure if this part is redundant after the new explanation in line 2425, i think getting a review is the best option here.

@AbdeMohlbi AbdeMohlbi marked this pull request as ready for review May 7, 2026 21:50

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the documentation for BuildContext to clarify why certain methods should not be called in initState and explains how didChangeDependencies handles inherited widget updates. Feedback suggests restoring a removed detail regarding the dependency lifecycle—specifically that dependencies persist until a widget or ancestor is moved—and using singular phrasing for increased precision.

Comment thread packages/flutter/lib/src/widgets/framework.dart Outdated
@github-actions github-actions Bot removed the CICD Run CI/CD label May 7, 2026
@AbdeMohlbi AbdeMohlbi added the CICD Run CI/CD label May 7, 2026
Comment on lines +2418 to +2420
/// If the inherited value changes, the widget will rebuild, but any logic
/// or variables initialized inside the constructor or [State.initState]
/// will not execute again, leaving the widget with stale data.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not exactly clear from this sentence that logic/variables initialized in the constructor or State.initState not re-executing is a bad thing. I think you need to highlight the dependency on the inherited value to make the connection here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think the latest commit should clear things up.

victorsanni
victorsanni previously approved these changes May 7, 2026
@github-actions github-actions Bot removed the CICD Run CI/CD label May 7, 2026
@AbdeMohlbi AbdeMohlbi added the CICD Run CI/CD label May 7, 2026
@AbdeMohlbi AbdeMohlbi changed the title Improve dependOnInheritedWidgetOfExactType documentation to explain why it is bad to use it in iniState Improve dependOnInheritedWidgetOfExactType documentation to explain why it is bad to use it in initState May 12, 2026
@github-actions github-actions Bot removed the CICD Run CI/CD label May 17, 2026
@Piinks Piinks requested a review from victorsanni May 26, 2026 23:14
@victorsanni victorsanni added the CICD Run CI/CD label May 30, 2026
@AbdeMohlbi AbdeMohlbi added the autosubmit Merge PR when tree becomes green via auto submit App label May 30, 2026
@auto-submit

auto-submit Bot commented May 30, 2026

Copy link
Copy Markdown
Contributor

autosubmit label was removed for flutter/flutter/186216, because The base commit of the PR is older than 7 days and can not be merged. Please merge the latest changes from the main into this branch and resubmit the PR.

@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label May 30, 2026
@github-actions github-actions Bot removed the CICD Run CI/CD label May 30, 2026
@AbdeMohlbi AbdeMohlbi added autosubmit Merge PR when tree becomes green via auto submit App CICD Run CI/CD labels May 30, 2026
@auto-submit auto-submit Bot added this pull request to the merge queue Jun 1, 2026
Merged via the queue into flutter:master with commit 0243134 Jun 1, 2026
94 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jun 1, 2026
auto-submit Bot pushed a commit to flutter/packages that referenced this pull request Jun 1, 2026
flutter/flutter@b05a9d7...54e199a

2026-06-01 engine-flutter-autoroll@skia.org Roll Fuchsia Linux SDK from jMR_VXQi07kAk8vbR... to q27k7_um1GvVrySZS... (flutter/flutter#187338)
2026-06-01 rmacnak@google.com Remove use of deprecated API related to removal of the VM isolate. (flutter/flutter#187013)
2026-06-01 116356835+AbdeMohlbi@users.noreply.github.com Improve `dependOnInheritedWidgetOfExactType` documentation to explain why it is bad to use it in initState (flutter/flutter#186216)
2026-06-01 chris@bracken.jp Revert "Move dart-lang/ai to a top level third party dependency in en… (flutter/flutter#187370)
2026-05-30 jakemac@google.com Move dart-lang/ai to a top level third party dependency in engine (flutter/flutter#187268)
2026-05-30 evanwall@buffalo.edu add sdf golden variants for OpenGL (flutter/flutter#187246)
2026-05-30 engine-flutter-autoroll@skia.org Roll Skia from dc01525ac468 to 0aee4675e0ad (6 revisions) (flutter/flutter#187334)
2026-05-29 engine-flutter-autoroll@skia.org Roll Skia from c480ba2eb2eb to dc01525ac468 (4 revisions) (flutter/flutter#187317)
2026-05-29 jason-simmons@users.noreply.github.com Remove the Y coordinate flip workaround in the Material stretch effect shader now that it is no longer required by the Impeller GLES back end (flutter/flutter#187247)
2026-05-29 bkonyi@google.com [flutter_tools, devicelab] Fix filesystem safety guard for symlinked temp directories (flutter/flutter#187320)
2026-05-29 30870216+gaaclarke@users.noreply.github.com Brings linux tests out of bringup. (flutter/flutter#187271)
2026-05-29 137456488+flutter-pub-roller-bot@users.noreply.github.com Roll pub packages (flutter/flutter#187321)
2026-05-29 engine-flutter-autoroll@skia.org Roll Fuchsia GN SDK from SEfYx3xgueX3aFAY3... to oOAcFhkoE2_-Sy67z... (flutter/flutter#187310)
2026-05-29 36861262+QuncCccccc@users.noreply.github.com Fix mismatch between hit-test tree and traversal tree (flutter/flutter#186826)
2026-05-29 jason-simmons@users.noreply.github.com [Impeller] Ensure that the TextureGLES destructor cleans up all objects that it holds including the sync fence (flutter/flutter#187216)
2026-05-29 engine-flutter-autoroll@skia.org Roll Packages from 10cbdc5 to e930ced (3 revisions) (flutter/flutter#187306)
2026-05-29 engine-flutter-autoroll@skia.org Roll Skia from d9d6b440c4e7 to c480ba2eb2eb (1 revision) (flutter/flutter#187305)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC stuartmorgan@google.com,tarrinneal@google.com on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
creatorpiyush pushed a commit to creatorpiyush/packages that referenced this pull request Jun 10, 2026
…r#11816)

flutter/flutter@b05a9d7...54e199a

2026-06-01 engine-flutter-autoroll@skia.org Roll Fuchsia Linux SDK from jMR_VXQi07kAk8vbR... to q27k7_um1GvVrySZS... (flutter/flutter#187338)
2026-06-01 rmacnak@google.com Remove use of deprecated API related to removal of the VM isolate. (flutter/flutter#187013)
2026-06-01 116356835+AbdeMohlbi@users.noreply.github.com Improve `dependOnInheritedWidgetOfExactType` documentation to explain why it is bad to use it in initState (flutter/flutter#186216)
2026-06-01 chris@bracken.jp Revert "Move dart-lang/ai to a top level third party dependency in en… (flutter/flutter#187370)
2026-05-30 jakemac@google.com Move dart-lang/ai to a top level third party dependency in engine (flutter/flutter#187268)
2026-05-30 evanwall@buffalo.edu add sdf golden variants for OpenGL (flutter/flutter#187246)
2026-05-30 engine-flutter-autoroll@skia.org Roll Skia from dc01525ac468 to 0aee4675e0ad (6 revisions) (flutter/flutter#187334)
2026-05-29 engine-flutter-autoroll@skia.org Roll Skia from c480ba2eb2eb to dc01525ac468 (4 revisions) (flutter/flutter#187317)
2026-05-29 jason-simmons@users.noreply.github.com Remove the Y coordinate flip workaround in the Material stretch effect shader now that it is no longer required by the Impeller GLES back end (flutter/flutter#187247)
2026-05-29 bkonyi@google.com [flutter_tools, devicelab] Fix filesystem safety guard for symlinked temp directories (flutter/flutter#187320)
2026-05-29 30870216+gaaclarke@users.noreply.github.com Brings linux tests out of bringup. (flutter/flutter#187271)
2026-05-29 137456488+flutter-pub-roller-bot@users.noreply.github.com Roll pub packages (flutter/flutter#187321)
2026-05-29 engine-flutter-autoroll@skia.org Roll Fuchsia GN SDK from SEfYx3xgueX3aFAY3... to oOAcFhkoE2_-Sy67z... (flutter/flutter#187310)
2026-05-29 36861262+QuncCccccc@users.noreply.github.com Fix mismatch between hit-test tree and traversal tree (flutter/flutter#186826)
2026-05-29 jason-simmons@users.noreply.github.com [Impeller] Ensure that the TextureGLES destructor cleans up all objects that it holds including the sync fence (flutter/flutter#187216)
2026-05-29 engine-flutter-autoroll@skia.org Roll Packages from 10cbdc5 to e930ced (3 revisions) (flutter/flutter#187306)
2026-05-29 engine-flutter-autoroll@skia.org Roll Skia from d9d6b440c4e7 to c480ba2eb2eb (1 revision) (flutter/flutter#187305)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC stuartmorgan@google.com,tarrinneal@google.com on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
via-guy pushed a commit to via-guy/flutter that referenced this pull request Jun 26, 2026
… why it is bad to use it in initState (flutter#186216)

Fixes flutter#73423

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [AI contribution guidelines] and understand my
responsibilities, or I am not using AI tools.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [ ] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [ ] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

If this change needs to override an active code freeze, provide a
comment explaining why. The code freeze workflow can be overridden by
code reviewers. See pinned issues for any active code freezes with
guidance.

**Note**: The Flutter team is currently trialing the use of [Gemini Code
Assist for
GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code).
Comments from the `gemini-code-assist` bot should not be taken as
authoritative feedback from the Flutter team. If you find its comments
useful you can update your code accordingly, but if you are unsure or
disagree with the feedback, please feel free to wait for a Flutter team
member's review for guidance on which automated comments should be
addressed.

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[AI contribution guidelines]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#ai-contribution-guidelines
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Clarify/improve dependOnInheritedWidgetOfExactType documentation?

3 participants