1

我有一个警报对话框,我想在外部单击时将其关闭,我知道这是颤动中警报对话框的默认行为,但我不知道在外部单击时阻止它关闭的问题是什么。

我尝试将 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);
4

2 回答 2

0

在 onPressed 或 onTap 上调用它:

void showMessage(){
  showDialog(
    context:context,
    builder: (Buildcontext context){
       return AlertDialog(
         backgroundColor: Colors.transparent,
         content: Container(
            width: MediaQuery.of(context).size.width,
            height: 100,
            alignment: AlignmentDirectional.center
            child: Text("TRIAL",style: TextStyle(color: Colors.white))
        )
      )
    }
  )
}
于 2019-10-08T09:08:58.950 回答
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);
  }
于 2020-04-28T13:05:14.447 回答