WillPopScope prevents swipe to go back on MaterialPageRoute
- Add a
MaterialPageRoute
to your app's page stackreturn new MaterialPageRoute<Null>( settings: settings, builder: (BuildContext context) => new StoryPage(itemId: itemId), );
- Wrap that page's
Scaffold
in aWillPopScope
widgetreturn 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(), );