DateTime? currentBackPressTime;
Future<bool> onWillPop() async {
DateTime now = DateTime.now();
if (currentBackPressTime == null ||
now.difference(currentBackPressTime!) > Duration(seconds: 2)) {
currentBackPressTime = now;
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('再按一次退出应用'),
),
);
return false;
}
SystemNavigator.pop(); // 退出应用
return true;
}
WillPopScope(
onWillPop: onWillPop,
child:)