繁体   English   中英

如何在 flutter 中添加关闭对话框

[英]How to add closing dialog box in flutter

当用户多次按下返回按钮时,如何在 flutter 中添加退出应用程序的对话框。 它在ondetach过程中吗?

用 WillPopScope 小部件包裹你的脚手架

然后分配 onWillPop: _willPopCallback,

带有 WillPopScope Widget 的 Scaffold 将是 child: WillPopScope( onWillPop: _willPopCallback, child: Scaffold(

然后创建 function

DateTime currentBackPressTime;

Future<bool> _willPopCallback() async {
DateTime now = DateTime.now();
if (currentBackPressTime == null || now.difference(currentBackPressTime) > Duration(seconds: 2)) {
  currentBackPressTime = now;


 // Do Things Here
 // Dialog Box
 // Snackbar
 // Toast



   return Future.value(false);
 }
return Future.value(true);
}

希望对你有帮助

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM