Skip to content

Conversation

LukasMirbt
Copy link
Owner

Adds support for TypedRelativeGoRoute.

Builds on flutter#9732

Continuation of flutter#8476 by @ThangVuNguyenViet

Compared to flutter#8476, the approach taken in this PR avoids breaking changes and creates a separate RouteData subclass instead of extending GoRouteData. The approach increases flexibility and avoids extending behavior that might not make sense for a relative route.

Fully resolves flutter/flutter#108177.

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 3

@LukasMirbt LukasMirbt force-pushed the go-router/add-relative-go-route-data branch 3 times, most recently from d59d222 to f778d2e Compare August 4, 2025 19:29
@LukasMirbt LukasMirbt force-pushed the go-router-builder/add-support-for-relative-routes branch from c280a01 to a501098 Compare August 4, 2025 19:31
Copy link

@chunhtai chunhtai left a comment

Choose a reason for hiding this comment

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

Can you also add a readme section for the goRelative route?

@gemini-code-assist Can you add a section to talk about how to use goRelative in the readme.md follow the same format as the existing content in the readme ?

TypedRelativeGoRoute<DetailsRoute>(
path: 'details/:detailId',
routes: <TypedRoute<RouteData>>[
TypedRelativeGoRoute<SettingsRoute>(path: 'settings/:settingId'),
Copy link

Choose a reason for hiding this comment

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

What will happen if this is another TypedGoRoute? or should we assert or force the type of the routes to TypedRelativeGoRoute or TypedShellRoute?

Copy link
Owner Author

Choose a reason for hiding this comment

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

I added a build-time check in RouteBaseConfig._fromAnnotation. Do you agree with that approach?
Do you think it's necessary to add an assert in TypedRelativeGoRoute as well?

// if there are any queryParam objects, add in the `queryParam` bits
String get _locationArgs {
final Map<String, String> pathParameters = Map<String, String>.fromEntries(
_pathParams.map((String pathParameter) {
Copy link

Choose a reason for hiding this comment

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

can you factor this out so we don't duplicate the logic between this and goRoute version?

Copy link
Owner Author

Choose a reason for hiding this comment

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

Done! 👍

return "'$location'";
}

ParameterElement? get _extraParam => _ctor.parameters
Copy link

Choose a reason for hiding this comment

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

same for these getter, or consider using mixin

Copy link
Owner Author

Choose a reason for hiding this comment

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

Done! 👍

@chunhtai
Copy link

chunhtai commented Aug 4, 2025

oh looks like this is a pr in fork. Once you are ready, can you open a pr against main repo? we usually review both go_router and go_router_builder pr together, and only start merging once both are approved

@LukasMirbt LukasMirbt force-pushed the go-router/add-relative-go-route-data branch from f778d2e to e8c8f2b Compare August 4, 2025 21:56
@LukasMirbt LukasMirbt force-pushed the go-router-builder/add-support-for-relative-routes branch from a501098 to ba35aa3 Compare August 4, 2025 22:56
@LukasMirbt LukasMirbt force-pushed the go-router-builder/add-support-for-relative-routes branch from b139041 to 11e0b72 Compare August 4, 2025 23:37
@LukasMirbt LukasMirbt closed this Aug 4, 2025
@LukasMirbt
Copy link
Owner Author

Can you also add a readme section for the goRelative route?

@gemini-code-assist Can you add a section to talk about how to use goRelative in the readme.md follow the same format as the existing content in the readme ?

Reopened in flutter/packages (flutter#9749) and added a readme section.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants