WillPopScope prevents swipe to go back on MaterialPageRoute
- Add a
MaterialPageRouteto your app's page stackreturn new MaterialPageRoute<Null>( settings: settings, builder: (BuildContext context) => new StoryPage(itemId: itemId), );
- Wrap that page's
Scaffoldin aWillPopScopewidgetreturn new WillPopScope( onWillPop: () async { return true; }, child: new Scaffold( … ), ); - Try to swipe to go back on iOS. The page won't swipe.
我的优化,可以让手势在左边划起才生效
Platform.isIOS
? GestureDetector(
onHorizontalDragUpdate: (details) {
if (details.delta.dx > 3 && details.localPosition.dx < 50) {
onWillPop!.call();
}
},
child: WillPopScope(
onWillPop: onWillPop,
child: contextScaffold(),
),
)
: WillPopScope (
onWillPop:onWillPop,
child: contextScaffold(),
);
本文介绍了如何在Flutter中使用WillPopScope和GestureDetector来防止在MaterialPageRoute上进行右滑返回,通过检测iOS设备上的左滑手势并在符合条件时调用onWillPop方法实现单向导航。
3085

被折叠的 条评论
为什么被折叠?



