-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[go_router] fix context extension for replaceNamed (#3927)
The extension method is not passing all the data to the function, such as pathParams and queryParams, fixes: flutter/flutter#126222
- Loading branch information
1 parent
e84b49c
commit 1dea5f9
Showing
4 changed files
with
65 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:go_router/go_router.dart'; | ||
|
||
void main() { | ||
group('replaceNamed', () { | ||
Future<GoRouter> createGoRouter( | ||
WidgetTester tester, { | ||
Listenable? refreshListenable, | ||
}) async { | ||
final GoRouter router = GoRouter( | ||
initialLocation: '/', | ||
routes: <GoRoute>[ | ||
GoRoute( | ||
path: '/', | ||
name: 'home', | ||
builder: (_, __) => const _MyWidget(), | ||
), | ||
GoRoute( | ||
path: '/page-0/:tab', | ||
name: 'page-0', | ||
builder: (_, __) => const SizedBox()) | ||
], | ||
); | ||
await tester.pumpWidget(MaterialApp.router( | ||
routerConfig: router, | ||
)); | ||
return router; | ||
} | ||
|
||
testWidgets('Passes GoRouter parameters through context call.', | ||
(WidgetTester tester) async { | ||
final GoRouter router = await createGoRouter(tester); | ||
await tester.tap(find.text('Settings')); | ||
await tester.pumpAndSettle(); | ||
expect(router.location, '/page-0/settings?search=notification'); | ||
}); | ||
}); | ||
} | ||
|
||
class _MyWidget extends StatelessWidget { | ||
const _MyWidget(); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return ElevatedButton( | ||
onPressed: () => context.replaceNamed('page-0', | ||
pathParameters: <String, String>{'tab': 'settings'}, | ||
queryParameters: <String, String>{'search': 'notification'}), | ||
child: const Text('Settings')); | ||
} | ||
} |