mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
make router assert more strict (#67672)
This commit is contained in:
parent
973404a27f
commit
cb0bdb4994
@ -245,7 +245,12 @@ class Router<T> extends StatefulWidget {
|
||||
this.routeInformationParser,
|
||||
required this.routerDelegate,
|
||||
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),
|
||||
super(key: key);
|
||||
|
||||
|
||||
@ -118,6 +118,50 @@ void main() {
|
||||
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 {
|
||||
final SimpleRouteInformationProvider provider = SimpleRouteInformationProvider();
|
||||
provider.value = const RouteInformation(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user