From fbc15384bba46a7af6d3dbc034a8457322449087 Mon Sep 17 00:00:00 2001 From: chunhtai <47866232+chunhtai@users.noreply.github.com> Date: Thu, 27 Aug 2020 16:43:05 -0700 Subject: [PATCH] =?UTF-8?q?Fixes=20router=20to=20not=20report=20route=20in?= =?UTF-8?q?formation=20when=20it=20is=20already=20up=20to=E2=80=A6=20(#645?= =?UTF-8?q?96)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/flutter/lib/src/widgets/router.dart | 3 +- .../flutter/test/widgets/router_test.dart | 39 +++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/packages/flutter/lib/src/widgets/router.dart b/packages/flutter/lib/src/widgets/router.dart index d2e3132d11..959420355e 100644 --- a/packages/flutter/lib/src/widgets/router.dart +++ b/packages/flutter/lib/src/widgets/router.dart @@ -395,7 +395,6 @@ class _RouterState extends State> { if (widget.routeInformationProvider != null) { _processInitialRoute(); } - _lastSeenLocation = widget.routeInformationProvider?.value?.location; } bool _routeInformationReportingTaskScheduled = false; @@ -552,6 +551,7 @@ class _RouterState extends State> { void _processInitialRoute() { _currentRouteInformationParserTransaction = Object(); _currentRouterDelegateTransaction = Object(); + _lastSeenLocation = widget.routeInformationProvider.value.location; widget.routeInformationParser .parseRouteInformation(widget.routeInformationProvider.value) .then(_verifyRouteInformationParserStillCurrent(_currentRouteInformationParserTransaction, widget)) @@ -563,6 +563,7 @@ class _RouterState extends State> { void _handleRouteInformationProviderNotification() { _currentRouteInformationParserTransaction = Object(); _currentRouterDelegateTransaction = Object(); + _lastSeenLocation = widget.routeInformationProvider.value.location; widget.routeInformationParser .parseRouteInformation(widget.routeInformationProvider.value) .then(_verifyRouteInformationParserStillCurrent(_currentRouteInformationParserTransaction, widget)) diff --git a/packages/flutter/test/widgets/router_test.dart b/packages/flutter/test/widgets/router_test.dart index 4cf54635bf..e14f32fd74 100644 --- a/packages/flutter/test/widgets/router_test.dart +++ b/packages/flutter/test/widgets/router_test.dart @@ -434,6 +434,45 @@ void main() { expect(reportedRouteInformation.location, 'update'); }); + testWidgets('router does not report when route information is up to date with route information provider', (WidgetTester tester) async { + RouteInformation reportedRouteInformation; + final SimpleRouteInformationProvider provider = SimpleRouteInformationProvider( + onRouterReport: (RouteInformation information) { + reportedRouteInformation = information; + } + ); + provider.value = const RouteInformation( + location: 'initial', + ); + final SimpleRouterDelegate delegate = SimpleRouterDelegate(reportConfiguration: true); + delegate.builder = (BuildContext context, RouteInformation routeInformation) { + return Text(routeInformation.location); + }; + + await tester.pumpWidget(buildBoilerPlate( + Router( + routeInformationProvider: provider, + routeInformationParser: SimpleRouteInformationParser(), + routerDelegate: delegate, + ) + )); + expect(find.text('initial'), findsOneWidget); + expect(reportedRouteInformation, isNull); + // This will cause the router to rebuild. + provider.value = const RouteInformation( + location: 'update', + ); + // This will schedule the route reporting. + delegate.notifyListeners(); + await tester.pump(); + + expect(find.text('initial'), findsNothing); + expect(find.text('update'), findsOneWidget); + // The router should not report because the route name is already up to + // date. + expect(reportedRouteInformation, isNull); + }); + testWidgets('PlatformRouteInformationProvider works', (WidgetTester tester) async { final RouteInformationProvider provider = PlatformRouteInformationProvider( initialRouteInformation: const RouteInformation(