简体   繁体   中英

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? 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. But how do I do this when I go back with swipe gesture?

PS WillPopScope will not help, only relevant for Android.

I don't think there's a way to directly pass the result without using 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.
  2. You can use a shared state somewhere up the tree to store data using one of the state management approaches .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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