本篇为继上片监听返回键基础下优化:
以下做返回键监听两种情况:
import 'package:fluttertoast/fluttertoast.dart'; //提示第三方插件
1. 单击提示双击退出,双击时退出App
DateTime _lastPressedAt; //上次点击时间
main.dart-MyApp中:
home: WillPopScope( // 监听返回键Widget
onWillPop: () async { // 点击返回键即触发该事件
if (_lastPressedAt == null) { //首次点击提示...信息
Fluttertoast.showToast(
msg: "双击退出程序...",
gravity: ToastGravity.BOTTOM,
timeInSecForIos: 1,
backgroundColor: Colors.grey[400],
textColor: Colors.white,
fontSize: ScreenUtil().setWidth(12),
);
}
if (_lastPressedAt == null || DateT