-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[go_router] Adds void replace() and replaceNamed to GoRouterDelegate, GoRouter and GoRouterHelper
#2306
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] Adds void replace() and replaceNamed to GoRouterDelegate, GoRouter and GoRouterHelper
#2306
Changes from 3 commits
1258fb7
1db90bd
2760560
33f7424
a9019f9
8ec9776
44e35ef
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -70,6 +70,26 @@ extension GoRouterHelper on BuildContext { | |||||
| extra: extra, | ||||||
| ); | ||||||
|
|
||||||
| /// Replaces the current location with the given one w/ optional query | ||||||
|
Contributor
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.
Suggested change
|
||||||
| /// parameters, e.g. `/family/f2/person/p1?color=blue | ||||||
|
Contributor
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. maybe also mention go/push use |
||||||
| void replace(String location, {Object? extra}) => | ||||||
| GoRouter.of(this).replace(location, extra: extra); | ||||||
|
|
||||||
| /// Replaces the current location with the named route w/ optional parameters, | ||||||
|
Contributor
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.
Suggested change
|
||||||
| /// e.g. `name='person', params={'fid': 'f2', 'pid': 'p1'}` | ||||||
|
Contributor
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. also use the |
||||||
| void replaceNamed( | ||||||
| String name, { | ||||||
| Map<String, String> params = const <String, String>{}, | ||||||
| Map<String, String> queryParams = const <String, String>{}, | ||||||
| Object? extra, | ||||||
| }) => | ||||||
| GoRouter.of(this).replaceNamed( | ||||||
| name, | ||||||
| params: params, | ||||||
| queryParams: queryParams, | ||||||
| extra: extra, | ||||||
| ); | ||||||
|
|
||||||
| /// Returns `true` if there is more than 1 page on the stack. | ||||||
| bool canPop() => GoRouter.of(this).canPop(); | ||||||
|
|
||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -78,6 +78,52 @@ void main() { | |
| ); | ||
| }); | ||
|
|
||
| group('replace', () { | ||
|
Contributor
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. consider adding a test for
Contributor
Author
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. I added a test for |
||
| testWidgets( | ||
| 'It should replace the last match with the given one', | ||
| (WidgetTester tester) async { | ||
| final GoRouter goRouter = GoRouter( | ||
| initialLocation: '/', | ||
| routes: <GoRoute>[ | ||
| GoRoute(path: '/', builder: (_, __) => const SizedBox()), | ||
| GoRoute(path: '/page-0', builder: (_, __) => const SizedBox()), | ||
| GoRoute(path: '/page-1', builder: (_, __) => const SizedBox()), | ||
| ], | ||
| ); | ||
| await tester.pumpWidget( | ||
| MaterialApp.router( | ||
| routeInformationProvider: goRouter.routeInformationProvider, | ||
| routeInformationParser: goRouter.routeInformationParser, | ||
| routerDelegate: goRouter.routerDelegate, | ||
| ), | ||
| ); | ||
|
|
||
| goRouter.push('/page-0'); | ||
|
|
||
| goRouter.routerDelegate.addListener(expectAsync0(() {})); | ||
| final GoRouteMatch first = goRouter.routerDelegate.matches.first; | ||
| final GoRouteMatch last = goRouter.routerDelegate.matches.last; | ||
| goRouter.replace('/page-1'); | ||
| expect(goRouter.routerDelegate.matches.length, 2); | ||
| expect( | ||
| goRouter.routerDelegate.matches.first, | ||
| first, | ||
| reason: 'The first match should still be in the list of matches', | ||
| ); | ||
| expect( | ||
| goRouter.routerDelegate.matches.last, | ||
| isNot(last), | ||
| reason: 'The last match should have been removed', | ||
| ); | ||
| expect( | ||
| goRouter.routerDelegate.matches.last.fullpath, | ||
| '/page-1', | ||
| reason: 'The new location should have been pushed', | ||
| ); | ||
| }, | ||
| ); | ||
| }); | ||
|
|
||
| testWidgets('dispose unsubscribes from refreshListenable', | ||
| (WidgetTester tester) async { | ||
| final FakeRefreshListenable refreshListenable = FakeRefreshListenable(); | ||
|
|
||
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.
nit: add an empty line between two versions
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.
Oops sorry for that, I added that in 8ec9776