Fixes router to not report route information when it is already up to… (#64596)
diff --git a/packages/flutter/lib/src/widgets/router.dart b/packages/flutter/lib/src/widgets/router.dart
index d2e3132..9594203 100644
--- a/packages/flutter/lib/src/widgets/router.dart
+++ b/packages/flutter/lib/src/widgets/router.dart
@@ -395,7 +395,6 @@
if (widget.routeInformationProvider != null) {
_processInitialRoute();
}
- _lastSeenLocation = widget.routeInformationProvider?.value?.location;
}
bool _routeInformationReportingTaskScheduled = false;
@@ -552,6 +551,7 @@
void _processInitialRoute() {
_currentRouteInformationParserTransaction = Object();
_currentRouterDelegateTransaction = Object();
+ _lastSeenLocation = widget.routeInformationProvider.value.location;
widget.routeInformationParser
.parseRouteInformation(widget.routeInformationProvider.value)
.then<T>(_verifyRouteInformationParserStillCurrent(_currentRouteInformationParserTransaction, widget))
@@ -563,6 +563,7 @@
void _handleRouteInformationProviderNotification() {
_currentRouteInformationParserTransaction = Object();
_currentRouterDelegateTransaction = Object();
+ _lastSeenLocation = widget.routeInformationProvider.value.location;
widget.routeInformationParser
.parseRouteInformation(widget.routeInformationProvider.value)
.then<T>(_verifyRouteInformationParserStillCurrent(_currentRouteInformationParserTransaction, widget))
diff --git a/packages/flutter/test/widgets/router_test.dart b/packages/flutter/test/widgets/router_test.dart
index 4cf5463..e14f32f 100644
--- a/packages/flutter/test/widgets/router_test.dart
+++ b/packages/flutter/test/widgets/router_test.dart
@@ -434,6 +434,45 @@
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<RouteInformation>(
+ 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(