-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[go_router] Fixes crashes when popping navigators manually #2952
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 all commits
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 |
|---|---|---|
|
|
@@ -953,6 +953,41 @@ void main() { | |
| ]); | ||
| }); | ||
|
|
||
| testWidgets('on pop twice', (WidgetTester tester) async { | ||
| final List<GoRoute> routes = <GoRoute>[ | ||
| GoRoute( | ||
| path: '/', | ||
| builder: (_, __) => const DummyScreen(), | ||
| routes: <RouteBase>[ | ||
| GoRoute( | ||
| path: 'settings', | ||
| builder: (_, __) => const DummyScreen(), | ||
| routes: <RouteBase>[ | ||
| GoRoute( | ||
| path: 'profile', | ||
| builder: (_, __) => const DummyScreen(), | ||
| ), | ||
| ]), | ||
| ]), | ||
| ]; | ||
|
|
||
| final GoRouter router = await createRouter(routes, tester, | ||
| initialLocation: '/settings/profile'); | ||
|
|
||
| log.clear(); | ||
| router.pop(); | ||
| router.pop(); | ||
| await tester.pumpAndSettle(); | ||
| expect(log, <Object>[ | ||
| isMethodCall('selectMultiEntryHistory', arguments: null), | ||
| isMethodCall('routeInformationUpdated', arguments: <String, dynamic>{ | ||
| 'location': '/', | ||
| 'state': null, | ||
| 'replace': false | ||
| }), | ||
| ]); | ||
| }); | ||
|
|
||
| testWidgets('on pop with path parameters', (WidgetTester tester) async { | ||
| final List<GoRoute> routes = <GoRoute>[ | ||
| GoRoute( | ||
|
|
@@ -1012,6 +1047,80 @@ void main() { | |
| ]); | ||
| }); | ||
|
|
||
| testWidgets('Can manually pop root navigator and display correct url', | ||
|
||
| (WidgetTester tester) async { | ||
| final GlobalKey<NavigatorState> rootNavigatorKey = | ||
| GlobalKey<NavigatorState>(); | ||
|
|
||
| final List<RouteBase> routes = <RouteBase>[ | ||
| GoRoute( | ||
| path: '/', | ||
| builder: (BuildContext context, GoRouterState state) { | ||
| return const Scaffold( | ||
| body: Text('Home'), | ||
| ); | ||
| }, | ||
| routes: <RouteBase>[ | ||
| ShellRoute( | ||
| builder: | ||
| (BuildContext context, GoRouterState state, Widget child) { | ||
| return Scaffold( | ||
| appBar: AppBar(), | ||
| body: child, | ||
| ); | ||
| }, | ||
| routes: <RouteBase>[ | ||
| GoRoute( | ||
| path: 'b', | ||
| builder: (BuildContext context, GoRouterState state) { | ||
| return const Scaffold( | ||
| body: Text('Screen B'), | ||
| ); | ||
| }, | ||
| routes: <RouteBase>[ | ||
| GoRoute( | ||
| path: 'c', | ||
| builder: (BuildContext context, GoRouterState state) { | ||
| return const Scaffold( | ||
| body: Text('Screen C'), | ||
| ); | ||
| }, | ||
| ), | ||
| ], | ||
| ), | ||
| ], | ||
| ), | ||
| ], | ||
| ), | ||
| ]; | ||
|
|
||
| await createRouter(routes, tester, | ||
| initialLocation: '/b/c', navigatorKey: rootNavigatorKey); | ||
| expect(find.text('Screen C'), findsOneWidget); | ||
| expect(log, <Object>[ | ||
| isMethodCall('selectMultiEntryHistory', arguments: null), | ||
| isMethodCall('routeInformationUpdated', arguments: <String, dynamic>{ | ||
| 'location': '/b/c', | ||
| 'state': null, | ||
| 'replace': false | ||
| }), | ||
| ]); | ||
|
|
||
| log.clear(); | ||
| rootNavigatorKey.currentState!.pop(); | ||
| await tester.pumpAndSettle(); | ||
|
|
||
| expect(find.text('Home'), findsOneWidget); | ||
| expect(log, <Object>[ | ||
| isMethodCall('selectMultiEntryHistory', arguments: null), | ||
| isMethodCall('routeInformationUpdated', arguments: <String, dynamic>{ | ||
| 'location': '/', | ||
| 'state': null, | ||
| 'replace': false | ||
| }), | ||
| ]); | ||
| }); | ||
|
|
||
| testWidgets('works correctly with async redirect', | ||
| (WidgetTester tester) async { | ||
| final UniqueKey login = UniqueKey(); | ||
|
|
||
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.
We missed this when we refactor the pop. PopNavigatorRouterDelegateMixin is no longer needed since we override poproute directly