background method

Widget background({
  1. Color? color,
  2. String? bgImage,
  3. BoxFit? fitBgImage,
  4. BoxShape shape = BoxShape.rectangle,
  5. double? radius,
  6. double? border,
  7. Color? borderColor,
  8. double? borderLeft,
  9. double? borderTop,
  10. double? borderRight,
  11. double? borderBottom,
  12. double? topLeft,
  13. double? topRight,
  14. double? bottomLeft,
  15. double? bottomRight,
  16. double? width,
  17. double? height,
  18. double? maxWidth,
  19. double? maxHeight,
  20. double? minWidth,
  21. double? minHeight,
  22. BoxDecoration? decoration,
  23. Alignment? alignment,
})

Implementation

Widget background({
  Color? color,
  String? bgImage,
  BoxFit? fitBgImage,
  BoxShape shape = BoxShape.rectangle,
  double? radius,
  double? border,
  Color? borderColor,
  double? borderLeft,
  double? borderTop,
  double? borderRight,
  double? borderBottom,
  double? topLeft,
  double? topRight,
  double? bottomLeft,
  double? bottomRight,
  double? width,
  double? height,
  double? maxWidth,
  double? maxHeight,
  double? minWidth,
  double? minHeight,
  BoxDecoration? decoration,
  Alignment? alignment,
}) {
  bool allBorderRadiusNull = topLeft == null &&
      topRight == null &&
      bottomLeft == null &&
      bottomRight == null;
  bool allBorderNull = borderLeft == null &&
      borderTop == null &&
      borderRight == null &&
      borderBottom == null;

  return ClipRRect(
      // borderRadius: BorderRadius.all(Radius.circular(0)),
      borderRadius: !allBorderRadiusNull && borderColor==null ? BorderRadius.only(
                  topLeft: Radius.circular(topLeft ?? 0),
                  topRight: Radius.circular(topRight ?? 0),
                  bottomLeft: Radius.circular(bottomLeft ?? 0),
                  bottomRight: Radius.circular(bottomRight ?? 0),
                )
              : BorderRadius.all(Radius.circular(0)),
      child: Container(
        width: width,
        height: height,
        child: this,
        constraints: (maxWidth != null ||
                maxHeight != null ||
                minWidth != null ||
                minHeight != null)
            ? BoxConstraints(
                maxWidth: maxWidth ?? double.infinity,
                maxHeight: maxHeight ?? double.infinity,
                minWidth: minWidth ?? 0.0,
                minHeight: minHeight ?? 0.0,
              )
            : null,
        alignment: alignment,
        decoration: decoration != null
            ? decoration
            : BoxDecoration(
                color: color,
                shape: shape,
                image: bgImage == null
                    ? null
                    : DecorationImage(
                        image: bgImage.contains('http')
                            ? NetworkImage(bgImage)
                            : AssetImage(bgImage) as ImageProvider<Object>,
                        fit: fitBgImage ?? BoxFit.contain,
                      ),
                border: !allBorderNull
                    ? Border(
                        left: borderLeft == null
                            ? BorderSide.none
                            : BorderSide(
                                color: borderColor ?? themeColor.ffDEDFDE!,
                                width: borderLeft,
                              ),
                        top: borderTop == null
                            ? BorderSide.none
                            : BorderSide(
                                color: borderColor ?? themeColor.ffDEDFDE!,
                                width: borderTop,
                              ),
                        right: borderRight == null
                            ? BorderSide.none
                            : BorderSide(
                                color: borderColor ?? themeColor.ffDEDFDE!,
                                width: borderRight,
                              ),
                        bottom: borderBottom == null
                            ? BorderSide.none
                            : BorderSide(
                                color: borderColor ?? themeColor.ffDEDFDE!,
                                width: borderBottom,
                              ),
                      )
                    : border == null
                        ? null
                        : Border.all(
                            width: border,
                            color: borderColor ?? themeColor.ffDEDFDE!),
                borderRadius: !allBorderNull
                    ? null
                    : allBorderRadiusNull
                        ? BorderRadius.all(Radius.circular(radius ?? 0))
                        : BorderRadius.only(
                            topLeft: Radius.circular(topLeft ?? 0),
                            topRight: Radius.circular(topRight ?? 0),
                            bottomLeft: Radius.circular(bottomLeft ?? 0),
                            bottomRight: Radius.circular(bottomRight ?? 0),
                          ),
              ),
      ));
}