buildSmartContainer function
Widget
buildSmartContainer({
- bool visible = true,
- BoxConstraints? constraints,
- bool userClip = false,
- AlignmentGeometry? alignment,
- GestureTapCallback? onTap,
- bool isCircle = false,
- double borderWidth = 0,
- Color backgroundColor = Colors.transparent,
- double radius = 0,
- Widget? child,
- EdgeInsets? padding = EdgeInsets.zero,
- Color borderColor = Colors.transparent,
- EdgeInsets? margin,
- BorderRadius? borderRadius,
- double? height,
- double? width,
- HitTestBehavior? behavior,
- Offset? offset,
- Color? boxColor,
- double blurRadius = 0,
- double spreadRadius = 0,
- List<
BoxShadow> ? boxShadow, - Widget replacement = const SizedBox.shrink(),
- bool maintainSize = false,
- bool maintainAnimation = false,
- bool maintainState = false,
胶囊控件
Implementation
Widget buildSmartContainer({
bool visible = true,
BoxConstraints? constraints,
bool userClip = false,
AlignmentGeometry? alignment,
GestureTapCallback? onTap,
bool isCircle = false,
double borderWidth = 0,
Color backgroundColor = Colors.transparent,
double radius = 0,
Widget? child,
EdgeInsets? padding = EdgeInsets.zero,
Color borderColor = Colors.transparent,
EdgeInsets? margin,
BorderRadius? borderRadius,
double? height,
double? width,
HitTestBehavior? behavior,
Offset? offset,
Color? boxColor,
double blurRadius = 0,
double spreadRadius = 0,
List<BoxShadow>? boxShadow,
Widget replacement = const SizedBox.shrink(),
bool maintainSize = false,
bool maintainAnimation = false,
bool maintainState = false
}){
///加判断防止过度渲染
Widget realChild;
BorderRadius mRadius = borderRadius ?? BorderRadius.all(Radius.circular(getRadius(radius)));
if(userClip){
realChild = Container(
child: ClipRRect(
borderRadius: mRadius,
child: Container(
constraints: constraints,
width: width,
height: height,
margin: margin,
padding: padding,
color: backgroundColor,
alignment: alignment,
child: child??Container(),
),
),
);
if(borderWidth > 0 || ObjectUtil.isNotEmpty(boxShadow)){
realChild = Container(
decoration: BoxDecoration(
borderRadius: mRadius,
border: borderWidth == 0? null : Border.all(color: borderColor, width: borderWidth),
boxShadow: boxShadow
),
child: realChild
);
}
}else{
realChild = 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 : mRadius,
border: borderWidth == 0? null : Border.all(color: borderColor, width: borderWidth),
boxShadow: boxShadow
),
child: child??Container(),
);
}
if(ObjectUtil.isNotEmpty(onTap)){
realChild = GestureDetector(
behavior: behavior,
onTap: onTap,
child: realChild
);
}
if(!visible){
realChild = Visibility(
visible: visible,
replacement: replacement,
maintainSize: maintainSize,
maintainState: maintainState,
maintainAnimation: maintainAnimation,
child: GestureDetector(
behavior: behavior,
onTap: onTap,
child: realChild
),
);
}
return realChild;
}