Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes new pageData not being used in old StandardPage's brought back to the top of the navigation stack. #30

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions packages/patapata_core/lib/src/widgets/standard_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,13 @@ abstract class StandardPageWithResult<T extends Object?, E extends Object?>

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();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -1820,9 +1828,12 @@ class StandardRouterDelegate extends RouterDelegate<StandardRouteData>
?.standardPageKey
.currentState;

bool tLastPageDataChanged = false;

if (tLastPage != null) {
if (tLastPage.pageData != pageData) {
tLastPage.pageData = pageData;
tLastPageDataChanged = true;
}

if (tLastPage.active) {
Expand Down Expand Up @@ -1852,6 +1863,13 @@ class StandardRouterDelegate extends RouterDelegate<StandardRouteData>

final tFuture = (tCompleter as Completer<E?>).future;

if (tLastPageDataChanged) {
_pageInstanceToRouteData[tLastPageInstance] = StandardRouteData(
factory: tFactory,
pageData: pageData,
);
}

_updatePages();

return tFuture;
Expand Down
Loading