Flutter 手势侧滑返回

以前遇到过侧滑退出App的需求,以前没有做过,所以在此留下做法,我写的做法是之前网上查到的,但具体是哪个大佬写的忘记了。

Scaffold(
  body: WillPopScope(
       child: ,
       onWillPop: () async{
           MySingleton().quitAPP();///这里是做处理的地方
           return false;///禁止返回上一层
       },
   ),
)

这里是桥接安卓事件

///退出app
  Future quitAPP() async {
    if(MySingleton().isQuit){
      await SystemChannels.platform.invokeMethod('SystemNavigator.pop');
    }else{
      UISingleton().showBlueLog('再次返回确认退出');///这里是弹窗提示
      MySingleton().isQuit = true;
      MySingleton().quitTimer = Timer(Duration(seconds: 2), (){
        MySingleton().isQuit = false;
        MySingleton().quitTimer.cancel();
      });
    }
  }

你可能感兴趣的:(Flutter 手势侧滑返回)