Skip to content

[go_router] Add ShellRoute - #2362

Closed
johnpryan wants to merge 23 commits into
flutter:mainfrom
johnpryan:add-new-route-types
Closed

[go_router] Add ShellRoute#2362
johnpryan wants to merge 23 commits into
flutter:mainfrom
johnpryan:add-new-route-types

Conversation

@johnpryan

@johnpryanjohnpryan commented Jul 22, 2022

Copy link
Copy Markdown
Contributor

Adds ShellRoute

Resolvesflutter/flutter#108141

@johnpryan
johnpryan requested a review from chunhtaiJuly 22, 2022 19:43
@johnpryanjohnpryan changed the title Add new route types[go_router] Add new route typesJul 22, 2022
@johnpryan
johnpryan marked this pull request as ready for review July 22, 2022 21:19

@prince-kumarprince-kumar left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM

Comment threadpackages/go_router/lib/src/route.dart Outdated
Comment threadpackages/go_router/lib/src/route.dart Outdated
Comment threadpackages/go_router/lib/src/route.dart Outdated
Comment threadpackages/go_router/lib/src/route.dart Outdated
Comment threadpackages/go_router/lib/src/route.dart Outdated
Comment threadpackages/go_router/lib/src/route.dart Outdated
Comment threadpackages/go_router/lib/src/route.dart Outdated
Comment threadpackages/go_router/lib/src/route.dart Outdated
Comment threadpackages/go_router/lib/src/route.dart Outdated
Comment threadpackages/go_router/test/go_router_test.dart Outdated
@johnpryanjohnpryan changed the title [go_router] Add new route types[go_router] Add new route types and builder for ShellRouteAug 1, 2022
@johnpryan

johnpryan commented Aug 1, 2022

Copy link
Copy Markdown
ContributorAuthor

@loic-sharma@chunhtai ready for another look - I added some functionality to ShellRoute with some tests, but right now this is still a "dark" feature and not part of the public API exposed by lib/go_router.dart.

@johnpryan

Copy link
Copy Markdown
ContributorAuthor

After discussing this offline, I want to make some changes to this PR:

  • Remove NestedStackRoute
  • Remove StackedRoute and stick with GoRoute
  • ShellRoute now always builds a Router and Navigator. This means that sub-routes will stack on this Navigator by default, rather than requiring a NestedNavigatorRoute. We will use an additional Router to ensure that we are handling back button behavior correctly. This cannot be made optional because pageBuilder would break for child routes of ShellRoute.
  • Add a navigatorKey parameter to the GoRoute constructor. This specifies which Navigator to place this GoRoute onto. By default, GoRoutes stack onto the Navigator built by the nearest ShellRoute ancestor.
  • Add a shellNavigatorKey parameter to the ShellRoute constructor. This specifies the navigator key to use when building the Navigator associated with this ShellRoute.
  • Add a navigatorKey parameter to the ShellRoute constructor, which has the same behavior as navigatorKey on GoRoute.

@johnpryanjohnpryan changed the title [go_router] Add new route types and builder for ShellRoute[go_router] Add ShellRouteAug 10, 2022
@chunhtai
chunhtai self-requested a review August 10, 2022 17:30
Comment threadpackages/go_router/CHANGELOG.md Outdated
Comment threadpackages/go_router/CHANGELOG.md Outdated
@loic-sharma

Copy link
Copy Markdown
Member

Should this PR target the go_router_v5 branch now?

Comment threadpackages/go_router/lib/src/typedefs.dart Outdated
@johnpryan

Copy link
Copy Markdown
ContributorAuthor

Should this PR target the go_router_v5 branch now?

This isn't a breaking change, but maybe we should if we want to avoid merge conflicts. @chunhtai WDYT?

@cedvdb

cedvdb commented Aug 11, 2022

Copy link
Copy Markdown
Contributor

I assume this pr deals with nested routers.

One annoying thing with nested routers in practice are all the overlays like dialogs, bottom sheet, etc.

By default the result will be unexpected for most users: the modal barrier will only appear on the nested route. You have to explicitely call useRoot: true or something like that.

How will those scenarios be handled ?

I said it before when @chunhtai requested feedback: those two concepts of "overlay" and navigation should not have been mixed together in my opinion. Imo a separate overlay handler class is needed, but that might be to big of a change.

@johnpryan

Copy link
Copy Markdown
ContributorAuthor

By default the result will be unexpected for most users: the modal barrier will only appear on the nested route. You have to explicitly call useRoot: true or something like that.
How will those scenarios be handled ?

You can specify which Navigator a route's screen will be overlaid on by specifying a navigatorKey on the GoRouter constructor or a shellNavigatorKey on the ShellRoute if you are using nested navigation. Then you specify the same navigatorKey on the GoRoute.

I said it before when @chunhtai requested feedback: those two concepts of "overlay" and navigation should not have been mixed together in my opinion. Imo a separate overlay handler class is needed, but that might be too big of a change.

Can you describe this scenario a bit more? This PR is a simplified version of go_router_prototype, which supports overlay-based navigation (GoRoute / StackedRoute) and shell-based navigation (ShellRoute). Shell-based navigation is very similar to how routing works for web-application frameworks and isn't based on overlays.

@cedvdb

This comment was marked as off-topic.

@johnpryan

Copy link
Copy Markdown
ContributorAuthor

@cedvdb this is getting off-topic, would you mind filing a separate issue?

@johnpryan
johnpryan deleted the add-new-route-types branch August 12, 2022 21:40
@johnpryan

Copy link
Copy Markdown
ContributorAuthor

New pull request: #2453

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[go_router] Add ShellRoute

6 participants

@johnpryan@loic-sharma@cedvdb@prince-kumar@ValentinVignal@chunhtai