showAlertDialog method

Future<bool?> showAlertDialog(
  1. BuildContext context, {
  2. String? title,
  3. Widget? content,
  4. String confirmButtonText = 'Ok',
  5. String? cancelButtonText,
})

Implementation

Future<bool?> showAlertDialog(BuildContext context,
    {String? title,
    Widget? content,
    String confirmButtonText = 'Ok',
    String? cancelButtonText}) {
  var titleWidget = title == null ? null : Text(title);
  var contentWidget = content == null ? null : content;

  var popupActions = <Widget>[];

  if (cancelButtonText != null) {
    popupActions.add(TextButton(
      child: Text(cancelButtonText),
      onPressed: () {
        Navigator.of(context).pop(false);
      },
    ));
  }

  popupActions.add(TextButton(
    child: Text(confirmButtonText),
    onPressed: () {
      Navigator.of(context).pop(true);
    },
  ));

  return showDialog<bool?>(
      context: context,
      barrierDismissible: false,
      builder: (_) => AlertDialog(
            actions: popupActions,
            title: titleWidget,
            content: contentWidget,
          ));
}