Open tomaspodmanicky opened 9 months ago
There is an open PR for this at https://github.com/flutter/flutter/pull/139164
If i understand correctly, this is asking for a way to inject result when user backswipe. The linked pr does not solve the issue.
@tomaspodmanicky I think it is always impossible to inject the result even with willpopscope, or did I misunderstood something?
@chunhtai yes, currently, it is not possible with WillPopScope, but because there is new widget for that I think it is good to implement this funcionality. Currently if you want to return data from current screen to previous, you cant backswipe on iOS, and that sucks...
sometimes I need to use exit dialog - that means I have to use Navigator.pop and backswipe is not possible, but I think it would be nice to have this feature implemented
it is by design, if user backswipe, it means they want to abort the current workflow. In this case, the system do not want anything to change. It is the same as android back button. It is also why the route future is always T?
, not just T
.
If you do want to have some data persist after a route is popped, you can use some state management system.
abort? i mean it works everywhere and it does not feel like I want to abort something. I just want to go back. So there is no chance of this feature being implemented? How can I then solve it using state management? Can you send me some link, tutorial or just something?
my problem is, that I navigate at some route, change the data there and then swipe back to the listview, where I need to update the data without calling the API...
Perhaps you could take the API sample as a starting point?
https://github.com/flutter/flutter/blob/master/examples/api/lib/widgets/pop_scope/pop_scope.0.dart
It includes a dialog example.
For the other case, you could try to set canPop
to true and set the "value" in the onPopInvoked callback, using a state management solution. This way you can still get the value when the user did a backswipe.
What do you mean, by starting point? I need to somehow update the data in listview, and this way it is the fastest.
But this callback in popScope is called after the pop is executed, so how can I return the data?
Before the pop event, the framework could request a result, which would then be delegated to PopScope
.
body: PopScope( canPop: true, onPopInvoked: (didPop) async { if (didPop) { ref.read(someProvider.notifier).presettedFunction(data); } },
if you use App-wide state(ex. riverpod) instead of sending data through Navigator.pop(), you can use back-swipe while updating the data also.
Is the code below what you have with WillPopScope, and you're trying to migrate that to PopScope?
Maybe we shouldn't support that out of the box with PopScope. It seems like when using showDialog
, if the user dismisses by tapping the barrier, then null
is returned as the route result. So that tells me that passing a value other than null
in that kind of situation is going against the design of things.
I think I would lean towards finding another solution as others have suggested.
any update about this part,i think when user use swipe back,the data return to previous is normal action.
same issue
The PR mentioned above is almost ready to merge (https://github.com/flutter/flutter/pull/139164).
Edit: Sorry, looks like that PR doesn't solve this issue. See also https://github.com/flutter/flutter/issues/138624.
anything new about this?
We can make use of https://api.flutter.dev/flutter/widgets/Route/currentResult.html
currently the backswipe just call navigator.pop without a result
and where should i use that?
I guess there would need to be framework changes. Something like we could get a result from the route here:
And then pass it through to the pop here:
Is there an existing issue for this?
Use case
Currently, the PopScope widget does not allow to implement iOS back swipe with returning data to previous page. As WillPopScope is depracated because this feature is coming to Android, it should be improved...
In my applications, I HAVE TO return data to previous page - sometimes dialog has to be used, but sometimes not (canPop is kinda OK), but I also want to use iOS back swipe, because it is really handy feature and users like it.
Proposal
PopScope widget should be able to return data to the previous page. Overwrite the Navigator.pop(), that is built in the widget, or something. And what would be the best - ability to invoke back swipe, but, after that, prompt the dialog, so user can click "Cancel" and stay on current page.