首页 > 解决方案 > Flutter - 底部溢出 81 像素的 RenderFlex

问题描述

下午好,我是 android 编程新手。我想问一下我的代码中的错误。错误是“在布局期间引发了以下断言:RenderFlex 在底部溢出了 81 个像素。” . 我试图找到一个解决方案,但仍然没有任何效果。这是我的代码。谢谢你

class berita_secondpage extends StatelessWidget {
  final String title;

  berita_secondpage({
    this.title,
  });

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text(title),
        ),
        body: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            Expanded(
              child: Container(
                  decoration: BoxDecoration(
                      borderRadius: BorderRadius.only(
                          bottomLeft: Radius.circular(30),
                          bottomRight: Radius.circular(30)),
                      image: DecorationImage(
                        image: AssetImage("assets/images/aquaman.jpg"),
                        fit: BoxFit.cover,
                      ))),
            ),
            Container(
              height: 260,
              child: Column(
                children: <Widget>[
                  Padding(
                    padding: EdgeInsets.fromLTRB(20, 20, 20, 0),
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: <Widget>[
                        Text(
                          title,
                          style: TextStyle(
                            // color: Colors.lightBlueAccent,
                            fontSize: 25,
                            fontWeight: FontWeight.w600,
                          ),
                        ),
                        Text(
                          "diupload pada : 20 Agustus 2021",
                          style: TextStyle(
                            // color: Colors.lightBlueAccent,
                            fontSize: 10,
                            fontWeight: FontWeight.w600,
                          ),
                        ),
                        SizedBox(
                          width: 15,
                        ),
                        Text(
                          "testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing",
                          style: TextStyle(
                            // color: Colors.lightBlueAccent,
                            fontSize: 17,
                            fontWeight: FontWeight.w600,
                          ),
                        ),
                      ],
                    ),
                  )
                ],
              ),
            )
          ],
        ));
  }
}

标签: androidflutterdart

解决方案


您的问题是由于您的第二个容器高度而发生的。你给容器高度 260,但你的文本需要更多的空间来显示。 记住,'A RenderFlex overflowed ......'想告诉你你的数据(图像/文本)需要更多空间,但你给他的空间很小。

class SecondPage extends StatelessWidget {
  final String title;
  SecondPage({required this.title});

     @override
     Widget build(BuildContext context) {
      return Scaffold(
         appBar: AppBar(
      title: Text(title),
    ),
    body: Container(
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Expanded(
            child: Container(
              decoration: const BoxDecoration(
                color: Colors.red,
                borderRadius: BorderRadius.only(
                    bottomLeft: Radius.circular(30),
                    bottomRight: Radius.circular(30)),
                image: DecorationImage(
                  image: NetworkImage('https://picsum.photos/250?image=9'),
                  fit: BoxFit.cover,
                ),
              ),
            ),
          ),
          Container(
            height: 360,
            child: Column(
              children: <Widget>[
                Padding(
                  padding: EdgeInsets.fromLTRB(20, 20, 20, 0),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: <Widget>[
                      Text(
                        title,
                        style: const TextStyle(
                          // color: Colors.lightBlueAccent,
                          fontSize: 25,
                          fontWeight: FontWeight.w600,
                        ),
                      ),
                      const Text(
                        "diupload pada : 20 Agustus 2021",
                        style:  TextStyle(
                          color: Colors.lightBlueAccent,
                          fontSize: 10,
                          fontWeight: FontWeight.w600,
                        ),
                      ),
                      const   SizedBox(
                        width: 15,
                      ),
                      const Text(
                        "testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing",
                        style:  TextStyle(
                          // color: Colors.lightBlueAccent,
                          fontSize: 17,
                          fontWeight: FontWeight.w600,
                        ),
                      ),
                    ],
                  ),
                )
              ],
            ),
          )
        ],
      ),
    ));
 }
}

推荐阅读