confirmAction function

void confirmAction(
  1. BuildContext context, {
  2. dynamic onConfirm()?,
  3. String? message,
  4. String? confirm,
  5. ElevatedButton? actionButtonStyle,
  6. ButtonStyle? confirmButtonStyle,
  7. ButtonStyle? closeButtonStyle,
  8. dynamic onClose()?,
  9. String? close,
  10. Key? confirmKey,
  11. bool? useRedColor,
  12. String? title,
})

Implementation

void confirmAction(
  BuildContext context, {
  Function()? onConfirm,
  String? message,
  String? confirm,
  ElevatedButton? actionButtonStyle,
  ButtonStyle? confirmButtonStyle,
  ButtonStyle? closeButtonStyle,
  Function()? onClose,
  String? close,
  Key? confirmKey,
  bool? useRedColor,
  String? title,
}) {
  showDialog(
    context: context,
    builder: (context) => AlertDialog(
      title: Text(title ?? "Are you sure you can to continue"),
      content: message == null ? null : Text(message),
      actions: [
        Container(
          width: width(context),
          padding: const EdgeInsets.all(10),
          child: actionButtonStyle ??
              ElevatedButton(
                key: confirmKey ?? const Key("yes"),
                style: confirmButtonStyle ??
                    ElevatedButton.styleFrom(primary: Colors.red),
                onPressed: () {
                  pop(context);
                  onConfirm!();
                },
                child: Text(confirm ?? "Yes"),
              ),
        ),
        Container(
          width: width(context),
          padding: const EdgeInsets.all(10),
          child: ElevatedButton(
            key: const Key("no"),
            onPressed: () {
              if (onClose != null) {
                onClose();
              }
              pop(context);
            },
            child: Text(close ?? "No"),
          ),
        ),
      ],
    ),
  );
}