如何摆脱因容器的固定宽度和高度引起的错误

时间:2019-08-22 13:12:10

标签: flutter

我要在文本太长时将Container设置为固定高度。我尝试扩展代码和滚动代码

代码

 child: Column(
            children: <Widget>[
              Container(
                padding: EdgeInsets.symmetric(vertical: 5),
                height: MediaQuery.of(context).size.height / 7.5,
                width: MediaQuery.of(context).size.width,
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.end,
                  children: <Widget>[
                    Container(
                        width: MediaQuery.of(context).size.width / 1.6,
                        margin: EdgeInsets.symmetric(horizontal: 5),
                        child: Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: <Widget>[
                            Text(
                              post.name,
                              textDirection: TextDirection.rtl,
                              style: TextStyle(
                                fontStyle: FontStyle.normal,
                                decorationColor: Colors.black,
                                fontSize: 16,
                                fontWeight: FontWeight.w600, // light
                              ),
                            )
                          ],
                        )),
                    Container(
                      width: MediaQuery.of(context).size.width / 4,
                      decoration: BoxDecoration(
                        image: DecorationImage(
                            image: NetworkImage(post.email),
                            fit: BoxFit.fitHeight),
                      ),
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.end,
                        mainAxisAlignment: MainAxisAlignment.end,
                        children: <Widget>[
                          Container(
                              margin: EdgeInsets.only(bottom: 0, right: 10),
                              color: Colors.black.withOpacity(0.50),
                              child: Row(
                                children: <Widget>[
                                  Text(post.since,
                                      textDirection: TextDirection.rtl,
                                      style: TextStyle(color: Colors.white)),
                                  Icon(
                                    Icons.timer,
                                    textDirection: TextDirection.rtl,
                                    color: Color(0xFFffab40),
                                    size:
                                        MediaQuery.of(context).size.width / 35,
                                  )
                                ],
                              ))
                        ],
                      ),
                    ),
                  ],
                ),
              )
            ],
          )

使用post.name容器,当文本太长时,我会面对 屏幕截图 enter image description here

黄色错误,已尝试修复.. 使用滚动时,我面对的应用程序因ios崩溃

1 个答案:

答案 0 :(得分:-2)

Container默认会尝试扩展以匹配其父级大小。您通过提供固定的widthheight来约束它。您可以删除Container,也可以删除width/height