Flutter 半径可能等于null时的问题

Flutter 半径可能等于null时的问题,flutter,dart,Flutter,Dart,嗨,我正在为我的应用程序布局构建一个小部件。我对半径有问题,因为当小部件在另一个文件中时,我没有调用控制半径的参数,卡就会消失。我插入了控制半径是否为空的函数,但是如果值为空,卡会一直消失 代码如下: class ContainerCard extends StatelessWidget { ContainerCard({ this.child, this.backgroundColor, thi

嗨,我正在为我的应用程序布局构建一个小部件。我对半径有问题,因为当小部件在另一个文件中时,我没有调用控制半径的参数,卡就会消失。我插入了控制半径是否为空的函数,但是如果值为空,卡会一直消失

代码如下:

    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);
          }
 }

在构造函数中,可以将默认值设置为边界半径,如下所示

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,
          });

谢谢你,这很有效!