您好,我正在为我的应用程序布局构建一个小部件。我对半径有问题,因为当小部件在另一个文件中,而我没有调用控制半径的参数时,卡就消失了。我已经插入了一个函数,如果半径为空,则控制,但如果值为空,则卡一直消失。
代码如下:
class ContainerCard extends StatelessWidget {
ContainerCard({
this.child,
this.backgroundColor,
this.alignment,
this.height,
this.width,
this.topLeft,
this.topRight,
this.bottomLeft,
this.bottomRight,
});
final Widget child;
final Color backgroundColor;
final Alignment alignment;
final double height, width, topLeft, topRight, bottomLeft, bottomRight;
@override
Widget build(BuildContext context) {
return Align(
alignment: alignment == null ? Alignment.center : alignment,
child: Container(
height: height,
width: width,
decoration: BoxDecoration(
color: backgroundColor == null ? Colors.white : backgroundColor,
borderRadius: BorderRadius.only(
topLeft: setRadius(topLeft),
topRight: setRadius(topRight),
bottomLeft: setRadius(bottomLeft),
bottomRight: setRadius(bottomRight),
),
),
child: child,
),
);
}
Radius setRadius(double radius) {
return Radius.circular(radius) == null
? Radius.circular(0)
: Radius.circular(radius);
}
}
发布于 2021-04-25 18:26:34
在构造函数中,您可以将默认值设置为边界半径,如下所示
class ContainerCard extends StatelessWidget {
ContainerCard({
this.child,
this.backgroundColor,
this.alignment,
this.height,
this.width,
this.topLeft = 0,
this.topRight = 0,
this.bottomLeft = 0,
this.bottomRight = 0,
});
https://stackoverflow.com/questions/67252254
复制相似问题