make router assert more strict (#67672)
This commit is contained in:
@@ -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() {
|
|||||||
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(
|
||||||
|
|||||||
Reference in New Issue
Block a user