简体   繁体   English

Flutter:当我使用 iOS 向后滑动手势时,如何将数据传回 Navigator?

[英]Flutter: How can I pass data back to Navigator when I use iOS swipe back gesture?

How can I pass some data back to Navigator when I close the page with iOS swipe back gesture?当我使用 iOS 向后滑动手势关闭页面时,如何将一些数据传递回 Navigator? If I close the page manually, obviously everything works correctly, because when I close it, I call the Navigator.pop() method and pass the data in the arguments.如果我手动关闭页面,显然一切正常,因为当我关闭它时,我会调用 Navigator.pop() 方法并在参数中传递数据。 But how do I do this when I go back with swipe gesture?但是当我用滑动手势返回时我该怎么做?

PS WillPopScope will not help, only relevant for Android. PS WillPopScope 无济于事,仅适用于 Android。

I don't think there's a way to directly pass the result without using Navigator.pop() .我认为没有办法在不使用Navigator.pop()情况下直接传递结果。 I can think of two ways for solving the issue:我可以想到两种解决问题的方法:

  1. If swiping back means "Cancel" (as opposite to eg submitting data via some explicit button, where you can call Navigator.pop(result) ), then you can distinguish these 2 cases by checking if result of Navigator.push() is not null.如果向后滑动意味着“取消”(与例如通过一些显式按钮提交数据相反,您可以在其中调用Navigator.pop(result) ),那么您可以通过检查Navigator.push()结果是否不是来区分这两种情况空值。
  2. You can use a shared state somewhere up the tree to store data using one of the state management approaches .您可以使用状态管理方法之一在树的某处使用共享状态来存储数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM