简体   繁体   English

Flutter:iOS 带有数据的向后滑动手势

[英]Flutter: iOS swipe back gesture with data

I'm trying to implement a way to send data back to previous route.我正在尝试实现一种将数据发送回先前路由的方法。 The Navigator.of(context).pop function allows a parameter that works perfectly when used with a button-onpress. Navigator.of(context).pop function 允许参数在与按钮按下时完美配合。 Problem is: On Android, users can also go back via the Android-specific back button, so I tried to catch this with the help of a WillPopScope-widget.问题是:在 Android 上,用户还可以通过 Android 特定的后退按钮返回 go,所以我试图借助 WillPopScope 小部件来解决这个问题。 Within the onWillPop parameter, I again use Navigator.of(context).pop(data), so now the job is done on Android.在 onWillPop 参数中,我再次使用 Navigator.of(context).pop(data),所以现在工作在 Android 上完成。 New problem is: Now, due to the WillPopScope widget, swipe-back gestures on iOS dont work anymore.新问题是:现在,由于 WillPopScope 小部件,iOS 上的向后滑动手势不再起作用。

So, the question is: How can I send data back to previous route, no matter whether user tapped on a button I put there, tapped on Android-specific back-button or used the swipe-back gesture on iOS?所以,问题是:我如何才能将数据发送回之前的路由,无论用户是点击了我放在那里的按钮、点击了 Android 特定的后退按钮还是使用了 iOS 上的向后滑动手势?

Hope it got clear:)希望它清楚:)

For iOS you can implement the CupertinoPageRoute instead of MaterialPageRoute like this:对于 iOS,您可以像这样实现 CupertinoPageRoute 而不是 MaterialPageRoute:

import 'dart:io';
import 'package:flutter/cupertino.dart';

if(Platform.isIOS) {
   CupertinoPageRoute route = CupertinoPageRoute(
                           settings: RouteSettings(arguments: YOUR ARGUMENTS),
                           builder: (context) => SecondPage());

} 
await Navigator.push(context, route);

now you have access the Arguments you passed in the settings prop when you swipe back.现在您可以访问当您向后滑动时在settings道具中传递的 Arguments。

I hope this will fix your Issue.我希望这能解决您的问题。

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

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