这是我的代码的示例(我使用“ fluttertoast”显示吐司消息,您可以使用小吃栏或警报或其他方式)
DateTime currentBackPressTime;@overrideWidget build(BuildContext context) { return Scaffold( ... body: WillPopScope(child: getBody(), onWillPop: onWillPop), );}Future<bool> onWillPop() { DateTime now = DateTime.now(); if (currentBackPressTime == null || now.difference(currentBackPressTime) > Duration(seconds: 2)) { currentBackPressTime = now; Fluttertoast.showToast(msg: exit_warning); return Future.value(false); } return Future.value(true); }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)