error static method

void error({
  1. String svgAssetDir = 'assets/images/ic_dialog_warning.svg',
  2. bool showAsset = true,
  3. String title = 'Failed',
  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 btnYesText = 'Close',
  13. Color? barrierColor = Colors.black54,
  14. double cornerRadius = 4.0,
  15. dynamic onYes()?,
  16. Widget? additional,
})

-- example implementation --

ExAlert.error(
  context: Get.context!,
  title: 'Failed :"))',
  message: 'Lorem Ipsum is simply dummy text of the printing and typesetting industry',
  onYes: () => print('clicked'),
);

Implementation

static void error({
  String svgAssetDir = 'assets/images/ic_dialog_warning.svg',
  bool showAsset = true,
  String title = 'Failed',
  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 btnYesText = 'Close',
  Color? barrierColor = Colors.black54,
  double cornerRadius = 4.0,
  Function()? onYes,
  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: [
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                ElevatedButton(
                  style: ElevatedButton.styleFrom(backgroundColor: Theme.of(context).colorScheme.error),
                  onPressed: onYes ?? () => Get.back(),
                  child: Text(btnYesText),
                ).pOnly(left: 12, right: 12, bottom: 12).h(55).expand(),
              ],
            ),
          ],
        ),
      );
    },
  );
}