Unverified Commit cb0bdb49 authored by chunhtai's avatar chunhtai Committed by GitHub

make router assert more strict (#67672)

parent 973404a2
...@@ -245,7 +245,12 @@ class Router<T> extends StatefulWidget { ...@@ -245,7 +245,12 @@ class Router<T> extends StatefulWidget {
this.routeInformationParser, this.routeInformationParser,
required this.routerDelegate, required this.routerDelegate,
this.backButtonDispatcher, this.backButtonDispatcher,
}) : assert(routeInformationProvider == null || routeInformationParser != null), }) : assert(
(routeInformationProvider == null) == (routeInformationParser == null),
'You must provide both routeInformationProvider and routeInformationParser '
'if this router parses route information. Otheriwse, they should both '
'be null.'
),
assert(routerDelegate != null), assert(routerDelegate != null),
super(key: key); super(key: key);
......
...@@ -118,6 +118,50 @@ void main() { ...@@ -118,6 +118,50 @@ void main() {
expect(find.text('popped'), findsOneWidget); expect(find.text('popped'), findsOneWidget);
}); });
testWidgets('Router throw when passes only routeInformationProvider', (WidgetTester tester) async {
final SimpleRouteInformationProvider provider = SimpleRouteInformationProvider();
provider.value = const RouteInformation(
location: 'initial',
);
try {
Router<RouteInformation>(
routeInformationProvider: provider,
routerDelegate: SimpleRouterDelegate(
builder: (BuildContext context, RouteInformation information) {
return Text(information.location);
},
),
);
} on AssertionError catch(e) {
expect(
e.message,
'You must provide both routeInformationProvider and '
'routeInformationParser if this router parses route information. '
'Otheriwse, they should both be null.'
);
}
});
testWidgets('Router throw when passes only routeInformationParser', (WidgetTester tester) async {
try {
Router<RouteInformation>(
routeInformationParser: SimpleRouteInformationParser(),
routerDelegate: SimpleRouterDelegate(
builder: (BuildContext context, RouteInformation information) {
return Text(information.location);
},
),
);
} on AssertionError catch(e) {
expect(
e.message,
'You must provide both routeInformationProvider and '
'routeInformationParser if this router parses route information. '
'Otheriwse, they should both be null.'
);
}
});
testWidgets('PopNavigatorRouterDelegateMixin works', (WidgetTester tester) async { testWidgets('PopNavigatorRouterDelegateMixin works', (WidgetTester tester) async {
final SimpleRouteInformationProvider provider = SimpleRouteInformationProvider(); final SimpleRouteInformationProvider provider = SimpleRouteInformationProvider();
provider.value = const RouteInformation( provider.value = const RouteInformation(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment