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 ShellRoute #2453
Conversation
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.
Only half way through, will continue review next week
About this example: Example... final GoRouter _router = GoRouter(
navigatorKey: _rootNavigatorKey,
routes: <RouteBase>[
/// Application shell
ShellRoute(
path: '/',
...
routes: <RouteBase>[
...
/// Displayed when the second item in the the bottom navigation bar is selected.
GoRoute(
path: 'b',
...
routes: <RouteBase>[
/// Same as "/a/details", but displayed on the root Navigator.
GoRoute(
path: 'details',
// Display on the root Navigator
navigatorKey: _rootNavigatorKey,
builder: (BuildContext context, GoRouterState state) {
return const DetailsScreen(label: 'B');
},
),
],
),
],
),
],
); Some comments:
|
It's not, it's wrapped in a GoRouter.
The GoRouter's navigatorKey specifies the key for the top-level Navigator. Since 87c16ad renames |
Whoops my bad 🤦 |
runApp(ShellRouteExampleApp()); | ||
} | ||
|
||
/// An example demonstrating how to use [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'm worried that folks will see this example and think you need to define a root navigator key to use ShellRoute
. I wonder if we should have two separate shell route examples:
- The simplest shell route example possible
- This more advanced shell route example that shows you how to "break out" of the shell route and display on top of the root navigator.
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.
SGTM - I'll break it out into two samples
Hello, I am experimenting and trying to implement tabs with ShellRoute, but I was wondering if it is (or will be) possible to persist the navigation stack in the selected tab? e.g. when navigating from /a to /a/details then to /b and going back to /a would open /a/details page. I would like to implement similar navigation as the Youtube app has. |
@johnpryan
|
@sigis151 this won't be included in this initial version of ShellRoute, but you can follow this feature here: flutter/flutter#99124 |
@miaosun009 thanks for bringing that up and providing a snippet - as this is currently built, ShellRoutes can be pushed and popped like normal GoRoutes, but we might need to figure out what canPop should do in this situation. For example, what if I'm building an app that needs to push a ShellRoute with a tab bar? Should canPop return false in that case? |
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 didn't look at the test yet
@johnpryan Maybe it's not a ShellRoute problem, but to achieve what I want, what do I need to do |
@miaosun009 after talking about this PR with @chunhtai some more I think we are going to remove the Edit: We are removing the |
- fix CHANGELOG - remove TODO - Use a Map to make navigator key algorithm O(n) - rename navigatorKey and shellNavigatorKey to parentNavigatorKey and navigatorKey - Make navigator key optional in build phase
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.
everything else looks good
2f4bc7d
to
c9f670b
Compare
This will fail but it should pass
|
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 is this still true in the final merged version? When pushing a GoRoute that is inside a ShellRoute, the builder function is not executed. However when using |
@flodaniel no, ShellRoutes can't be pushed and popped. Do you have a snippet that shows the issue you are seeing? Feel free to file an issue and cc me. |
Oh. I am not sure that this justifies as an issue right now. I am posting this here but can open an issue if you think it makes sense. Current solution:
This is how it works when i go to the first child route of the ShellRoute, but not if I push it.
The solution with using the ShellRoute is shorter, cleaner and allows to clearly scope dependencies to a number of (sub)-pages. I am migrating our project from flow_builder to go_router and the major downside is that we have to move all our dependencies injections further up the widget tree without an easy solution to scope them to a number of sub-pages, which we really hoped we could do with ShellRoutes :) |
@flodaniel I think we need to ensure that the BuildContext is correct for all builders, this will be addressed with relative routing I think. |
Thanks a lot @johnpryan. I will follow this ticket and hope for a swift merge. You rock! |
This adds ShellRoute, a new route type that builds an inner Navigator
resolves flutter/flutter#108141
resolves flutter/flutter#99126
resolves flutter/flutter#109479