[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
- 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/services.dart';
import 'package:flutter/widgets.dart';
import 'parser.dart';
/// The [RouteInformationProvider] created by go_router.
class GoRouteInformationProvider extends RouteInformationProvider
@ -44,10 +43,7 @@ class GoRouteInformationProvider extends RouteInformationProvider
}
@override
RouteInformation get value => DebugGoRouteInformation(
location: _value.location,
state: _value.state,
);
RouteInformation get value => _value;
RouteInformation _value;
set value(RouteInformation other) {
@ -110,10 +106,3 @@ class GoRouteInformationProvider extends RouteInformationProvider
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,
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;
try {
initialMatches = matcher.findMatch(routeInformation.location!,

View File

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

View File

@ -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: 5.1.0
version: 5.1.1
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

View File

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