首页 > 解决方案 > 对话框在 Flutter 中关闭

问题描述

通过单击在后台加载哪些数据, 我有一个更新按钮。

当数据加载时,我正在显示AlertDialog,它会在数据加载时自动关闭。

但是,在加载数据时,如果用户单击屏幕上的其他位置,则对话框将关闭,这是不希望的。

问题是如何防止对话框关闭?

 Future<void> _loadingDialog(String title) async {
 return showDialog(
   context: context,
   barrierDismissible: true,
   builder: (context) {
     return AlertDialog(
       title: Text(title),
       content: LinearProgressIndicator(
         backgroundColor: colorPrimaryLight,
         valueColor: AlwaysStoppedAnimation<Color>(colorPrimaryDark),
       ),
     );
   },
 );
} 

标签: dartflutterflutter-layout

解决方案


好的,这很简单,我只需要设置

barrierDismissible: false,

推荐阅读