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

Returning result from a page after state restoration #149

Open
BarashkovaElena opened this issue Aug 9, 2024 · 2 comments
Open

Returning result from a page after state restoration #149

BarashkovaElena opened this issue Aug 9, 2024 · 2 comments

Comments

@BarashkovaElena
Copy link

qlevar_router allows to return the result from a page this way:
final result = await QR.to<String>('/page', waitForResult: true);

This works fine until we want to support state restoration on android. Consider the following steps:

  1. Configure the app with qlevar_router with state restoration enabled.
  2. Enable "don't keep activities" flag on Android device.
  3. Start the app and open a page with waitForResult = true
  4. Put the app to background, causing it to be killed by the system.
  5. Go back to the app, so that its state and route is restored.
  6. Close the currently opened page by calling QR.back('result')

The caller page will not receive this result.

I haven't found a way to pass result in a way that survives state restoration. Would be helpful to have this option.

@SchabanBo
Copy link
Owner

Correct me if I am wrong, but I don't think this is possible.
The issue arises because, after the app is killed and then restored, the asynchronous function waiting for a result cannot persist its state. When the app is restored, the function that was waiting is no longer in the same state, so it doesn’t know to continue awaiting the response. The awaiter context is lost during the state restoration process, making it impossible for the function to resume waiting for the result without additional mechanisms.

@BarashkovaElena
Copy link
Author

As far as I know, Navigation 2.0 can do that via https://api.flutter.dev/flutter/widgets/RestorableRouteFuture-class.html and other classes with "restorable" prefix.
But even go_router doesn't have this option yet, so I'm unsure how difficult to integrate it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants