showAlert static method

void showAlert(
  1. BuildContext context, {
  2. String? title,
  3. String? content,
  4. Function? onConfirm,
})

Implementation

static void showAlert(BuildContext context,
    {String? title, String? content, Function? onConfirm}) {
  showDialog(
    context: context,
    builder: (BuildContext context) => AlertDialog(
      title: Text(
        '$title',
        style: TextStyle(fontSize: 22.0, color: Colors.black),
      ),
      titleTextStyle: TextStyle(fontStyle: FontStyle.normal),
      content: Text(
        '$content',
        style: TextStyle(fontSize: 14.0),
      ),
      actions: <Widget>[
        TextButton(
          child: Text('取消'),
          onPressed: () => Navigator.pop(context, 'Cancel'),
        ),
        TextButton(
          child: Text('确定'),
          onPressed: () => Navigator.pop(context, 'OK'),
        ),
      ],
    ),
  ).then<String>((returnVal) async {
    if (returnVal != null) {
      if (returnVal == 'OK') {
        if (onConfirm != null) onConfirm();
      }
    }
    return '';
  });
}