-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[go_router] Add topRoute to GoRouterState
#5736
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[go_router] Add topRoute to GoRouterState
#5736
Conversation
chunhtai
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the code LGTM, would be good to add an example in the example/ to showcase how to use this new property as well
| /// ``` | ||
| final ValueKey<String> pageKey; | ||
|
|
||
| /// The current matched top route |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs more description. May be mention what this mean if you this is a this GoRouteState represent a shellroute.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated the documentation with the following, is this what you were thinking of?
/// The current matched top route associated with this state.
///
/// If this state represents a [ShellRoute], the top [GoRoute] will be the current
/// matched location associated with the [ShellRoute]. This allows the [ShellRoute]'s
/// associated GoRouterState to be uniquely identified using [GoRoute.name]
final GoRoute? topRoute;| Widget _buildLeadingButton(BuildContext context) { | ||
| final RouteMatchList currentConfiguration = | ||
| GoRouter.of(context).routerDelegate.currentConfiguration; | ||
| final RouteMatch lastMatch = currentConfiguration.last; | ||
| final Uri location = lastMatch is ImperativeRouteMatch | ||
| ? lastMatch.matches.uri | ||
| : currentConfiguration.uri; | ||
| final bool canPop = location.pathSegments.length > 1; | ||
| final Widget button = canPop | ||
| ? BackButton(onPressed: GoRouter.of(context).pop) | ||
| : const SizedBox.shrink(key: ValueKey<String>('NoLeadingButton')); | ||
| return button; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the example, I had to manually create the leading button since this is in a scaffold above the children. Is there a better way of doing this? For context, auto_route has AutoLeadingButton
hannah-hyj
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
@johnpryan hi john, chun-heng is on vacation, can you take a second look at this PR? |
|
Yep I can review. |
johnpryan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great!
Removed to keep the example simple and make it more readable.
Return null from `_buildLeadingButton` if it shouldn't show a leading button
johnpryan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, we should also add this API to go_router_builder if we haven't already.
|
I don't use go_router_builder so i haven't checked. Should that be done in a separate PR? |
|
yes, go_router_builder changes are usually done in separated PRs. @johnpryan i don't think we need to change go_router_builder to add this |
|
Are we waiting for @chunhtai to return before merging this? |
|
Thanks! |
flutter/packages@cbe8100...516648a 2024-01-28 19920697+getBoolean@users.noreply.github.com [go_router] Add `topRoute` to `GoRouterState` (flutter/packages#5736) 2024-01-27 stuartmorgan@google.com Add Kotlin to CONTRIBUTING.md (flutter/packages#5970) 2024-01-26 engine-flutter-autoroll@skia.org Roll Flutter (stable) from 67457e6 to 4145645 (1 revision) (flutter/packages#5979) 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-flutter-autoroll Please CC flutter-ecosystem@google.com,rmistry@google.com on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: 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
This PR exposes the current top route to
GoRouterState, this allowsShellRouteto know what is the current child and process the state accordingly.This could be used like this, given that each
GoRoutehad thenameparameter givenIf you had to change anything in the flutter/tests repo, include a link to the migration guide as per the breaking change policy.
Pre-launch Checklist
dart format.)[shared_preferences]pubspec.yamlwith an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.CHANGELOG.mdto add a description of the change, following repository CHANGELOG style.///).If you need help, consider asking for advice on the #hackers-new channel on Discord.