show static method

Future<void> show({
  1. required BuildContext context,
  2. bool disableBackBtn = false,
  3. double width = 300.0,
  4. bool? resizeToAvoidBottomInset,
  5. CustomAlertImage image = const CustomAlertImage(),
  6. Text? title,
  7. double titleOffset = 10,
  8. Widget? content,
  9. double contentOffset = 10,
  10. CrossAxisAlignment alignment = CrossAxisAlignment.start,
  11. CustomAlertActions? actionWidget,
  12. MainAxisAlignment actionAlignment = MainAxisAlignment.end,
  13. bool showCancelBtn = false,
  14. String cancelBtnText = 'Cancel',
  15. String confirmBtnText = 'Ok',
  16. Color confirmBtnColor = Colors.blue,
  17. Color confirmBtnTextColor = Colors.white,
  18. double borderRadius = 12,
  19. void onCancelBtnTap()?,
  20. void onConfirmBtnTap()?,
  21. Curve curve = Curves.elasticOut,
  22. Curve reverseCurve = Curves.easeOutExpo,
  23. bool barrierDismissible = false,
})

Implementation

static Future<void> show({
  required BuildContext context,
  bool disableBackBtn = false,
  double width = 300.0,
  bool? resizeToAvoidBottomInset,
  CustomAlertImage image = const CustomAlertImage(),
  Text? title,
  double titleOffset = 10,
  Widget? content,
  double contentOffset = 10,
  CrossAxisAlignment alignment = CrossAxisAlignment.start,
  CustomAlertActions? actionWidget,
  MainAxisAlignment actionAlignment = MainAxisAlignment.end,
  bool showCancelBtn = false,
  String cancelBtnText = 'Cancel',
  String confirmBtnText = 'Ok',
  Color confirmBtnColor = Colors.blue,
  Color confirmBtnTextColor = Colors.white,
  double borderRadius = 12,
  void Function()? onCancelBtnTap,
  void Function()? onConfirmBtnTap,
  Curve curve = Curves.elasticOut,
  Curve reverseCurve = Curves.easeOutExpo,
  bool barrierDismissible = false
}) async {
  await showGeneralDialog(
    context: context,
    barrierColor: Colors.black26,
    pageBuilder: (context, animation, secondaryAnimation) {
      return PopScope(
        canPop: !disableBackBtn,
        child: Scaffold(
          backgroundColor: Colors.transparent,
          resizeToAvoidBottomInset: resizeToAvoidBottomInset,
          body: GestureDetector(
            onTap: barrierDismissible? () {
              Navigator.pop(context);
            } : null,
            child: Container(
              color: Colors.transparent,
              alignment: Alignment.center,
              child: GestureDetector(
                onTap: () {},
                child: SingleChildScrollView(
                  padding: const EdgeInsets.symmetric(vertical: 20),
                  child: Container(
                    width: width,
                    decoration: BoxDecoration(
                      color: Colors.white,
                      borderRadius: BorderRadius.circular(borderRadius),
                    ),
                    child: Column(
                      mainAxisSize: MainAxisSize.min,
                      children: [
                        image._build(borderRadius),
                        Padding(
                          padding: const EdgeInsets.symmetric(
                            horizontal: 20,
                            vertical: 20,
                          ),
                          child: Column(
                            crossAxisAlignment: alignment,
                            children: [
                              Padding(
                                padding: EdgeInsets.only(
                                  top: title == null ? 0 : titleOffset,
                                ),
                                child:
                                    title ??
                                    SizedBox(
                                      child: content == null
                                          ? Text(
                                              'Title',
                                              style: TextStyle(
                                                fontSize: 18,
                                                fontWeight: FontWeight.bold,
                                              ),
                                            )
                                          : const SizedBox(),
                                    ),
                              ),

                              SizedBox(
                                height: (title == null && content== null) || (title != null && content != null) ? contentOffset : 0,
                              ),

                              Padding(
                                padding: EdgeInsets.only(
                                  bottom:
                                      content is Text ||
                                          (title == null && content == null)
                                      ? 20
                                      : 0,
                                ),
                                child:
                                    content ??
                                    SizedBox(
                                      child: title == null
                                          ? Text('alert content')
                                          : null,
                                    ),
                              ),

                              actionWidget ??
                                  CustomAlertActions(
                                    alignment: actionAlignment,
                                    actions: [
                                      showCancelBtn
                                          ? TextButton(
                                              style: TextButton.styleFrom(
                                                foregroundColor: Colors.grey,
                                              ),
                                              onPressed:
                                                  onCancelBtnTap ??
                                                  () {
                                                    Navigator.of(context).pop();
                                                  },
                                              child: Text(cancelBtnText),
                                            )
                                          : const SizedBox(),

                                      ElevatedButton(
                                        style: ElevatedButton.styleFrom(
                                          backgroundColor: confirmBtnColor,
                                          foregroundColor: confirmBtnTextColor,
                                        ),
                                        onPressed:
                                            onConfirmBtnTap ??
                                            () {
                                              Navigator.of(context).pop();
                                            },
                                        child: Text(confirmBtnText),
                                      ),
                                    ],
                                  ),
                            ],
                          ),
                        ),
                      ],
                    ),
                  ),
                ),
              ),
            ),
          ),
        ),
      );
    },
    transitionBuilder: (context, animation, secondaryAnimation, child) {
      // Add scaling effect
      return ScaleTransition(
        scale: CurvedAnimation(
          parent: animation,
          curve: curve,
          reverseCurve: reverseCurve,
        ),
        child: child,
      );
    },
  );
}