Flutter:在iOS和Android中禁用滑动导航 [英] Flutter: Disable Swipe to Navigate Back in iOS and Android
问题描述
我是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),而且我发现了这个利基小标志:Navigator对象上的 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和Android中禁用滑动导航的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!