buildSmartContainer function

Widget buildSmartContainer(
  1. {bool visible = true,
  2. BoxConstraints constraints,
  3. bool userClip = false,
  4. AlignmentGeometry alignment,
  5. GestureTapCallback onTap,
  6. bool isCircle = false,
  7. double borderWidth = 0,
  8. Color backgroundColor = Colors.white,
  9. double radius = 0,
  10. Widget child,
  11. EdgeInsets padding,
  12. Color borderColor = Colors.white,
  13. EdgeInsets margin,
  14. BorderRadiusGeometry borderRadius,
  15. double height,
  16. double width,
  17. HitTestBehavior behavior}
)

胶囊控件

Implementation

Widget buildSmartContainer({
  bool visible = true,
  BoxConstraints constraints,
  bool userClip = false,
  AlignmentGeometry alignment,
  GestureTapCallback onTap,
  bool isCircle = false,
  double borderWidth = 0,
  Color backgroundColor = Colors.white,
  double radius = 0,
  Widget child,
  EdgeInsets padding,
  Color borderColor = Colors.white,
  EdgeInsets margin,
  BorderRadiusGeometry borderRadius,
  double height,
  double width,
  HitTestBehavior behavior
}){
  return Visibility(
    visible: visible,
    child: GestureDetector(
        behavior: behavior,
        onTap: onTap,
        child: userClip? ClipRRect(
          borderRadius: borderRadius??BorderRadius.all(Radius.circular(radius)),
          child: Container(
            constraints: constraints,
            color: backgroundColor,
            width: width,
            height: height,
            margin: margin,
            padding: padding,
            alignment: alignment,
            child: child??Container(),
          ),
        ): Container(
          constraints: constraints,
          width: width,
          height: height,
          margin: margin,
          padding: padding,
          alignment: alignment,
          decoration: BoxDecoration(
              shape: isCircle? BoxShape.circle : BoxShape.rectangle,
              color: backgroundColor,
              borderRadius: isCircle? null : borderRadius??BorderRadius.all(Radius.circular(radius)),
              border: borderWidth == 0? null : Border.all(color: borderColor, width: borderWidth)
          ),
          child: child??Container(),
        )
    ),
  );
}