From 4b2590e5861f89369e69f3ea0f4ff67a867fbb82 Mon Sep 17 00:00:00 2001 From: Jason Parrott Date: Mon, 9 Dec 2024 17:27:07 +0900 Subject: [PATCH] fix: fix an issue when StandardPage page data's type changes from nullable to non-nullable and null data is trying to be restored on route load. fix: fix an issue where if you navigate to an existing StandardPage, the old pageData would not be overridden with the new pageData. --- .../lib/src/widgets/standard_page.dart | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/packages/patapata_core/lib/src/widgets/standard_page.dart b/packages/patapata_core/lib/src/widgets/standard_page.dart index 69904d5..04f5554 100644 --- a/packages/patapata_core/lib/src/widgets/standard_page.dart +++ b/packages/patapata_core/lib/src/widgets/standard_page.dart @@ -770,6 +770,13 @@ abstract class StandardPageWithResult return; } + + // TODO: In the future, we should look at use cases here + // And decide if we want to update the current navigation + // data (like the URL) or not. Currently, we do not. + // If we were to, we'd need to update _pageInstanceToRouteData + // with the newest pageData. + _sendPageDataEvent(); (Router.of(context).routerDelegate as StandardRouterDelegate?) ?._updatePages(); @@ -1178,8 +1185,9 @@ class StandardRouteInformationParser @override RouteInformation? restoreRouteInformation(StandardRouteData configuration) { - final tStringLocation = - configuration.factory?.generateLink(configuration.pageData); + final tStringLocation = configuration.factory?.generateLink( + configuration.pageData ?? + configuration.factory?.pageDataWhenNull?.call()); if (tStringLocation != null) { final tLocation = Uri.tryParse(tStringLocation); @@ -1820,9 +1828,12 @@ class StandardRouterDelegate extends RouterDelegate ?.standardPageKey .currentState; + bool tLastPageDataChanged = false; + if (tLastPage != null) { if (tLastPage.pageData != pageData) { tLastPage.pageData = pageData; + tLastPageDataChanged = true; } if (tLastPage.active) { @@ -1852,6 +1863,13 @@ class StandardRouterDelegate extends RouterDelegate final tFuture = (tCompleter as Completer).future; + if (tLastPageDataChanged) { + _pageInstanceToRouteData[tLastPageInstance] = StandardRouteData( + factory: tFactory, + pageData: pageData, + ); + } + _updatePages(); return tFuture;