From 1946fc4da0f80c522d7e3ae7d4f7309908ed86f2 Mon Sep 17 00:00:00 2001 From: Mouad Debbar Date: Mon, 7 Oct 2019 15:23:31 -0700 Subject: [PATCH] [web] Always send the route name even if it's null (#41996) --- .../widgets/route_notification_messages.dart | 16 +++---- .../route_notification_messages_test.dart | 47 +++++++++++++++++++ 2 files changed, 54 insertions(+), 9 deletions(-) diff --git a/packages/flutter/lib/src/widgets/route_notification_messages.dart b/packages/flutter/lib/src/widgets/route_notification_messages.dart index 5cbe6bd5eb..4b82a73690 100644 --- a/packages/flutter/lib/src/widgets/route_notification_messages.dart +++ b/packages/flutter/lib/src/widgets/route_notification_messages.dart @@ -29,14 +29,12 @@ class RouteNotificationMessages { static void _notifyRouteChange(String methodName, Route route, Route previousRoute) { final String previousRouteName = previousRoute?.settings?.name; final String routeName = route?.settings?.name; - if (previousRouteName != null || routeName != null) { - SystemChannels.navigation.invokeMethod( - methodName, - { - 'previousRouteName': previousRouteName, - 'routeName': routeName, - }, - ); - } + SystemChannels.navigation.invokeMethod( + methodName, + { + 'previousRouteName': previousRouteName, + 'routeName': routeName, + }, + ); } } diff --git a/packages/flutter/test/widgets/route_notification_messages_test.dart b/packages/flutter/test/widgets/route_notification_messages_test.dart index c8f9d3910d..8a7dee5ae7 100644 --- a/packages/flutter/test/widgets/route_notification_messages_test.dart +++ b/packages/flutter/test/widgets/route_notification_messages_test.dart @@ -167,4 +167,51 @@ void main() { }, )); }); + + testWidgets('Nameless routes should send platform messages', (WidgetTester tester) async { + final List log = []; + SystemChannels.navigation.setMockMethodCallHandler((MethodCall methodCall) async { + log.add(methodCall); + }); + + await tester.pumpWidget(MaterialApp( + initialRoute: '/home', + routes: { + '/home': (BuildContext context) { + return OnTapPage( + id: 'Home', + onTap: () { + // Create a route with no name. + final Route route = MaterialPageRoute( + builder: (BuildContext context) => const Text('Nameless Route'), + ); + Navigator.push(context, route); + }, + ); + }, + }, + )); + + expect(log, hasLength(1)); + expect( + log.last, + isMethodCall('routePushed', arguments: { + '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: { + 'previousRouteName': '/home', + 'routeName': null, + }), + ); + }); }