showPumaAlert function

dynamic showPumaAlert(
  1. BuildContext context, {
  2. String title = "",
  3. String message = "",
  4. String yes = "OK",
  5. String? no,
  6. void onYes()?,
  7. void onNo()?,
  8. Color? yesColor,
  9. Color? noColor,
  10. bool delayYesAction = false,
  11. int delayActionSecond = 5,
})

Implementation

showPumaAlert(
  BuildContext context, {
  String title = "",
  String message = "",
  String yes = "OK",
  String? no,
  void Function()? onYes,
  void Function()? onNo,
  Color? yesColor,
  Color? noColor,
  bool delayYesAction = false,
  int delayActionSecond = 5,
}) {
  var alert;
  Color _yesColor = yesColor ?? Theme.of(context).colorScheme.primary;
  Color _noColor = noColor ?? Theme.of(context).colorScheme.error;

  if (Platform.isIOS) {
    alert = CupertinoAlertDialog(
      title: new Text(title),
      content: new Text(message),
      actions: [
        if (no != null)
          PumaCupertinoButton(
            text: no,
            color: _noColor,
            onPressed: onNo == null ? () => Navigator.of(context).pop() : onNo,
          ),
        PumaCupertinoButton(
          text: yes,
          color: _yesColor,
          onPressed: onYes!,
          delayAction: delayYesAction ? delayActionSecond : 0,
        )
      ],
    );
  } else {
    alert = AlertDialog(
      title: Text(title),
      content: Text(message),
      actions: [
        if (no != null)
          PumaMaterialButton(
            text: no,
            color: _noColor,
            onPressed: onNo == null ? () => Navigator.of(context).pop() : onNo,
            context: context,
          ),
        PumaMaterialButton(
          text: yes,
          color: _yesColor,
          onPressed: onYes!,
          delayAction: delayYesAction ? delayActionSecond : 0,
          context: context,
        ),
      ],
    );
  }

  showDialog(
    context: context,
    builder: (BuildContext context) {
      return alert;
    },
  );
}