Skip to content

Commit 5600590

Browse files
authored
[go_router] Export inherited_go_router.dart file (#1145)
1 parent cb49412 commit 5600590

File tree

4 files changed

+40
-2
lines changed

4 files changed

+40
-2
lines changed

packages/go_router/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 3.0.6
2+
3+
- Exports inherited_go_router.dart file.
4+
15
## 3.0.5
26

37
- Add `dispatchNotification` method to `DummyBuildContext` in tests. (This

packages/go_router/lib/go_router.dart

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export 'src/go_route.dart';
1515
export 'src/go_router.dart';
1616
export 'src/go_router_refresh_stream.dart';
1717
export 'src/go_router_state.dart';
18+
export 'src/inherited_go_router.dart';
1819
export 'src/typedefs.dart' show GoRouterPageBuilder, GoRouterRedirect;
1920
export 'src/url_path_strategy.dart';
2021

packages/go_router/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: go_router
22
description: A declarative router for Flutter based on Navigation 2 supporting
33
deep linking, data-driven routes and more
4-
version: 3.0.5
4+
version: 3.0.6
55
repository: https://github.com/flutter/packages/tree/main/packages/go_router
66
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+go_router%22
77

packages/go_router/test/inherited_go_router_test.dart

+34-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import 'package:flutter/foundation.dart';
66
import 'package:flutter/material.dart';
77
import 'package:flutter_test/flutter_test.dart';
88
import 'package:go_router/go_router.dart';
9-
import 'package:go_router/src/inherited_go_router.dart';
109

1110
void main() {
1211
group('updateShouldNotify', () {
@@ -71,6 +70,15 @@ void main() {
7170
expect(properties.properties.first, isA<DiagnosticsProperty<GoRouter>>());
7271
expect(properties.properties.first.value, goRouter);
7372
});
73+
74+
testWidgets('mediates Widget\'s access to GoRouter.',
75+
(WidgetTester tester) async {
76+
final MockGoRouter router = MockGoRouter();
77+
await tester.pumpWidget(MaterialApp(
78+
home: InheritedGoRouter(goRouter: router, child: const _MyWidget())));
79+
await tester.tap(find.text('My Page'));
80+
expect(router.latestPushedName, 'my_page');
81+
});
7482
}
7583

7684
bool setupInheritedGoRouterChange({
@@ -103,3 +111,28 @@ class Page2 extends StatelessWidget {
103111
@override
104112
Widget build(BuildContext context) => Container();
105113
}
114+
115+
class _MyWidget extends StatelessWidget {
116+
const _MyWidget({Key? key}) : super(key: key);
117+
118+
@override
119+
Widget build(BuildContext context) {
120+
return ElevatedButton(
121+
onPressed: () => context.pushNamed('my_page'),
122+
child: const Text('My Page'));
123+
}
124+
}
125+
126+
class MockGoRouter extends GoRouter {
127+
MockGoRouter() : super(routes: <GoRoute>[]);
128+
129+
late String latestPushedName;
130+
131+
@override
132+
void pushNamed(String name,
133+
{Map<String, String> params = const <String, String>{},
134+
Map<String, String> queryParams = const <String, String>{},
135+
Object? extra}) {
136+
latestPushedName = name;
137+
}
138+
}

0 commit comments

Comments
 (0)