在其外部单击时如何关闭警报对话框

时间:2019-10-07 09:39:25

标签: flutter dialog android-alertdialog flutter-layout flutter-alertdialog

我有一个警报对话框,我想在其外部单击时将其关闭,我知道这是抖动对话框中默认的行为,但是我不知道是什么原因阻止了其在外部单击时无法关闭

我尝试将barrierDismissable设置为true,但仍然无法正常工作。

This is my dialog : 

termsAndConditionsDialog(BuildContext context) {

    AlertDialog alert = AlertDialog(
      title:  Text("Terms and Conditions", style: TextStyle(fontSize: 18, color: AppColors.accentColor),),
      content: Text(
        generalSettings.policyForCustomer,
        style: TextStyle(fontSize: 16),
      ),

    );


    // show the dialog
    showDialog(
      barrierDismissible: true,
      context: context,
      builder: (BuildContext context) {
        return alert;
      },
    );
  }


and this is how I call it from button's onPressed : 
 termsAndConditionsDialog(context);

2 个答案:

答案 0 :(得分:0)

在onPressed或onTap上调用它:

pip install factor-analyzer

答案 1 :(得分:0)

自定义提醒方法

typedef ResponseCallbackValueLess = void Function();

showAlertDialogWithOkButton(
  BuildContext context,
  String message,
  String heading,
  String buttonAcceptTitle,
  ResponseCallbackValueLess callback) {
Widget continueButton = FlatButton(
  child: Text(buttonAcceptTitle),
  onPressed: () {
    callback();
  },
);

如下所示:

showAlertDialogWithOkButton(context,
                          'No items found in your cart.',
                          "app name", "Ok", dismissAlert(context));

dismissAlert(context){
    Navigator.pop(context);
  }