showAlertDialog method

bool showAlertDialog(
  1. BuildContext context,
  2. String title,
  3. String content,
  4. String buttonText
)

Show an alert dialog with a title and content.

The context parameter is a required BuildContext for displaying the dialog. The title parameter is the title of the alert dialog. The content parameter is the content of the alert dialog.

Implementation

bool showAlertDialog(
    BuildContext context, String title, String content, String buttonText) {
  showDialog(
    context: context,
    builder: (BuildContext context) {
      return AlertDialog(
        title: Text(title),
        content: Text(content),
        actions: <Widget>[
          TextButton(
            child: Text(
              buttonText,
              style: TextStyle(
                  color: Theme.of(context).dialogTheme.titleTextStyle?.color),
            ),
            onPressed: () => Navigator.of(context).pop(),
          ),
        ],
      );
    },
  );
  return true;
}