showAlert static method

Future showAlert(
  1. String? title,
  2. String? text,
  3. BuildContext context, {
  4. dynamic onPressed,
  5. dynamic barrierDismissible,
  6. required String okText,
})

Implementation

static Future showAlert(String? title, String? text, BuildContext context,
    {onPressed, barrierDismissible, required String okText}) {
  if (kIsWeb) {
    return showDialog(
      context: context,
      barrierDismissible: barrierDismissible ?? true,
      builder: (BuildContext context) {
        return AlertDialog(
          title:
              Text(title!, style: Theme.of(context).textTheme.displayMedium),
          content: SingleChildScrollView(
            child: ListBody(
              children: <Widget>[
                Text(
                  text!,
                  style: Theme.of(context).textTheme.bodyMedium,
                ),
              ],
            ),
          ),
          actions: <Widget>[
            TextButton(
              child: Text(
                okText,
                style: Theme.of(context).textTheme.displaySmall,
              ),
              onPressed: () {
                if (onPressed != null) {
                  onPressed();
                } else {
                  Navigator.of(context).pop();
                }
              },
            ),
          ],
        );
      },
    );
  } else {
    if (Platform.isAndroid) {
      return showDialog(
        context: context,
        barrierDismissible: barrierDismissible ?? true,
        builder: (BuildContext context) {
          return AlertDialog(
            shape: RoundedRectangleBorder(
                borderRadius:
                    BorderRadius.circular(DUI.spacing.borderRadius)),
            titlePadding: EdgeInsets.only(
                top: 2 * DUI.spacing.lateralPaddingValue,
                bottom: DUI.spacing.lateralPaddingValue / 2,
                left: DUI.spacing.lateralPaddingValue,
                right: DUI.spacing.lateralPaddingValue),
            contentPadding: EdgeInsets.symmetric(
                vertical: 0, horizontal: DUI.spacing.lateralPaddingValue),
            actionsPadding: EdgeInsets.symmetric(
                vertical: 0, horizontal: DUI.spacing.lateralPaddingValue),
            surfaceTintColor: Theme.of(context).colorScheme.background,
            title: DUI.text.title3(context, title!),
            content: DUI.text.regular(context, text!),
            actions: <Widget>[
              TextButton(
                child: DUI.text.regular(context, okText,
                    bold: true, color: Colors.blueAccent),
                onPressed: () {
                  if (onPressed != null) {
                    onPressed();
                  } else {
                    Navigator.of(context).pop();
                  }
                },
              ),
            ],
          );
        },
      );
    } else {
      return showDialog(
        barrierDismissible: barrierDismissible ?? true,
        context: context,
        builder: (BuildContext context) {
          return CupertinoAlertDialog(
            title: Text(
              title!,
            ),
            content: Column(
              children: <Widget>[
                DUI.spacing.spacer(small: true),
                Text(
                  text!,
                  style: const TextStyle(height: 1.2),
                )
              ],
            ),
            actions: <Widget>[
              CupertinoDialogAction(
                isDefaultAction: true,
                child: Text(
                  okText,
                  style: TextStyle(color: Colors.blueAccent),
                ),
                onPressed: () {
                  if (onPressed != null) {
                    onPressed();
                  } else {
                    Navigator.of(context).pop();
                  }
                },
              ),
            ],
          );
        },
      );
    }
  }
}