我有一个警报对话框,我希望在单击它外部时将其关闭,我知道这是颤振中警报对话框的默认行为,但我不知道是什么问题阻止它在外面单击时关闭。
我试图将障碍可解雇为真,但它仍然不起作用。
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);
在 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))
)
)
}
)
}
自定义警报方法
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);
}