infoDialog static method

void infoDialog({
  1. required BuildContext context,
  2. required String title,
  3. required String message,
  4. String dismissButtonText = 'OK',
  5. VoidCallback? onPressed,
  6. double dismissButtonFontSize = 20,
  7. double titleFontSize = 25,
  8. Color? titleTextColor,
  9. Color? messageTextColor,
  10. Color dismissAndroidButtonColor = Colors.lightBlue,
})

The info dialog will only show a text, a message and a dismiss button

Implementation

static void infoDialog({
  required BuildContext context,
  required String title,
  required String message,
  String dismissButtonText = 'OK',
  VoidCallback? onPressed,

  /// you can change the dismiss button text
  double dismissButtonFontSize = 20,

  /// you can change the dismiss button font size too but only on android
  double titleFontSize = 25,

  /// You can change all the colors
  Color? titleTextColor,
  Color? messageTextColor,
  Color dismissAndroidButtonColor = Colors.lightBlue
}) {
  /// This is to show the iOS dialog type with Cupertino Widgets
  if (Platform.isIOS) {

    /// Cupertino dialogs
    showDialog(
      context: context,
      builder: (BuildContext context) {
        return CupertinoAlertDialog(
          title: Center(child: new Text(title)),
          content: new Text(message, style: TextStyle(color: titleTextColor),),
          actions: <Widget>[
            CupertinoDialogAction(
              child: Text(
                dismissButtonText,
                textAlign: TextAlign.justify,
                style: TextStyle(color: messageTextColor),
              ),
              onPressed: () {
                /// Does buttons are only to dismiss so the only function is the navigator that pops.
                Navigator.pop(context);
                if (onPressed != null) {
                  onPressed();
                }
              },
            )
          ],
        );
      },
    );
  } else {
    showDialog(
      context: context,
      builder: (BuildContext context) {
        // return object of type Dialog
        return AlertDialog(
          title: Center(
              child: new Text(
                title,
                style: TextStyle(
                    fontSize: titleFontSize,
                    fontWeight: FontWeight.bold,
                    color: titleTextColor == null ? Colors.grey.shade800 : titleTextColor),
              )),
          content: new Text(
            message,
            textAlign: TextAlign.justify,
            style: TextStyle(color: messageTextColor == null ? Colors.grey.shade800 : messageTextColor),
          ),
          actions: <Widget>[
            new TextButton(
              /// usually buttons at the bottom of the dialog
              child: new Text(
                dismissButtonText,
                style: TextStyle(fontSize: dismissButtonFontSize, color: dismissAndroidButtonColor),
              ),
              onPressed: () {
                Navigator.pop(context);
                /// Does buttons are only to dismiss so the only function is the navigator that pops.
                if (onPressed != null) {
                  onPressed();
                }
              },
            ),
          ],
        );
      },
    );
  }
}