Skip to content

Commit

Permalink
[go_router] Export inherited_go_router.dart file (#1145)
Browse files Browse the repository at this point in the history
  • Loading branch information
rizumita authored Mar 25, 2022
1 parent cb49412 commit 5600590
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
4 changes: 4 additions & 0 deletions packages/go_router/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 3.0.6

- Exports inherited_go_router.dart file.

## 3.0.5

- Add `dispatchNotification` method to `DummyBuildContext` in tests. (This
Expand Down
1 change: 1 addition & 0 deletions packages/go_router/lib/go_router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export 'src/go_route.dart';
export 'src/go_router.dart';
export 'src/go_router_refresh_stream.dart';
export 'src/go_router_state.dart';
export 'src/inherited_go_router.dart';
export 'src/typedefs.dart' show GoRouterPageBuilder, GoRouterRedirect;
export 'src/url_path_strategy.dart';

Expand Down
2 changes: 1 addition & 1 deletion packages/go_router/pubspec.yaml
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: 3.0.5
version: 3.0.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

Expand Down
35 changes: 34 additions & 1 deletion packages/go_router/test/inherited_go_router_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:go_router/go_router.dart';
import 'package:go_router/src/inherited_go_router.dart';

void main() {
group('updateShouldNotify', () {
Expand Down Expand Up @@ -71,6 +70,15 @@ void main() {
expect(properties.properties.first, isA<DiagnosticsProperty<GoRouter>>());
expect(properties.properties.first.value, goRouter);
});

testWidgets('mediates Widget\'s access to GoRouter.',
(WidgetTester tester) async {
final MockGoRouter router = MockGoRouter();
await tester.pumpWidget(MaterialApp(
home: InheritedGoRouter(goRouter: router, child: const _MyWidget())));
await tester.tap(find.text('My Page'));
expect(router.latestPushedName, 'my_page');
});
}

bool setupInheritedGoRouterChange({
Expand Down Expand Up @@ -103,3 +111,28 @@ class Page2 extends StatelessWidget {
@override
Widget build(BuildContext context) => Container();
}

class _MyWidget extends StatelessWidget {
const _MyWidget({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
return ElevatedButton(
onPressed: () => context.pushNamed('my_page'),
child: const Text('My Page'));
}
}

class MockGoRouter extends GoRouter {
MockGoRouter() : super(routes: <GoRoute>[]);

late String latestPushedName;

@override
void pushNamed(String name,
{Map<String, String> params = const <String, String>{},
Map<String, String> queryParams = const <String, String>{},
Object? extra}) {
latestPushedName = name;
}
}

0 comments on commit 5600590

Please sign in to comment.