[web] Always send the route name even if it's null (#41996)
This commit is contained in:
@@ -29,14 +29,12 @@ class RouteNotificationMessages {
|
||||
static void _notifyRouteChange(String methodName, Route<dynamic> route, Route<dynamic> previousRoute) {
|
||||
final String previousRouteName = previousRoute?.settings?.name;
|
||||
final String routeName = route?.settings?.name;
|
||||
if (previousRouteName != null || routeName != null) {
|
||||
SystemChannels.navigation.invokeMethod<void>(
|
||||
methodName,
|
||||
<String, dynamic>{
|
||||
'previousRouteName': previousRouteName,
|
||||
'routeName': routeName,
|
||||
},
|
||||
);
|
||||
}
|
||||
SystemChannels.navigation.invokeMethod<void>(
|
||||
methodName,
|
||||
<String, dynamic>{
|
||||
'previousRouteName': previousRouteName,
|
||||
'routeName': routeName,
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -167,4 +167,51 @@ void main() {
|
||||
},
|
||||
));
|
||||
});
|
||||
|
||||
testWidgets('Nameless routes should send platform messages', (WidgetTester tester) async {
|
||||
final List<MethodCall> log = <MethodCall>[];
|
||||
SystemChannels.navigation.setMockMethodCallHandler((MethodCall methodCall) async {
|
||||
log.add(methodCall);
|
||||
});
|
||||
|
||||
await tester.pumpWidget(MaterialApp(
|
||||
initialRoute: '/home',
|
||||
routes: <String, WidgetBuilder>{
|
||||
'/home': (BuildContext context) {
|
||||
return OnTapPage(
|
||||
id: 'Home',
|
||||
onTap: () {
|
||||
// Create a route with no name.
|
||||
final Route<void> route = MaterialPageRoute<void>(
|
||||
builder: (BuildContext context) => const Text('Nameless Route'),
|
||||
);
|
||||
Navigator.push<void>(context, route);
|
||||
},
|
||||
);
|
||||
},
|
||||
},
|
||||
));
|
||||
|
||||
expect(log, hasLength(1));
|
||||
expect(
|
||||
log.last,
|
||||
isMethodCall('routePushed', arguments: <String, dynamic>{
|
||||
'previousRouteName': null,
|
||||
'routeName': '/home',
|
||||
}),
|
||||
);
|
||||
|
||||
await tester.tap(find.text('Home'));
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(seconds: 1));
|
||||
|
||||
expect(log, hasLength(2));
|
||||
expect(
|
||||
log.last,
|
||||
isMethodCall('routePushed', arguments: <String, dynamic>{
|
||||
'previousRouteName': '/home',
|
||||
'routeName': null,
|
||||
}),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user