逻辑:
比对两次返回时间
需要用到WillPopScope组件 捕捉返回事件
实现:
return new WillPopScope(
child: //,
onWillPop: () async{
// 点击返回键的操作
if(lastPopTime == null || DateTime.now().difference(lastPopTime) > Duration(seconds: 2)){
lastPopTime = DateTime.now();
Fluttertoast.showToast(msg: '请再按一次退出!');
}else{
lastPopTime = DateTime.now();
// 退出app
await SystemChannels.platform.invokeMethod('SystemNavigator.pop');
}
},);
如果文章对您有帮助请自行mark
关注我,一起成长!
先赞后看是个好习惯
@As.Kai