showCometChatConfirmDialog function

dynamic showCometChatConfirmDialog({
  1. required BuildContext context,
  2. Widget? title,
  3. Widget? messageText,
  4. String? confirmButtonText,
  5. String? cancelButtonText,
  6. dynamic onConfirm()?,
  7. dynamic onCancel()?,
  8. ConfirmDialogStyle style = const ConfirmDialogStyle(),
})

showCometChatConfirmDialog is a function that renders a alert dialog box

  showCometChatConfirmDialog(
     context: context,
     title: Text("some title"),
     messageText: Text("some message"),
     cancelButtonText: "cancel",
     confirmButtonText: "ok",
     onCancel: () {},
     onConfirm: () {},
     style: ConfirmDialogStyle()
     );

Implementation

showCometChatConfirmDialog(
    {required BuildContext context,
    Widget? title,
    Widget? messageText,
    String? confirmButtonText,
    String? cancelButtonText,
    Function()? onConfirm,
    Function()? onCancel,
    ConfirmDialogStyle style = const ConfirmDialogStyle()}) {
  showDialog(
    context: context,
    barrierColor: style.shadowColor ?? const Color(0xff000000).withOpacity(0.2),
    builder: (BuildContext context) {
      return AlertDialog(
        shape: const RoundedRectangleBorder(
            borderRadius: BorderRadius.all(Radius.circular(8.0))),
        backgroundColor: style.backgroundColor ?? const Color(0xffFFFFFF),
        elevation: 10,
        title: title,
        content: messageText,
        actions: [
          if (cancelButtonText != null)
            TextButton(
              onPressed: onCancel ??
                  () {
                    Navigator.of(context).pop();
                  },
              child: Text(
                cancelButtonText,
                style: style.cancelButtonTextStyle ??
                    const TextStyle(
                        fontSize: 14,
                        fontWeight: FontWeight.w500,
                        color: Color(0xff3399FF)),
              ),
            ),
          if (confirmButtonText != null)
            TextButton(
              onPressed: onConfirm ??
                  () {
                    Navigator.of(context).pop();
                  },
              child: Text(confirmButtonText,
                  style: style.confirmButtonTextStyle ??
                      const TextStyle(
                          fontSize: 14,
                          fontWeight: FontWeight.w500,
                          color: Color(0xff3399FF))),
            ),
        ],
      );
    },
  );
}