show static method

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

Implementation

static Future<void> show({
  required BuildContext context,
  bool disableBackBtn = false,
  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,
}) async {
  await showGeneralDialog(
    context: context,
    barrierDismissible: false,
    barrierColor: Colors.black26,
    pageBuilder: (context, animation, secondaryAnimation) {
      return PopScope(
        canPop: !disableBackBtn,
        child: Scaffold(
          backgroundColor: Colors.transparent,
          resizeToAvoidBottomInset: resizeToAvoidBottomInset,
          body: Center(
            child: SingleChildScrollView(
              padding: const EdgeInsets.symmetric(vertical: 20),
              child: Container(
                width: 300,
                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,
      );
    },
  );
}