smartDialog function

Future smartDialog({
  1. required Widget child,
  2. String title = "",
  3. String hideText = "Hide",
  4. bool noAction = false,
  5. bool zeroPadding = false,
  6. bool barrierDismissible = true,
  7. TextStyle? titleStyle,
  8. TextStyle? hideTextStyle,
  9. Color? bgColor,
  10. required BuildContext context,
})

Implementation

Future<dynamic> smartDialog(
    {required Widget child,
    String title = "",
    String hideText = "Hide",
    bool noAction = false,
    bool zeroPadding = false,
    bool barrierDismissible = true,
    TextStyle? titleStyle,
    TextStyle? hideTextStyle,
    Color? bgColor,
    required BuildContext context}) {
  return showDialog(
      context: context,
      barrierDismissible: barrierDismissible, // user must tap button!
      builder: (BuildContext context) {
        Widget? titleWidget = title != ""
            ? Text(
                title,
                style: titleStyle ??
                    Get.find<AppFonts>().L(
                        isBold: true,
                        color: Get.find<AppColors>().dialogTextColor),
              )
            : null;
        List<Widget>? actions;
        if (noAction == false) {
          actions = [
            TextButton(
              child: Text(hideText,
                  style: hideTextStyle ??
                      Get.find<AppFonts>()
                          .M(color: Get.find<AppColors>().dialogHintColor)),
              onPressed: () {
                Navigator.of(context).pop();
              },
            )
          ];
        }
        return StatefulBuilder(builder: (context, StateSetter setState) {
          return AlertDialog(
            contentPadding: zeroPadding
                ? EdgeInsets.zero
                : const EdgeInsets.fromLTRB(24.0, 20.0, 24.0, 24.0),
            title: titleWidget,
            backgroundColor:
                bgColor ?? Get.find<AppColors>().dialogBackgroundColor,
            content: SingleChildScrollView(
              child: ListBody(children: <Widget>[child]),
            ),
            actions: actions,
          );
        });
      });
}