Flutter:在iOS中禁用滑动导航 [英] Flutter: Disable Swipe to Navigate Back in iOS

查看:408
本文介绍了Flutter:在iOS中禁用滑动导航的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是flutter开发的新手,在iOS中,当您有导航抽屉并滑动以打开它时,它会感到沮丧,它将执行Navigation.of(context).pop().我想在iOS中禁用此滑动弹出"行为.我一直在仔细阅读文档,但是运气不佳.

I'm new to flutter development, and find it a bit frustrating in iOS when you have a navigation drawer and when you swipe to open it, it'll perform a Navigation.of(context).pop(). I would like to disable this "swipe to pop" behavior in iOS. I have been perusing the documentation, but without much luck.

我确实看到了称为 WillPopScope 的东西似乎可以解决问题( github问题在这里),但我不是100 %确定这是否是正确"的方法(似乎太复杂了……应该更容易了……就像根应用程序上的设置一样.)

I do see something referred to as a WillPopScope which seems to do the trick (github issue for it here), but I'm not 100% sure if this is the "correct" way to do it (it seems too complicated... it should be easier... like a setting on the root app).

推荐答案

我在这里还有一点.我只是在解决这个问题,但是我还需要用户能够通过按一下AppBar上的本机"后退按钮(不仅仅因为这个原因不想重新实现AppBar),而且我发现了这个利基小标志:导航器对象上的userGestureInProgress,所以我使用的(并且假定是首选方式)是:

I have one additional point here. I was just solving this problem, but I also needed my user to be able to go back by pressing the "native" back button on the AppBar (did not want to reimplement AppBar just because of this), and I found this niche little flag: userGestureInProgress on the Navigator object, so what I use (and presume is the preferred way) is:

onWillPop: () async {
    if (Navigator.of(context).userGestureInProgress)
      return false;
    else
      return true;
  },

这篇关于Flutter:在iOS中禁用滑动导航的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆