简体   繁体   English

底部溢出 x 个像素

[英]Bottom overflowed by x pixels

I have one column widget in which basically I want to show 2 children widgets first is some dynamic text and another is some container whose height should clip automatically or should automatically takes the remaining height of ConstrainedBox.我有一个列小部件,基本上我想在其中显示 2 个子小部件,首先是一些动态文本,另一个是一些容器,其高度应自动剪切或应自动采用 ConstrainedBox 的剩余高度。

I have tried below approach but bottom overflowed by x pixels error is coming.我尝试了以下方法,但底部溢出 x 像素错误即将到来。

Please suggest some approach.请提出一些方法。

ConstrainedBox(
        constraints: BoxConstraints(
            maxWidth: width, maxHeight:height),
        child: Column(
          children: [
            SizedBox(
              child: Text(
                name,
                maxLines: 2,
                textAlign: TextAlign.center,
                style: TextStyle(
                    color: Colors.black,
                    fontSize: fontSize,
                    fontWeight: FontWeight.bold),
              ),
            ),
              Container(
                  width: Constants.lineThickness,
                  height: 20, // **should automatically takes the remaining height of ConstrainedBox**
                  color: color)
          ],
        )
       );

Use Expanded Widget.使用Expanded小部件。

Sample Code:示例代码:

       Column(
          children: [
            SizedBox(
              child: Text(
                name,
                maxLines: 2,
                textAlign: TextAlign.center,
                style: TextStyle(
                    color: Colors.black,
                    fontSize: fontSize,
                    fontWeight: FontWeight.bold),
              ),
            ),
              Expanded(
                child: Center(
                    child: Text(
                        'It will take the availabe space in column'
                    )
                )
              )
          ],
        )

You can either increase the height in the BoxConstraints or use a SingleChildScrollView to enable scroll:您可以增加 BoxConstraints 中的高度或使用 SingleChildScrollView 来启用滚动:

        constraints: BoxConstraints(
          maxWidth: width, 
          maxHeight:height,
        ),
        child: SingleChildScrollView(
          child:Column(
            children: [
              SizedBox(
                child: Text(
                  name,
                  maxLines: 2,
                  textAlign: TextAlign.center,
                  style: TextStyle(
                      color: Colors.black,
                      fontSize: fontSize,
                      fontWeight: FontWeight.bold),
                ),
              ),
                Container(
                    width: Constants.lineThickness,
                    height: 20, // **should automatically takes the remaining height of ConstrainedBox**
                    color: color)
            ],
          ),
        ),
       );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM