showAlertDialog static method

dynamic showAlertDialog(
  1. BuildContext context,
  2. String title,
  3. String message,
  4. String okText,
  5. String cancelText, {
  6. dynamic onOkPressed,
  7. dynamic onCancelPressed,
  8. dynamic okCloseDialog = true,
})

显示弹出框

Implementation

static showAlertDialog(BuildContext context, String title, String message, String okText, String cancelText,
    {onOkPressed, onCancelPressed, okCloseDialog = true}) {
  showDialog<Null>(
    context: context,
    barrierDismissible: false,
    builder: (BuildContext context) {
      return AlertDialog(
        title: Text(title),
        content: SingleChildScrollView(
          child: ListBody(
            children: <Widget>[
              Text(message),
            ],
          ),
        ),
        actions: <Widget>[
          TextButton(
            child: Text(cancelText),
            onPressed: () {
              if (null != onCancelPressed) {
                onCancelPressed();
              }
              Navigator.of(context).pop();
            },
          ),
          TextButton(
            child: Text(okText),
            onPressed: () {
              if (null != onOkPressed) {
                onOkPressed();
              }
              if (null != okCloseDialog && okCloseDialog) {
                Navigator.of(context).pop();
              }
            },
          ),
        ],
      );
    },
  ).then((val) {
    print(val);
  });
}