-
Notifications
You must be signed in to change notification settings - Fork 3.4k
[go_router] Make replace
use pop
and push
to generate a new pageKey
#2747
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
Changes from 5 commits
4f0c5ee
9053078
9b20b5c
934f28e
a50d124
5a039d9
8e8d187
0568cef
30ac6cc
1ab67da
053d4fb
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 |
---|---|---|
|
@@ -45,6 +45,18 @@ class GoRouterDelegate extends RouterDelegate<RouteMatchList> | |
final bool routerNeglect; | ||
|
||
RouteMatchList _matchList = RouteMatchList.empty(); | ||
|
||
/// Stores the number of time each route route has been pushed. | ||
/// | ||
/// This is used to generate a unique key for each route. | ||
/// | ||
/// For example, it would could be equal to: | ||
/// ```dart | ||
/// { | ||
/// 'family': 1, | ||
/// 'family/:fid': 2, | ||
/// } | ||
/// ``` | ||
final Map<String, int> _pushCounts = <String, int>{}; | ||
final RouteConfiguration _configuration; | ||
|
||
|
@@ -136,9 +148,18 @@ class GoRouterDelegate extends RouterDelegate<RouteMatchList> | |
return navigatorKey.currentState?.canPop() ?? false; | ||
} | ||
|
||
void _debugAssertMatchListNotEmpty() { | ||
assert( | ||
_matchList.isNotEmpty, | ||
'You have popped the last page off of the stack,' | ||
' there are no pages left to show', | ||
); | ||
} | ||
|
||
/// Pop the top page off the GoRouter's page stack. | ||
void pop() { | ||
_matchList.pop(); | ||
_debugAssertMatchListNotEmpty(); | ||
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. you can also wrap this in an assert so that release mode will not even waste time calling into an empty function 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. Is 8e8d187 what you mean? 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. yes |
||
notifyListeners(); | ||
} | ||
|
||
|
@@ -147,8 +168,8 @@ class GoRouterDelegate extends RouterDelegate<RouteMatchList> | |
/// See also: | ||
/// * [push] which pushes the given location onto the page stack. | ||
void replace(RouteMatch match) { | ||
_matchList.matches.last = match; | ||
notifyListeners(); | ||
_matchList.pop(); | ||
push(match); // [push] will notify the listeners. | ||
} | ||
|
||
/// For internal use; visible for testing only. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
name: go_router | ||
description: A declarative router for Flutter based on Navigation 2 supporting | ||
deep linking, data-driven routes and more | ||
version: 5.1.3 | ||
version: 5.1.4 | ||
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. 5.1.3? 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. With the newly merged PRs, I'll make it 5.1.6 |
||
repository: https://github.com/flutter/packages/tree/main/packages/go_router | ||
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+go_router%22 | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.