confirm static method

void confirm({
  1. String svgAssetDir = 'assets/images/ic_dialog_warning.svg',
  2. bool showAsset = true,
  3. String title = '',
  4. double titleTextSize = 18,
  5. TextAlign titleTextAlign = TextAlign.left,
  6. Color titleTextColor = Colors.black,
  7. String message = '',
  8. double messageTextSize = 14,
  9. TextAlign messageTextAlign = TextAlign.left,
  10. Color messageTextColor = const Color(0xff596066),
  11. bool isDismissible = false,
  12. String btnNoText = 'No',
  13. dynamic onNo()?,
  14. String btnYesText = 'Yes',
  15. dynamic onYes()?,
  16. bool isWarningMode = false,
  17. Color? barrierColor = Colors.black54,
  18. double cornerRadius = 4.0,
  19. Widget? additional,
})

-- example implementation --

ExAlert.confirm(
  context: Get.context!,
  title: 'Some Question',
  message: 'Lorem Ipsum is simply dummy text of the printing and typesetting industry?',
  onYes: () => print('yes clicked'),
  onNo: () => print('no clicked'),
);

Implementation

static void confirm({
  String svgAssetDir = 'assets/images/ic_dialog_warning.svg',
  bool showAsset = true,
  String title = '',
  double titleTextSize = 18,
  TextAlign titleTextAlign = TextAlign.left,
  Color titleTextColor = Colors.black,
  String message = '',
  double messageTextSize = 14,
  TextAlign messageTextAlign = TextAlign.left,
  Color messageTextColor = const Color(0xff596066),
  bool isDismissible = false,
  String btnNoText = 'No',
  Function()? onNo,
  String btnYesText = 'Yes',
  Function()? onYes,
  bool isWarningMode = false,
  Color? barrierColor = Colors.black54,
  double cornerRadius = 4.0,
  Widget? additional,
}) {
  showDialog(
    context: Get.context!,
    barrierDismissible: isDismissible,
    barrierColor: barrierColor,
    builder: (context) {
      return WillPopScope(
        onWillPop: () async => isDismissible,
        child: AlertDialog(
          shape: RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(cornerRadius))),
          // contentPadding: EdgeInsets.all(16),
          scrollable: true,
          content: VStack([
            if (showAsset)
              VStack([
                if (svgAssetDir.isNotBlank)
                  SvgPicture.asset(svgAssetDir, width: 90, height: 90).centered()
                else
                  SvgPicture.asset(svgAssetDir, package: 'gredu_common', width: 90, height: 90).centered(),
                24.heightBox,
              ]),
            Text(
              title,
              style: TextStyle(fontSize: titleTextSize, fontWeight: FontWeight.bold, color: titleTextColor),
              textAlign: titleTextAlign,
              maxLines: 2,
            ).w(double.infinity),
            12.heightBox,
            Text(
              message,
              style: TextStyle(fontSize: messageTextSize, fontWeight: FontWeight.normal, color: messageTextColor, height: 1.5),
              textAlign: messageTextAlign,
            ).w(double.infinity),
            additional ?? 0.heightBox,
          ]),
          actions: [
            Column(
              children: [
                SizedBox(
                  width: double.infinity,
                  height: 44,
                  child: ElevatedButton(
                    style: ElevatedButton.styleFrom(backgroundColor: isWarningMode == true ? Theme.of(context).colorScheme.error : Theme.of(context).primaryColor),
                    onPressed: onYes ?? () => Get.back(),
                    child: Text(btnYesText),
                  ),
                ),
                12.heightBox,
                SizedBox(
                  width: double.infinity,
                  height: 44,
                  child: OutlinedButton(
                    style: OutlinedButton.styleFrom(
                      foregroundColor: isWarningMode == true ? Theme.of(context).colorScheme.error : Colors.black,
                      side: BorderSide(color: Color(0xff9EA9AD)),
                    ),
                    onPressed: onNo ?? () => Get.back(),
                    child: Text(btnNoText),
                  ),
                ),
                12.heightBox,
              ],
            ).pOnly(left: 12, right: 12),
          ],
        ),
      );
    },
  );
}