From 38dd934bb35dd131c12121028bfabc854cbd2b97 Mon Sep 17 00:00:00 2001 From: chunhtai <47866232+chunhtai@users.noreply.github.com> Date: Thu, 6 Jul 2023 09:22:33 -0700 Subject: [PATCH] [go_router] Exposes package-level privates (#4380) --- packages/go_router/CHANGELOG.md | 7 ++- packages/go_router/lib/go_router.dart | 38 +++-------- packages/go_router/lib/src/builder.dart | 11 +++- packages/go_router/lib/src/configuration.dart | 10 +-- packages/go_router/lib/src/delegate.dart | 11 +--- packages/go_router/lib/src/match.dart | 3 + packages/go_router/lib/src/parser.dart | 3 +- packages/go_router/lib/src/path_utils.dart | 2 +- packages/go_router/lib/src/route.dart | 48 +++++++++++++- packages/go_router/lib/src/route_data.dart | 15 +++-- packages/go_router/lib/src/router.dart | 4 +- packages/go_router/lib/src/state.dart | 3 + packages/go_router/lib/src/typedefs.dart | 63 ------------------- packages/go_router/pubspec.yaml | 2 +- packages/go_router/test/builder_test.dart | 5 +- .../go_router/test/configuration_test.dart | 3 +- packages/go_router/test/delegate_test.dart | 2 - packages/go_router/test/extension_test.dart | 1 - .../go_router/test/go_router_state_test.dart | 2 +- .../test/information_provider_test.dart | 2 +- packages/go_router/test/match_test.dart | 1 - packages/go_router/test/matching_test.dart | 3 +- packages/go_router/test/parser_test.dart | 4 -- packages/go_router/test/test_helpers.dart | 1 - 24 files changed, 103 insertions(+), 141 deletions(-) delete mode 100644 packages/go_router/lib/src/typedefs.dart diff --git a/packages/go_router/CHANGELOG.md b/packages/go_router/CHANGELOG.md index 0d1f3199f6..6b20ae5cfc 100644 --- a/packages/go_router/CHANGELOG.md +++ b/packages/go_router/CHANGELOG.md @@ -1,3 +1,7 @@ +## 9.0.2 + +- Exposes package-level privates. + ## 9.0.1 - Allows redirect only GoRoute to be part of RouteMatchList. @@ -5,8 +9,7 @@ ## 9.0.0 - **BREAKING CHANGE**: - - Removes GoRouter.location and GoRouter.canPop. Use GoRouterState.of().location and - Navigator.of().canPop instead. + - Removes GoRouter.location. Use GoRouterState.of().location instead. - GoRouter does not `extends` ChangeNotifier. - [Migration guide](https://flutter.dev/go/go-router-v9-breaking-changes) - Reduces excessive rebuilds due to inherited look up. diff --git a/packages/go_router/lib/go_router.dart b/packages/go_router/lib/go_router.dart index 31ed9c865b..d2728a077c 100644 --- a/packages/go_router/lib/go_router.dart +++ b/packages/go_router/lib/go_router.dart @@ -6,35 +6,17 @@ /// deep linking, data-driven routes and more. library go_router; -export 'src/configuration.dart' - show - GoRoute, - GoRouterState, - RouteBase, - ShellRoute, - ShellNavigationContainerBuilder, - StatefulNavigationShell, - StatefulNavigationShellState, - StatefulShellBranch, - StatefulShellRoute; +export 'src/builder.dart'; +export 'src/configuration.dart'; +export 'src/delegate.dart'; +export 'src/information_provider.dart'; +export 'src/match.dart' hide RouteMatchListCodec; +export 'src/misc/errors.dart'; export 'src/misc/extensions.dart'; export 'src/misc/inherited_router.dart'; export 'src/pages/custom_transition_page.dart'; -export 'src/route_data.dart' - show - RouteData, - GoRouteData, - ShellRouteData, - TypedRoute, - TypedGoRoute, - TypedShellRoute; +export 'src/parser.dart'; +export 'src/route.dart'; +export 'src/route_data.dart' hide NoOpPage; export 'src/router.dart'; -export 'src/typedefs.dart' - show - GoRouterPageBuilder, - GoRouterRedirect, - GoRouterWidgetBuilder, - ShellRouteBuilder, - ShellRoutePageBuilder, - StatefulShellRouteBuilder, - StatefulShellRoutePageBuilder; +export 'src/state.dart' hide GoRouterStateRegistry, GoRouterStateRegistryScope; diff --git a/packages/go_router/lib/src/builder.dart b/packages/go_router/lib/src/builder.dart index 774616519f..ccba1150db 100644 --- a/packages/go_router/lib/src/builder.dart +++ b/packages/go_router/lib/src/builder.dart @@ -5,16 +5,23 @@ import 'package:collection/collection.dart'; import 'package:flutter/widgets.dart'; -import '../go_router.dart'; import 'configuration.dart'; import 'logging.dart'; import 'match.dart'; import 'misc/error_screen.dart'; import 'misc/errors.dart'; import 'pages/cupertino.dart'; +import 'pages/custom_transition_page.dart'; import 'pages/material.dart'; +import 'route.dart'; import 'route_data.dart'; -import 'typedefs.dart'; +import 'state.dart'; + +/// Signature of a go router builder function with navigator. +typedef GoRouterBuilderWithNav = Widget Function( + BuildContext context, + Widget child, +); /// Signature for a function that takes in a `route` to be popped with /// the `result` and returns a boolean decision on whether the pop diff --git a/packages/go_router/lib/src/configuration.dart b/packages/go_router/lib/src/configuration.dart index a1969d6579..a0a9b93c4e 100644 --- a/packages/go_router/lib/src/configuration.dart +++ b/packages/go_router/lib/src/configuration.dart @@ -6,14 +6,16 @@ import 'dart:async'; import 'package:flutter/widgets.dart'; -import 'configuration.dart'; import 'logging.dart'; import 'match.dart'; import 'misc/errors.dart'; import 'path_utils.dart'; -import 'typedefs.dart'; -export 'route.dart'; -export 'state.dart'; +import 'route.dart'; +import 'state.dart'; + +/// The signature of the redirect callback. +typedef GoRouterRedirect = FutureOr Function( + BuildContext context, GoRouterState state); /// The route configuration for GoRouter configured by the app. class RouteConfiguration { diff --git a/packages/go_router/lib/src/delegate.dart b/packages/go_router/lib/src/delegate.dart index 1d382db2d9..6265bb67f9 100644 --- a/packages/go_router/lib/src/delegate.dart +++ b/packages/go_router/lib/src/delegate.dart @@ -7,12 +7,11 @@ import 'dart:async'; import 'package:flutter/foundation.dart'; import 'package:flutter/widgets.dart'; -import '../go_router.dart'; import 'builder.dart'; import 'configuration.dart'; import 'match.dart'; import 'misc/errors.dart'; -import 'typedefs.dart'; +import 'route.dart'; /// GoRouter implementation of [RouterDelegate]. class GoRouterDelegate extends RouterDelegate @@ -26,7 +25,6 @@ class GoRouterDelegate extends RouterDelegate required GoRouterWidgetBuilder? errorBuilder, required List observers, required this.routerNeglect, - required this.onException, String? restorationScopeId, }) : _configuration = configuration { builder = RouteBuilder( @@ -47,13 +45,6 @@ class GoRouterDelegate extends RouterDelegate /// Set to true to disable creating history entries on the web. final bool routerNeglect; - /// The exception handler that is called when parser can't handle the incoming - /// uri. - /// - /// If this is null, the exception is handled in the - /// [RouteBuilder.errorPageBuilder] or [RouteBuilder.errorBuilder]. - final GoExceptionHandler? onException; - final RouteConfiguration _configuration; _NavigatorStateIterator _createNavigatorStateIterator() => diff --git a/packages/go_router/lib/src/match.dart b/packages/go_router/lib/src/match.dart index 9106b1cf8a..e0e9898291 100644 --- a/packages/go_router/lib/src/match.dart +++ b/packages/go_router/lib/src/match.dart @@ -8,10 +8,12 @@ import 'dart:convert'; import 'package:collection/collection.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/widgets.dart'; +import 'package:meta/meta.dart'; import 'configuration.dart'; import 'misc/errors.dart'; import 'path_utils.dart'; +import 'route.dart'; /// An matched result by matching a [RouteBase] against a location. /// @@ -355,6 +357,7 @@ class RouteMatchList { /// suitable for using with [StandardMessageCodec]. /// /// The primary use of this class is for state restoration. +@internal class RouteMatchListCodec extends Codec> { /// Creates a new [RouteMatchListCodec] object. RouteMatchListCodec(RouteConfiguration configuration) diff --git a/packages/go_router/lib/src/parser.dart b/packages/go_router/lib/src/parser.dart index 778d099f7d..df4d551a8b 100644 --- a/packages/go_router/lib/src/parser.dart +++ b/packages/go_router/lib/src/parser.dart @@ -8,11 +8,12 @@ import 'dart:math'; import 'package:flutter/foundation.dart'; import 'package:flutter/widgets.dart'; -import '../go_router.dart'; import 'configuration.dart'; import 'information_provider.dart'; import 'logging.dart'; import 'match.dart'; +import 'route.dart'; +import 'router.dart'; /// The function signature of [GoRouteInformationParser.onParserException]. /// diff --git a/packages/go_router/lib/src/path_utils.dart b/packages/go_router/lib/src/path_utils.dart index ba403f4783..42b5f030a4 100644 --- a/packages/go_router/lib/src/path_utils.dart +++ b/packages/go_router/lib/src/path_utils.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import '../go_router.dart'; +import 'route.dart'; final RegExp _parameterRegExp = RegExp(r':(\w+)(\((?:\\.|[^\\()])+\))?'); diff --git a/packages/go_router/lib/src/route.dart b/packages/go_router/lib/src/route.dart index b7ba3affb5..71aef137be 100644 --- a/packages/go_router/lib/src/route.dart +++ b/packages/go_router/lib/src/route.dart @@ -7,11 +7,55 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/widgets.dart'; import 'package:meta/meta.dart'; -import '../go_router.dart'; import 'configuration.dart'; import 'match.dart'; import 'path_utils.dart'; -import 'typedefs.dart'; +import 'router.dart'; +import 'state.dart'; + +/// The page builder for [GoRoute]. +typedef GoRouterPageBuilder = Page Function( + BuildContext context, + GoRouterState state, +); + +/// The widget builder for [GoRoute]. +typedef GoRouterWidgetBuilder = Widget Function( + BuildContext context, + GoRouterState state, +); + +/// The widget builder for [ShellRoute]. +typedef ShellRouteBuilder = Widget Function( + BuildContext context, + GoRouterState state, + Widget child, +); + +/// The page builder for [ShellRoute]. +typedef ShellRoutePageBuilder = Page Function( + BuildContext context, + GoRouterState state, + Widget child, +); + +/// The widget builder for [StatefulShellRoute]. +typedef StatefulShellRouteBuilder = Widget Function( + BuildContext context, + GoRouterState state, + StatefulNavigationShell navigationShell, +); + +/// The page builder for [StatefulShellRoute]. +typedef StatefulShellRoutePageBuilder = Page Function( + BuildContext context, + GoRouterState state, + StatefulNavigationShell navigationShell, +); + +/// Signature for functions used to build Navigators +typedef NavigatorBuilder = Widget Function( + List? observers, String? restorationScopeId); /// The base class for [GoRoute] and [ShellRoute]. /// diff --git a/packages/go_router/lib/src/route_data.dart b/packages/go_router/lib/src/route_data.dart index 23e6740342..c0053a06b6 100644 --- a/packages/go_router/lib/src/route_data.dart +++ b/packages/go_router/lib/src/route_data.dart @@ -11,13 +11,14 @@ import 'package:meta/meta_meta.dart'; import 'route.dart'; import 'state.dart'; -/// A superclass for each route data +/// Baseclass for supporting +/// [Type-safe routing](https://pub.dev/documentation/go_router/latest/topics/Type-safe%20routes-topic.html). abstract class RouteData { - /// Default const constructor + /// Allows subclasses to have `const` constructors. const RouteData(); } -/// Baseclass for supporting +/// A class to represent a [GoRoute] in /// [Type-safe routing](https://pub.dev/documentation/go_router/latest/topics/Type-safe%20routes-topic.html). /// /// Subclasses must override one of [build], [buildPage], or @@ -123,10 +124,12 @@ abstract class GoRouteData extends RouteData { ); } -/// Base class for supporting -/// [nested navigation](https://pub.dev/packages/go_router#nested-navigation) +/// A class to represent a [ShellRoute] in +/// [Type-safe routing](https://pub.dev/documentation/go_router/latest/topics/Type-safe%20routes-topic.html). abstract class ShellRouteData extends RouteData { - /// Default const constructor + /// Allows subclasses to have `const` constructors. + /// + /// [ShellRouteData] is abstract and cannot be instantiated directly. const ShellRouteData(); /// [pageBuilder] is used to build the page diff --git a/packages/go_router/lib/src/router.dart b/packages/go_router/lib/src/router.dart index 26338ceebf..7c061df24a 100644 --- a/packages/go_router/lib/src/router.dart +++ b/packages/go_router/lib/src/router.dart @@ -12,7 +12,8 @@ import 'match.dart'; import 'misc/errors.dart'; import 'misc/inherited_router.dart'; import 'parser.dart'; -import 'typedefs.dart'; +import 'route.dart'; +import 'state.dart'; /// The function signature of [GoRouter.onException]. /// @@ -139,7 +140,6 @@ class GoRouter implements RouterConfig { routerDelegate = GoRouterDelegate( configuration: configuration, - onException: onException, errorPageBuilder: errorPageBuilder, errorBuilder: errorBuilder, routerNeglect: routerNeglect, diff --git a/packages/go_router/lib/src/state.dart b/packages/go_router/lib/src/state.dart index 89400e36d1..8ec5d0754b 100644 --- a/packages/go_router/lib/src/state.dart +++ b/packages/go_router/lib/src/state.dart @@ -3,6 +3,7 @@ // found in the LICENSE file. import 'package:flutter/widgets.dart'; +import 'package:meta/meta.dart'; import 'configuration.dart'; import 'misc/errors.dart'; @@ -181,6 +182,7 @@ class GoRouterState { /// /// Should not be used directly, consider using [GoRouterState.of] to access /// [GoRouterState] from the context. +@internal class GoRouterStateRegistryScope extends InheritedNotifier { /// Creates a GoRouterStateRegistryScope. @@ -195,6 +197,7 @@ class GoRouterStateRegistryScope /// /// Should not be used directly, consider using [GoRouterState.of] to access /// [GoRouterState] from the context. +@internal class GoRouterStateRegistry extends ChangeNotifier { /// creates a [GoRouterStateRegistry]. GoRouterStateRegistry(); diff --git a/packages/go_router/lib/src/typedefs.dart b/packages/go_router/lib/src/typedefs.dart deleted file mode 100644 index 7a4071529f..0000000000 --- a/packages/go_router/lib/src/typedefs.dart +++ /dev/null @@ -1,63 +0,0 @@ -// 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 'dart:async' show FutureOr; - -import 'package:flutter/widgets.dart'; - -import 'configuration.dart'; - -/// The widget builder for [GoRoute]. -typedef GoRouterWidgetBuilder = Widget Function( - BuildContext context, - GoRouterState state, -); - -/// The page builder for [GoRoute]. -typedef GoRouterPageBuilder = Page Function( - BuildContext context, - GoRouterState state, -); - -/// The widget builder for [ShellRoute]. -typedef ShellRouteBuilder = Widget Function( - BuildContext context, - GoRouterState state, - Widget child, -); - -/// The page builder for [ShellRoute]. -typedef ShellRoutePageBuilder = Page Function( - BuildContext context, - GoRouterState state, - Widget child, -); - -/// The widget builder for [StatefulShellRoute]. -typedef StatefulShellRouteBuilder = Widget Function( - BuildContext context, - GoRouterState state, - StatefulNavigationShell navigationShell, -); - -/// The page builder for [StatefulShellRoute]. -typedef StatefulShellRoutePageBuilder = Page Function( - BuildContext context, - GoRouterState state, - StatefulNavigationShell navigationShell, -); - -/// Signature of a go router builder function with navigator. -typedef GoRouterBuilderWithNav = Widget Function( - BuildContext context, - Widget child, -); - -/// The signature of the redirect callback. -typedef GoRouterRedirect = FutureOr Function( - BuildContext context, GoRouterState state); - -/// Signature for functions used to build Navigators -typedef NavigatorBuilder = Widget Function( - List? observers, String? restorationScopeId); diff --git a/packages/go_router/pubspec.yaml b/packages/go_router/pubspec.yaml index 83bebb1764..f6c8fe43a1 100644 --- a/packages/go_router/pubspec.yaml +++ b/packages/go_router/pubspec.yaml @@ -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: 9.0.1 +version: 9.0.2 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 diff --git a/packages/go_router/test/builder_test.dart b/packages/go_router/test/builder_test.dart index 9d426992cb..d3bfb3d6bd 100644 --- a/packages/go_router/test/builder_test.dart +++ b/packages/go_router/test/builder_test.dart @@ -4,10 +4,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'package:go_router/src/builder.dart'; -import 'package:go_router/src/configuration.dart'; -import 'package:go_router/src/match.dart'; -import 'package:go_router/src/router.dart'; +import 'package:go_router/go_router.dart'; import 'test_helpers.dart'; diff --git a/packages/go_router/test/configuration_test.dart b/packages/go_router/test/configuration_test.dart index ac4d1ed848..a5ed6f19b7 100644 --- a/packages/go_router/test/configuration_test.dart +++ b/packages/go_router/test/configuration_test.dart @@ -4,8 +4,7 @@ import 'package:flutter/widgets.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'package:go_router/src/configuration.dart'; -import 'package:go_router/src/misc/errors.dart'; +import 'package:go_router/go_router.dart'; import 'test_helpers.dart'; diff --git a/packages/go_router/test/delegate_test.dart b/packages/go_router/test/delegate_test.dart index 1b1d5e575f..c1ece69a46 100644 --- a/packages/go_router/test/delegate_test.dart +++ b/packages/go_router/test/delegate_test.dart @@ -5,9 +5,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:go_router/go_router.dart'; -import 'package:go_router/src/match.dart'; import 'package:go_router/src/misc/error_screen.dart'; -import 'package:go_router/src/misc/errors.dart'; import 'test_helpers.dart'; diff --git a/packages/go_router/test/extension_test.dart b/packages/go_router/test/extension_test.dart index 48a93a6144..97e5401bad 100644 --- a/packages/go_router/test/extension_test.dart +++ b/packages/go_router/test/extension_test.dart @@ -5,7 +5,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:go_router/go_router.dart'; -import 'package:go_router/src/match.dart'; void main() { group('replaceNamed', () { diff --git a/packages/go_router/test/go_router_state_test.dart b/packages/go_router/test/go_router_state_test.dart index b1d0eb5285..1541260122 100644 --- a/packages/go_router/test/go_router_state_test.dart +++ b/packages/go_router/test/go_router_state_test.dart @@ -5,7 +5,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:go_router/go_router.dart'; -import 'package:go_router/src/configuration.dart'; +import 'package:go_router/src/state.dart'; import 'test_helpers.dart'; diff --git a/packages/go_router/test/information_provider_test.dart b/packages/go_router/test/information_provider_test.dart index d708515183..02711a77a5 100644 --- a/packages/go_router/test/information_provider_test.dart +++ b/packages/go_router/test/information_provider_test.dart @@ -4,7 +4,7 @@ import 'package:flutter/widgets.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'package:go_router/src/information_provider.dart'; +import 'package:go_router/go_router.dart'; const String initialRoute = '/'; const String newRoute = '/new'; diff --git a/packages/go_router/test/match_test.dart b/packages/go_router/test/match_test.dart index f9e73075dd..d99e8edf56 100644 --- a/packages/go_router/test/match_test.dart +++ b/packages/go_router/test/match_test.dart @@ -5,7 +5,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:go_router/go_router.dart'; -import 'package:go_router/src/match.dart'; void main() { group('RouteMatch', () { diff --git a/packages/go_router/test/matching_test.dart b/packages/go_router/test/matching_test.dart index 640a467b90..b6337f47c8 100644 --- a/packages/go_router/test/matching_test.dart +++ b/packages/go_router/test/matching_test.dart @@ -6,9 +6,8 @@ import 'dart:async'; import 'package:flutter/widgets.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'package:go_router/src/configuration.dart'; +import 'package:go_router/go_router.dart'; import 'package:go_router/src/match.dart'; -import 'package:go_router/src/router.dart'; import 'test_helpers.dart'; diff --git a/packages/go_router/test/parser_test.dart b/packages/go_router/test/parser_test.dart index ad2573f614..c303ea3608 100644 --- a/packages/go_router/test/parser_test.dart +++ b/packages/go_router/test/parser_test.dart @@ -5,10 +5,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:go_router/go_router.dart'; -import 'package:go_router/src/configuration.dart'; -import 'package:go_router/src/information_provider.dart'; -import 'package:go_router/src/match.dart'; -import 'package:go_router/src/parser.dart'; RouteInformation createRouteInformation(String location, [Object? extra]) { return RouteInformation( diff --git a/packages/go_router/test/test_helpers.dart b/packages/go_router/test/test_helpers.dart index 229452cad6..71c89109f9 100644 --- a/packages/go_router/test/test_helpers.dart +++ b/packages/go_router/test/test_helpers.dart @@ -8,7 +8,6 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:go_router/go_router.dart'; -import 'package:go_router/src/match.dart'; Future createGoRouter(WidgetTester tester) async { final GoRouter goRouter = GoRouter(