发布于 4年前
flutter 双击返回退出APP
DateTime mLastDateTime;
Future<bool> _doubleExit() {
var nowDateTime = DateTime.now();
if (mLastDateTime != null &&
nowDateTime.millisecondsSinceEpoch -
mLastDateTime.millisecondsSinceEpoch <
2000) {
return Future.value(true);
} else {
mLastDateTime = DateTime.now();
Utils.toast.info('再按一次退出');
return Future.value(false);
}
}
@override
Widget build(BuildContext context) {
return WillPopScope(
onWillPop: _doubleExit,
child: Scaffold(
body: renderBody(),
bottomNavigationBar: renderBottomNavigationBar(),
));
}