Document super call order for State.didChangeDependencies by fahaddoc · Pull Request #185945 · flutter/flutter · GitHub
Skip to content

Document super call order for State.didChangeDependencies - #185945

Merged
auto-submit[bot] merged 3 commits into
flutter:masterfrom
fahaddoc:fix/28925-didchangedependencies-super-doc
Aug 5, 2026
Merged

Document super call order for State.didChangeDependencies#185945
auto-submit[bot] merged 3 commits into
flutter:masterfrom
fahaddoc:fix/28925-didchangedependencies-super-doc

Conversation

@fahaddoc

@fahaddoc fahaddoc commented May 3, 2026

Copy link
Copy Markdown
Contributor

The doc comment on State.didChangeDependencies is silent about where overrides should place the super.didChangeDependencies() call, even though @mustCallSuper is set on it. The sibling lifecycle hook State.initState already documents this convention, so the two methods read inconsistently and contributors hitting didChangeDependencies for the first time have to guess.

This PR adds a short note to the dartdoc that mirrors the wording on initState, telling implementations to start with a call to the inherited method (super.didChangeDependencies()). It is a documentation-only change to packages/flutter/lib/src/widgets/framework.dart. There is no behavior change, no API change, and no new public surface.

Fixes #28925.

Pre-launch Checklist

@github-actions github-actions Bot added the framework flutter/packages/flutter repository. See also f: labels. label May 3, 2026
@google-cla

google-cla Bot commented May 3, 2026

Copy link
Copy Markdown

@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 adds documentation to the didChangeDependencies method in framework.dart, advising that implementations should call the inherited method. A review comment suggests formatting the method reference using square brackets instead of backticks and omitting parentheses to align with Flutter's documentation style and enable dartdoc linking.

Comment on lines +1478 to +1479
/// Implementations of this method should start with a call to the inherited
/// method, as in `super.didChangeDependencies()`.

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.

medium

To maintain consistency with other lifecycle methods in this file (such as initState and didUpdateWidget) and to adhere to the Flutter documentation style, please use square brackets for the method reference instead of backticks. This also enables dartdoc to generate a clickable link to the inherited method. Additionally, the convention in this file is to omit the parentheses when referring to the method in this context.

  /// Implementations of this method should start with a call to the inherited
  /// method, as in [super.didChangeDependencies].
References
  1. The Flutter style guide and Effective Dart recommend using square brackets to refer to identifiers in doc comments to enable linking and maintain a consistent look across the framework's documentation. (link)

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.

Thank you for the update. I have verified the changes and they look correct and follow the requested style guide.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch, switched it over in e8fc173. Now reads [super.didChangeDependencies] so dartdoc renders the link, and dropped the parens to match what initState and didUpdateWidget do right above. Should be consistent with the rest of the file now 🙌

@fahaddoc
fahaddoc force-pushed the fix/28925-didchangedependencies-super-doc branch from 5989016 to e8fc173 Compare May 4, 2026 08:48
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

Gemini is experiencing higher than usual traffic and was unable to create the issue-comment-reply. Please try again in a few hours by commenting /gemini issue-comment-reply.

@justinmc
justinmc self-requested a review May 5, 2026 22:32
justinmc
justinmc previously approved these changes Jun 30, 2026

@justinmc justinmc 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.

LGTM but I'm curious if anyone has a good reason why the super call should be first.

Comment on lines +1478 to +1479
/// Implementations of this method should start with a call to the inherited
/// method, as in [super.didChangeDependencies].

@justinmc justinmc Jun 30, 2026

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.

Can anyone think of a good reason why it should be called first? I browsed the code hoping to find a definitive reason but I don't see one. The framework doesn't seem to do much itself with didChangeDependencies. See @navaronbracke's comment #28925 (comment).

That said, I'm all for providing some guidance and consistency for people here. If we can't find a definitive reason, maybe we should just add "typically", like: "...should typically start with a call..."

@loic-sharma loic-sharma Jun 30, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I agree didChangeDependencies should generally be called first.

Can anyone think of a good reason why it should be called first?

Your State might mix in RestorationMixin. If your didChangeDependencies doesn't call super first, your didChangeDependencies implementation can read a stale restoration bucket.

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.

Thank you for the great example, that's what I was looking for. So then I think we can ignore my "typically" suggestion and keep the PR as-is.

@justinmc justinmc added the CICD Run CI/CD label Jul 1, 2026
loic-sharma
loic-sharma previously approved these changes Jul 14, 2026

@loic-sharma loic-sharma left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the wonderful contribution!

@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Jul 14, 2026
@Piinks Piinks added the CICD Run CI/CD label Jul 21, 2026
@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Jul 22, 2026
@justinmc justinmc added CICD Run CI/CD autosubmit Merge PR when tree becomes green via auto submit App and removed autosubmit Merge PR when tree becomes green via auto submit App labels Jul 28, 2026
@justinmc

Copy link
Copy Markdown
Contributor

@fahaddoc Can you rebase this PR? Sorry I think it needs it to pass CI.

@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Jul 28, 2026
@loic-sharma loic-sharma added the CICD Run CI/CD label Jul 28, 2026
fahaddoc added 2 commits July 29, 2026 12:21
Mirror the guidance already present on State.initState so overrides know
to start with super.didChangeDependencies(). Doc-only change.

Fixes flutter#28925.
Replace `super.didChangeDependencies()` with [super.didChangeDependencies]
so dartdoc renders it as a proper link, matching the convention used
elsewhere in framework.dart.
@fahaddoc
fahaddoc force-pushed the fix/28925-didchangedependencies-super-doc branch from 49ae1d4 to 9bef138 Compare July 29, 2026 07:29
@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Jul 29, 2026
@fahaddoc

Copy link
Copy Markdown
Contributor Author

Done, rebased and force-pushed. Thanks @justinmc 🙏

@loic-sharma loic-sharma added the CICD Run CI/CD label Jul 29, 2026
/// expensive to do for every build.
///
/// Implementations of this method should start with a call to the inherited
/// method, as in [super.didChangeDependencies].

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It looks like CI checks fail because Dartdoc is unhappy with this syntax: https://logs.chromium.org/logs/flutter/buildbucket/cr-buildbucket/8674822439837403393/+/u/run_test.dart_for_docs_shard_and_subshard_None/stdout

dartdoc:stdout: Generating docs for package flutter...
dartdoc:stderr:   error: unresolved doc reference [super.didChangeDependencies]
dartdoc:stderr:     from popup_menu.PopupMenuButtonState.didChangeDependencies: (file:///b/s/w/ir/x/w/flutter/packages/flutter/lib/src/material/popup_menu.dart:1600:8)
dartdoc:stderr:     in documentation inherited from framework.State.didChangeDependencies: (file:///b/s/w/ir/x/w/flutter/packages/flutter/lib/src/widgets/framework.dart:1485:8)

We can fix this by switching to backticks:

Suggested change

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in db73852, thanks!

Dartdoc cannot resolve [super.didChangeDependencies] when the doc
comment is inherited by subclasses such as PopupMenuButtonState, which
fails the docs shard with "unresolved doc reference". Switch back to a
code span, matching how initState, didUpdateWidget, dispose and the
other lifecycle methods in this file refer to their super calls.
@fahaddoc
fahaddoc dismissed stale reviews from justinmc and loic-sharma via db73852 July 31, 2026 07:36
@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Jul 31, 2026
@loic-sharma loic-sharma added the CICD Run CI/CD label Jul 31, 2026

@loic-sharma loic-sharma left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Re-LGTM!

@Piinks
Piinks requested a review from justinmc August 4, 2026 22:26

@justinmc justinmc 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.

LGTM 👍

@justinmc justinmc added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 4, 2026
@auto-submit
auto-submit Bot added this pull request to the merge queue Aug 5, 2026
Merged via the queue into flutter:master with commit 8ef2fe4 Aug 5, 2026
29 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Aug 5, 2026
auto-submit Bot pushed a commit to flutter/packages that referenced this pull request Aug 10, 2026
…12420)

Manual roll requested by stuartmorgan@google.com

flutter/flutter@b766512...27b0988

2026-08-05 kevmoo@users.noreply.github.com reland(tool): remove redundant --enable-experiment=record-use flag (flutter/flutter#190591)
2026-08-05 chris@bracken.jp Windows: Propagate enabled accessibility state (flutter/flutter#190507)
2026-08-05 engine-flutter-autoroll@skia.org Roll Fuchsia Test Scripts from ltbuIH9Z3T_yOuigu... to vcANVO8VIDQHasH1X... (flutter/flutter#190589)
2026-08-05 256906086+mvincentong@users.noreply.github.com Document frozen embedder API structs (flutter/flutter#186842)
2026-08-05 49402500+fahaddoc@users.noreply.github.com Document super call order for State.didChangeDependencies (flutter/flutter#185945)
2026-08-05 dkwingsmt@users.noreply.github.com Move examples of `flutter/widgets` widgets out from `flutter/material` (flutter/flutter#189532)
2026-08-05 93888664+ColeSpringer@users.noreply.github.com [web] Use thread local strike caches in skwasm (flutter/flutter#190048)
2026-08-05 43089218+chika3742@users.noreply.github.com doc: fix typo in see also section for PrimaryScrollController.maybeOf (flutter/flutter#190386)
2026-08-05 jason-simmons@users.noreply.github.com Migrate the shell unit tests from legacy Dart native functions to FFI (flutter/flutter#190473)
2026-08-05 47866232+chunhtai@users.noreply.github.com render proxy box now defaults baseline calculation to null (flutter/flutter#190269)
2026-08-05 36861262+QuncCccccc@users.noreply.github.com Update Widgets Localizations from Translation Console (flutter/flutter#190503)
2026-08-04 154381524+flutteractionsbot@users.noreply.github.com Revert: fix(tool): remove redundant --enable-experiment=record-use flag (flutter/flutter#190583)
2026-08-04 engine-flutter-autoroll@skia.org Roll Fuchsia Test Scripts from 1frGe_KltAJKkeyPg... to ltbuIH9Z3T_yOuigu... (flutter/flutter#190561)
2026-08-04 chris@bracken.jp iOS,macOS: add tsan and ubsan support for Swift (flutter/flutter#190497)
2026-08-04 34465683+rkishan516@users.noreply.github.com fix: update on_message_ to nullptr after window destroy so that dart gets destroy message  (flutter/flutter#185807)
2026-08-04 bkonyi@google.com [flutter_tools] Gracefully handle locked Windows files during clean (flutter/flutter#190095)
2026-08-04 chris@bracken.jp iOS,macOS: make Logger thread-safe, conform to Sendable (flutter/flutter#190488)
2026-08-04 chris@bracken.jp iOS: Eliminate use of IOSContextNoop in platform view tests (reland) (flutter/flutter#190509)
2026-08-04 kevmoo@users.noreply.github.com fix(tool): remove redundant --enable-experiment=record-use flag (flutter/flutter#190475)
2026-08-04 awolff@google.com android_hardware_smoke_test: Detect blank image failures or EGL initialization warnings and retry (flutter/flutter#190110)
2026-08-04 30870216+gaaclarke@users.noreply.github.com Bumps text gamma on windows to match skia. (flutter/flutter#190477)
2026-08-04 engine-flutter-autoroll@skia.org Roll Skia from 48b58ee222f1 to a8583a0a2c11 (2 revisions) (flutter/flutter#190537)
2026-08-04 kevmoo@users.noreply.github.com [tool][web] Intercept dart2wasm errors & append JS migration footers (flutter/flutter#190476)
2026-08-04 dacoharkes@google.com [record_use] Migrate IconTreeShaker to `package:record_use` (flutter/flutter#190225)
2026-08-04 s4bre.py@gmail.com Handle unexpected exceptions during Azure metadata detection (flutter/flutter#189457)
2026-08-04 15619084+vashworth@users.noreply.github.com Fix merge conflict from flutter/flutter#190369 (flutter/flutter#190544)
2026-08-04 15619084+vashworth@users.noreply.github.com Prepare device support symbols (flutter/flutter#190369)
2026-08-04 engine-flutter-autoroll@skia.org Roll Packages from ac87e65 to 3498b9d (1 revision) (flutter/flutter#190532)
2026-08-04 engine-flutter-autoroll@skia.org Roll Skia from a08d918ebd6a to 48b58ee222f1 (11 revisions) (flutter/flutter#190527)

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
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.

didChangeDependencies docs don't specify where to call super

5 participants