-
Notifications
You must be signed in to change notification settings - Fork 3k
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] Improvement of StatefulShellRoute API - deprecating goBranch #7622
base: main
Are you sure you want to change the base?
Conversation
…emoving the need of using goBranch.
@chunhtai, would appreciate if you could have a look at this and see what you think, before I contuine fully implementing/documenting/testing this. The current implementation works (at least as first attempt) and the |
It feels a bit weird that we force the statefulbranch to use numeric path, is there a reason behind this change? |
Well, a numeric index is what we're using already, via the programmatic API. So there really is no change in what information you use to switch branch. But I was actually thinking about re-introducing the concept of giving each branch a name (which did exist at some point in the original StatefulShellRoute PR), and now that I think of it, this may certainly make the navigation feel less weird. I'll go ahead and add that change. |
…named branch redirects (i.e. instead of index).
I am more concern about url will be force to use numeric path like Another concern is that we should figure out when two url may point to same page. for example if /mypath/subpath also switch branch to 0, then both /mypath/subpath and /mypath/0 points to same page. In this case should the url for /mypath/0 redirect to /mypath/subpath? we need to update the reportRouteToEngine code to make sure we update the history correctly. |
Updated the description with more information about using names instead of indices. This change uses the standard redirect handling, so I would assume circular redirects etc would be handled already (i.e. redirect limits and supporting reporting back to the engine)? |
…fulNavigationShell. Introduced the GoRouterState subclass ShellRouteState, as replacement for ShellRouteContext and StatefulNavigationShell in public APIs.
Ok, so I took it one step further, to more thoroughly adress the issues of flutter/flutter#128262. It may be too much to do in a single step / PR, but I mainly did it to showcase a potential refactoring of the API around StatefulShellRoute, to improve the DX and make the API more in line with the rest of go router (i.e. path based). Would be great if you could take a deeper look at this @chunhtai. (Edit: updated the original PR description/comment with information about these changes). |
@tolo I'm not sure I understand the point of this PR. This is a response to your comment on the other PR where you link this one. Maybe it's to make routing work nicely with the usual navigation widgets which work with indexes currently, in which case, what's wrong with:
|
Basically, the initial intent of this PR was to add support for a path-based way of navigating to the current state of a stateful shell route or a branch thereof, which is not possible today. The more I worked on this PR though, other related opportunities for improvements also presented themselves. I would now summarise the motivations of this PR like this (will add it to the description):
|
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.
instead of using index, have you thought about using name instead? i.e a new name parameter to StatefulShellRouteBranch. and then you can use reuse goName API
Removed deprecation.
Good suggestion. |
Added some generalization and simplification around both the path based redirects and the API in general. Will update the PR description to reflect these changes after the weekend. |
…ils. Introduced method resetNavigatorLocation in ShellRouteState.
Decided to narrow the focus of this PR to mainly adress the goBranch API as well as introducing improvements around the ShellRoute/StatefulShellRoute API in general. Will update name and description shortly. |
More cleanup.
@chunhtai / @hannah-hyj, when you have a minute, I'd appreciate you're thoughts around this. |
I will take a look this week |
This PR introduces refactoring around the API of
StatefulShellRoute
andShellRouteBase
, to make routing with StatefulShellRoute less of a special case. The primary reason of this PR is to move away from the use of thegoBranch
method and also the need to expose the classStatefulNavigationShell
.To summarise, the basic motivations of this PR are:
ShellRouteBase
.The main changes in this PR are:
GoRouteState
subclass:ShellRouteState
. This class takes over the responsibility from StatefulNavigationShell when it comes to getting the active navigation state (i.e. branch index and branch locations).Basically, instead of using
goBranch
, you now do this:See the stateful_shell_route.dart example for a runnable demo of this change.
This PR addresses:
Pre-launch Checklist
dart format
.)[shared_preferences]
pubspec.yaml
with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.CHANGELOG.md
to add a description of the change, following repository CHANGELOG style, or this PR is exempt from CHANGELOG changes.///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.