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] Implement popUntil
#2728
Changes from 4 commits
4a809f3
0047433
4196431
701d26d
ab21137
f9e08c2
51395cd
43ec575
97cbf4e
59b89cd
2c48f39
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -166,6 +166,18 @@ class GoRouterDelegate extends RouterDelegate<RouteMatchList> | |
notifyListeners(); | ||
} | ||
|
||
/// Calls [pop] repeatedly until the predicate returns true. | ||
void popUntil(bool Function(RouteMatch) predicate) { | ||
bool hasPopped = false; | ||
while (!predicate(_matchList.last)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. things has changed a bit, its probably the best to call pop directly since it will remove any pageless route that are on top such as dialog. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @chunhtai It's hard to use go router.... Us project previous use more ‘pop with value on pages’, now have the requirement need do the web compatible, but go router no this feature to provide, then use 'Go_Router_Flow' lib, but looks like Pop function have been changed.... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No I mean the implementation of popUntil should use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @chunhtai I am calling pop in ♻️ Call pop repeatedly |
||
hasPopped = true; | ||
_matchList.pop(); | ||
} | ||
if (hasPopped) { | ||
notifyListeners(); | ||
} | ||
} | ||
|
||
/// Replaces the top-most page of the page stack with the given one. | ||
/// | ||
/// See also: | ||
|
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 you can just use
go
to build up to a certain routematch list? If we do refactor the imperative API this will be obsoleteThere 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.
What do you mean?
Are you suggesting that instead of calling
popUntil
(as a dev usinggo_router
), I should callgo
?I don't think it would do the same right?
If I understood correctly,
go
is kind of areplaceAll
, after usinggo
, there is no page to pop andcanPop
isfalse
.While
popUntil
will allow you to only pop some pages but not all. The use case is when the user finishes a wizard to set up something, you want to remove all the wizard's pages from the history but still keep the history the user accumulated before starting the wizard.go
wouldn't work in this scenario, right?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.
no I meant it seems like the
go
can replacepopUntil
. Since developer creates their own route table, they will be able to usego
to achieve functional equivalence ofpopUntil
. For example if they have route table like thislets say route match list is
[GoRouteA, GoRouteB, GoRouteC]
.popUntil((route) => route == GoRouteB)
will be the same asgo(GoRouteB)
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 this comes back to flutter/flutter#99112 's discussion.
Here you are assuming that the match list is
[GoRouteA, GoRouteB, GoRouteC]
and matches perfectly the structureAnd
pop
fromGoRouteC
always goes "back" toGoRouteB
.But as I described in flutter/flutter#99112 (comment), this is not what users are usually expecting. They don't always access
GoRouteC
fromGoRouteB
. So always "going back" toGoRouteB
fromGoRouteC
doesn't work.The way I understand it is that you are trying to merge/combine "app location" and "history"? But that's 2 different things that should be independent.
Am I missing something?
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.
no, you are right, the previous comment is under the assuming that the match list matches the structure. I am assuming
history
means the internal route stack, not the browser history. In that case, my proposal user can still modify the history through imperative API, it just that they won't be able to change app location with imperative API. Let's continue the discussion in the issue.