首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >radius的问题当它可能等于null时

radius的问题当它可能等于null时
EN

Stack Overflow用户
提问于 2021-04-25 18:19:29
回答 1查看 18关注 0票数 0

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

代码如下:

代码语言:javascript
运行
复制
    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);
          }
 }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-04-25 18:26:34

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

代码语言:javascript
运行
复制
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,
          });
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67252254

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档