android - WillPopScope 不适用于 Flutter 中的 IOS

标签 android ios flutter dart

在我的 flutter 应用程序中,我想控制 IOS 的弹出范围,但它不起作用。我没有像建议的一些示例那样使用 PageRoute 和 CupertinoWillPopScope包无法正常工作,它会抛出anchorpoint错误。那么有人可以帮我吗?

我尝试了 IOS 的 gestureDetector,但它没有触发上一页的操作,而这正是我想要做的。

if (!Platform.isIOS) {
      return WillPopScope(
        onWillPop: () async {
          timerController.startTimer();
          !Navigator.of(context).userGestureInProgress;
          return true;
        },
        child: MyPage(),
      );
    } else {
      return GestureDetector(
        onHorizontalDragUpdate: (details) {
          int sensitivity = 8;
          if (details.delta.dx > sensitivity) {
            // Right Swipe
            //timerController.startTimer();
          } else if (details.delta.dx < -sensitivity) {
            //Left Swipe
            timerController.startTimer();
          }
        },
        child: MyPage(),
      );
    }

最佳答案

问题尚未解决,请在 GitHub 中查看:here

我为 WillPopScope 制作了自定义类,它对我有用,我希望它也对您有用。

class MyWillPopScope extends StatelessWidget {

  MyWillPopScope({required this.child, this.onWillPop = false, Key? key}) : super(key: key);

  final Widget child;
  final bool onWillPop;

  @override
  Widget build(BuildContext context) {
    return Platform.isIOS ?
    GestureDetector(
      onPanUpdate: (details) {
        if (details.delta.dx > 0) {
          if(onWillPop){
            Navigator.of(context).pop();
          }
        }
      },
      child: WillPopScope(
        onWillPop: ()async{
          return false;
        },
        child: child,
      )
    )
    : WillPopScope(child: child, onWillPop: () async {
      return onWillPop;
    });
  }
}

关于android - WillPopScope 不适用于 Flutter 中的 IOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74419860/

相关文章:

android - 无法流式传输视频

php - 优化 foreach() 中的 SQL 查询

ios - ViewDidAppear 不会在每次应用程序进入前台时执行

android - Flutter 应用程序无法以 Debug模式启动

flutter - 如何在调用屏幕时显示 map

dart - 当应用程序被卸载时,sharedpreferences 会发生什么变化?

javascript - Cordova OnsenUI 应用程序中的 Google map V3( map 显示在浏览器中,但不在手机上)

java - Android 在服务类中创建新线程

ios - 如何创建同时缓存的发布属性包装器

ios - 如何使用 swift ios 在 mapview 中添加两个注释?