Unverified Commit fbc15384 authored by chunhtai's avatar chunhtai Committed by GitHub

Fixes router to not report route information when it is already up to… (#64596)

parent 8a6a76a3
......@@ -395,7 +395,6 @@ class _RouterState<T> extends State<Router<T>> {
if (widget.routeInformationProvider != null) {
_processInitialRoute();
}
_lastSeenLocation = widget.routeInformationProvider?.value?.location;
}
bool _routeInformationReportingTaskScheduled = false;
......@@ -552,6 +551,7 @@ class _RouterState<T> extends State<Router<T>> {
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 @@ class _RouterState<T> extends State<Router<T>> {
void _handleRouteInformationProviderNotification() {
_currentRouteInformationParserTransaction = Object();
_currentRouterDelegateTransaction = Object();
_lastSeenLocation = widget.routeInformationProvider.value.location;
widget.routeInformationParser
.parseRouteInformation(widget.routeInformationProvider.value)
.then<T>(_verifyRouteInformationParserStillCurrent(_currentRouteInformationParserTransaction, widget))
......
......@@ -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<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(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment