diff --git a/packages/patapata_core/lib/src/widgets/standard_page.dart b/packages/patapata_core/lib/src/widgets/standard_page.dart index 2d1a3ec..18ababf 100644 --- a/packages/patapata_core/lib/src/widgets/standard_page.dart +++ b/packages/patapata_core/lib/src/widgets/standard_page.dart @@ -784,6 +784,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(); @@ -1192,8 +1199,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); @@ -1897,9 +1905,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) { @@ -1929,6 +1940,13 @@ class StandardRouterDelegate extends RouterDelegate final tFuture = (tCompleter as Completer).future; + if (tLastPageDataChanged) { + _pageInstanceToRouteData[tLastPageInstance] = StandardRouteData( + factory: tFactory, + pageData: pageData, + ); + } + _updatePages(); return tFuture; diff --git a/packages/patapata_core/test/standard_app_widget_test.dart b/packages/patapata_core/test/standard_app_widget_test.dart index c3aafc1..6996a19 100644 --- a/packages/patapata_core/test/standard_app_widget_test.dart +++ b/packages/patapata_core/test/standard_app_widget_test.dart @@ -814,6 +814,45 @@ void main() { tApp.dispose(); }); + testWidgets( + "Standard Page PageData Test. If you have a pageKey for a StandardPage that ignores pageData.", + (WidgetTester tester) async { + final App tApp = createApp( + appWidget: StandardCupertinoApp( + onGenerateTitle: (context) => 'Test Title', + pages: [ + StandardPageFactory( + create: (data) => TestPageA(), + ), + StandardPageFactory( + pageKey: (_) => const ValueKey('TestPageC'), + create: (data) => TestPageC(), + ), + ], + ), + ); + + tApp.run(); + + await tApp.runProcess(() async { + await tester.pumpAndSettle(); + + await tester.tap(find.byKey(const ValueKey(kGoPageDataButton))); + + await tester.pumpAndSettle(); + + expect(find.text('Test Link Data is 10'), findsOneWidget); + + await tester.tap(find.byKey(const ValueKey(kGoPageDataButton))); + + await tester.pumpAndSettle(); + + expect(find.text('Test Link Data is 20'), findsOneWidget); + }); + + tApp.dispose(); + }); + testWidgets("Standard Page PageData Test. pageDataWhenNull", (WidgetTester tester) async { final App tApp = createApp(