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,
  13. Widget? closeWidget,
  14. Widget? confirmWidget,
  15. Widget? messageWidget,
  16. Widget? titleWidget,
})

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,
  Widget? closeWidget,
  Widget? confirmWidget,
  Widget? messageWidget,
  Widget? titleWidget,
}) {
  showDialog(
    context: context,
    builder: (context) => AlertDialog(
      title: titleWidget != null
          ? titleWidget
          : Text(title ?? "Are you sure you can to continue"),
      content: messageWidget != null
          ? messageWidget
          : message == null
              ? null
              : Text(message),
      actions: [
        if (confirmWidget != null)
          confirmWidget
        else
          Container(
            width: width(context),
            padding: const EdgeInsets.all(10),
            child: actionButtonStyle ??
                ElevatedButton(
                  key: confirmKey ?? const Key("yes"),
                  style: confirmButtonStyle ??
                      ElevatedButton.styleFrom(backgroundColor: Colors.red),
                  onPressed: () {
                    pop(context);
                    onConfirm!();
                  },
                  child: Text(confirm ?? "Yes"),
                ),
          ),
        if (closeWidget != null)
          closeWidget
        else
          Container(
            width: width(context),
            padding: const EdgeInsets.all(10),
            child: ElevatedButton(
              key: const Key("no"),
              style: closeButtonStyle,
              onPressed: () {
                if (onClose != null) {
                  onClose();
                }
                pop(context);
              },
              child: Text(close ?? "No"),
            ),
          ),
      ],
    ),
  );
}