Skip to content

[go_router] Add route metadata support to GoRouterState.#11773

Open
star4277 wants to merge 3 commits into
flutter:mainfrom
star4277:main
Open

[go_router] Add route metadata support to GoRouterState.#11773
star4277 wants to merge 3 commits into
flutter:mainfrom
star4277:main

Conversation

@star4277
Copy link
Copy Markdown

@star4277 star4277 commented May 25, 2026

This PR adds route metadata support across go_router route definitions, match resolution, and GoRouterState, including inheritance/override behavior and test coverage.

  • Added metadata support to RouteBase and all relevant route types.
  • Propagated merged route metadata into GoRouterState.
  • Added metadata resolution/merge logic in route matching:
  • inherit from parents
  • child keys override parent keys
  • default to empty map when absent
  • Wired top-level/error state builders to include metadata.
  • Added regression test coverage for metadata inheritance/override/empty behavior.

Fixes flutter/flutter#187049, flutter/flutter#160738.

Pre-Review Checklist

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

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.

Footnotes

  1. Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. 2

@google-cla
Copy link
Copy Markdown

google-cla Bot commented May 25, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@github-actions github-actions Bot added p: go_router triage-framework Should be looked at in framework triage labels May 25, 2026
Copy link
Copy Markdown

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

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 introduces a metadata property to RouteBase and GoRouterState, enabling the association of custom data with routes. The implementation includes logic within RouteMatchList to handle metadata inheritance and overriding during route matching. GoRouterState is updated to incorporate this metadata into its equality and hashing logic, and new tests verify the expected behavior. I have no feedback to provide.

@stuartmorgan-g stuartmorgan-g requested a review from chunhtai May 26, 2026 18:25
@stuartmorgan-g
Copy link
Copy Markdown
Collaborator

[x] I followed the version and CHANGELOG instructions, using semantic versioning and the repository CHANGELOG style, or I have commented below to indicate which documented exception this PR falls under1.

@star4277 I don't see this reflected in the PR. Are there changes you forgot to push?

@star4277
Copy link
Copy Markdown
Author

[x] I followed the version and CHANGELOG instructions, using semantic versioning and the repository CHANGELOG style, or I have commented below to indicate which documented exception this PR falls under1.

@star4277 I don't see this reflected in the PR. Are there changes you forgot to push?

Sorry, I missed it, I've made it up now

Comment thread packages/go_router/lib/src/route.dart Outdated
/// Navigator instead of the nearest ShellRoute ancestor.
final GlobalKey<NavigatorState>? parentNavigatorKey;

/// Metadata associated with the current route.
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.

The doc should say what this is for and in what case would someone use this

Comment thread packages/go_router/lib/src/match.dart Outdated
/// Metadata is inherited from parent routes and overridden by child routes.
/// Returns an empty map when no metadata can be found.
@meta.internal
Map<String, dynamic> routeMetadataFor(RouteMatchBase target) {
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.

this should be previate.

Comment thread packages/go_router/lib/src/state.dart Outdated

/// Metadata associated with the current route.
///
/// Metadata is inherited from parent routes and overridden by child routes.
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.

maybe give some a bit more example on how they will inherited and override

Comment thread packages/go_router/lib/src/state.dart Outdated
/// Metadata associated with the current route.
///
/// Metadata is inherited from parent routes and overridden by child routes.
/// This map is never null.
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.

this comment is not needed as it is obvious based on the type

expect(find.text('B'), findsOneWidget);
});

testWidgets('metadata inherits, overrides, and defaults to empty map', (
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.

also need a test for imperative push

Comment thread packages/go_router/CHANGELOG.md Outdated
@@ -1,3 +1,7 @@
## 17.2.4
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.

for go_router, you need to add an entry in pending_changes folder.

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.

also this is a new feature, we should bump minor version

@chunhtai
Copy link
Copy Markdown
Contributor

can you also add an example in the example/ folder to show case this api?

@star4277
Copy link
Copy Markdown
Author

can you also add an example in the example/ folder to show case this api?

Okay, I will take the time to correct the problem you mentioned, and then update the minor version number you mentioned, is it changed to 17.3?

@star4277
Copy link
Copy Markdown
Author

star4277 commented May 29, 2026

can you also add an example in the example/ folder to show case this api?

I have finished the modification. I don’t know if the minor version number upgrade you mentioned is written as 17.3.0. If not, could you please tell me what version I need to change to?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

p: go_router triage-framework Should be looked at in framework triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[go_router] Support route metadata inheritance and exposure via GoRouterState

3 participants