[go_router] removes DebugGoRouteInformation (#2713)

This commit is contained in:
chunhtai
2022-10-18 11:20:53 -07:00
committed by GitHub
parent 550e445951
commit ec78204d73
6 changed files with 17 additions and 39 deletions

View File

@ -1,3 +1,7 @@
## 5.1.1
- Removes DebugGoRouteInformation.
## 5.1.0 ## 5.1.0
- Removes urlPathStrategy completely, which should have been done in v5.0.0 but some code remained mistakenly. - Removes urlPathStrategy completely, which should have been done in v5.0.0 but some code remained mistakenly.

View File

@ -5,7 +5,6 @@
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'parser.dart';
/// The [RouteInformationProvider] created by go_router. /// The [RouteInformationProvider] created by go_router.
class GoRouteInformationProvider extends RouteInformationProvider class GoRouteInformationProvider extends RouteInformationProvider
@ -44,10 +43,7 @@ class GoRouteInformationProvider extends RouteInformationProvider
} }
@override @override
RouteInformation get value => DebugGoRouteInformation( RouteInformation get value => _value;
location: _value.location,
state: _value.state,
);
RouteInformation _value; RouteInformation _value;
set value(RouteInformation other) { set value(RouteInformation other) {
@ -110,10 +106,3 @@ class GoRouteInformationProvider extends RouteInformationProvider
return SynchronousFuture<bool>(true); return SynchronousFuture<bool>(true);
} }
} }
/// A debug class that is used for asserting the [GoRouteInformationProvider] is
/// in use with the [GoRouteInformationParser].
class DebugGoRouteInformation extends RouteInformation {
/// Creates a [DebugGoRouteInformation].
const DebugGoRouteInformation({super.location, super.state});
}

View File

@ -53,17 +53,6 @@ class GoRouteInformationParser extends RouteInformationParser<RouteMatchList> {
RouteInformation routeInformation, RouteInformation routeInformation,
BuildContext context, BuildContext context,
) { ) {
assert(() {
if (debugRequireGoRouteInformationProvider) {
assert(
routeInformation is DebugGoRouteInformation,
'This GoRouteInformationParser needs to be used with '
'GoRouteInformationProvider, did you forget to pass in '
'GoRouter.routeInformationProvider to the Router constructor?',
);
}
return true;
}());
late final RouteMatchList initialMatches; late final RouteMatchList initialMatches;
try { try {
initialMatches = matcher.findMatch(routeInformation.location!, initialMatches = matcher.findMatch(routeInformation.location!,

View File

@ -186,7 +186,7 @@ class GoRouter extends ChangeNotifier
}()); }());
_routeInformationParser _routeInformationParser
.parseRouteInformationWithDependencies( .parseRouteInformationWithDependencies(
DebugGoRouteInformation(location: location, state: extra), RouteInformation(location: location, state: extra),
// TODO(chunhtai): avoid accessing the context directly through global key. // TODO(chunhtai): avoid accessing the context directly through global key.
// https://github.com/flutter/flutter/issues/99112 // https://github.com/flutter/flutter/issues/99112
_routerDelegate.navigatorKey.currentContext!, _routerDelegate.navigatorKey.currentContext!,
@ -218,7 +218,7 @@ class GoRouter extends ChangeNotifier
void replace(String location, {Object? extra}) { void replace(String location, {Object? extra}) {
routeInformationParser routeInformationParser
.parseRouteInformationWithDependencies( .parseRouteInformationWithDependencies(
DebugGoRouteInformation(location: location, state: extra), RouteInformation(location: location, state: extra),
// TODO(chunhtai): avoid accessing the context directly through global key. // TODO(chunhtai): avoid accessing the context directly through global key.
// https://github.com/flutter/flutter/issues/99112 // https://github.com/flutter/flutter/issues/99112
_routerDelegate.navigatorKey.currentContext!, _routerDelegate.navigatorKey.currentContext!,

View File

@ -1,7 +1,7 @@
name: go_router name: go_router
description: A declarative router for Flutter based on Navigation 2 supporting description: A declarative router for Flutter based on Navigation 2 supporting
deep linking, data-driven routes and more deep linking, data-driven routes and more
version: 5.1.0 version: 5.1.1
repository: https://github.com/flutter/packages/tree/main/packages/go_router 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 issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+go_router%22

View File

@ -6,7 +6,6 @@ import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:go_router/go_router.dart'; import 'package:go_router/go_router.dart';
import 'package:go_router/src/configuration.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/match.dart';
import 'package:go_router/src/matching.dart'; import 'package:go_router/src/matching.dart';
import 'package:go_router/src/parser.dart'; import 'package:go_router/src/parser.dart';
@ -54,7 +53,7 @@ void main() {
RouteMatchList matchesObj = RouteMatchList matchesObj =
await parser.parseRouteInformationWithDependencies( await parser.parseRouteInformationWithDependencies(
const DebugGoRouteInformation(location: '/'), context); const RouteInformation(location: '/'), context);
List<RouteMatch> matches = matchesObj.matches; List<RouteMatch> matches = matchesObj.matches;
expect(matches.length, 1); expect(matches.length, 1);
expect(matches[0].queryParams.isEmpty, isTrue); expect(matches[0].queryParams.isEmpty, isTrue);
@ -65,8 +64,7 @@ void main() {
final Object extra = Object(); final Object extra = Object();
matchesObj = await parser.parseRouteInformationWithDependencies( matchesObj = await parser.parseRouteInformationWithDependencies(
DebugGoRouteInformation(location: '/abc?def=ghi', state: extra), RouteInformation(location: '/abc?def=ghi', state: extra), context);
context);
matches = matchesObj.matches; matches = matchesObj.matches;
expect(matches.length, 2); expect(matches.length, 2);
expect(matches[0].queryParams.length, 1); expect(matches[0].queryParams.length, 1);
@ -194,7 +192,7 @@ void main() {
final RouteMatchList matchesObj = final RouteMatchList matchesObj =
await parser.parseRouteInformationWithDependencies( await parser.parseRouteInformationWithDependencies(
const DebugGoRouteInformation(location: '/def'), context); const RouteInformation(location: '/def'), context);
final List<RouteMatch> matches = matchesObj.matches; final List<RouteMatch> matches = matchesObj.matches;
expect(matches.length, 1); expect(matches.length, 1);
expect(matches[0].queryParams.isEmpty, isTrue); expect(matches[0].queryParams.isEmpty, isTrue);
@ -229,8 +227,7 @@ void main() {
final BuildContext context = tester.element(find.byType(Router<Object>)); final BuildContext context = tester.element(find.byType(Router<Object>));
final RouteMatchList matchesObj = final RouteMatchList matchesObj =
await parser.parseRouteInformationWithDependencies( await parser.parseRouteInformationWithDependencies(
const DebugGoRouteInformation(location: '/123/family/456'), const RouteInformation(location: '/123/family/456'), context);
context);
final List<RouteMatch> matches = matchesObj.matches; final List<RouteMatch> matches = matchesObj.matches;
expect(matches.length, 2); expect(matches.length, 2);
@ -278,7 +275,7 @@ void main() {
final BuildContext context = tester.element(find.byType(Router<Object>)); final BuildContext context = tester.element(find.byType(Router<Object>));
final RouteMatchList matchesObj = final RouteMatchList matchesObj =
await parser.parseRouteInformationWithDependencies( await parser.parseRouteInformationWithDependencies(
const DebugGoRouteInformation(location: '/random/uri'), context); const RouteInformation(location: '/random/uri'), context);
final List<RouteMatch> matches = matchesObj.matches; final List<RouteMatch> matches = matchesObj.matches;
expect(matches.length, 2); expect(matches.length, 2);
@ -319,7 +316,7 @@ void main() {
final BuildContext context = tester.element(find.byType(Router<Object>)); final BuildContext context = tester.element(find.byType(Router<Object>));
final RouteMatchList matchesObj = final RouteMatchList matchesObj =
await parser.parseRouteInformationWithDependencies( await parser.parseRouteInformationWithDependencies(
const DebugGoRouteInformation(location: '/redirect'), context); const RouteInformation(location: '/redirect'), context);
final List<RouteMatch> matches = matchesObj.matches; final List<RouteMatch> matches = matchesObj.matches;
expect(matches.length, 2); expect(matches.length, 2);
@ -349,8 +346,7 @@ void main() {
final BuildContext context = tester.element(find.byType(Router<Object>)); final BuildContext context = tester.element(find.byType(Router<Object>));
expect(() async { expect(() async {
await parser.parseRouteInformationWithDependencies( await parser.parseRouteInformationWithDependencies(
const DebugGoRouteInformation(location: '::Not valid URI::'), const RouteInformation(location: '::Not valid URI::'), context);
context);
}, throwsA(isA<FormatException>())); }, throwsA(isA<FormatException>()));
}); });
@ -373,7 +369,7 @@ void main() {
final BuildContext context = tester.element(find.byType(Router<Object>)); final BuildContext context = tester.element(find.byType(Router<Object>));
final RouteMatchList matchesObj = final RouteMatchList matchesObj =
await parser.parseRouteInformationWithDependencies( await parser.parseRouteInformationWithDependencies(
const DebugGoRouteInformation(location: '/abd'), context); const RouteInformation(location: '/abd'), context);
final List<RouteMatch> matches = matchesObj.matches; final List<RouteMatch> matches = matchesObj.matches;
expect(matches, hasLength(1)); expect(matches, hasLength(1));
@ -417,7 +413,7 @@ void main() {
final BuildContext context = tester.element(find.byType(Router<Object>)); final BuildContext context = tester.element(find.byType(Router<Object>));
final RouteMatchList matchesObj = final RouteMatchList matchesObj =
await parser.parseRouteInformationWithDependencies( await parser.parseRouteInformationWithDependencies(
const DebugGoRouteInformation(location: '/a'), context); const RouteInformation(location: '/a'), context);
final List<RouteMatch> matches = matchesObj.matches; final List<RouteMatch> matches = matchesObj.matches;
expect(matches, hasLength(2)); expect(matches, hasLength(2));