简体   繁体   English

Renderflex 溢出 - 我如何在 flutter 中克服这个问题?

[英]Renderflex overflow - how do I overcome this in flutter?

I know I will get a lot of negative remarks for this question, but I'm getting really frustrated.我知道我会因为这个问题得到很多负面评价,但我真的很沮丧。 I tested my app on a new iPhone 11pro and I get now a lot of renderflex errors.我在新的 iPhone 11pro 上测试了我的应用程序,现在我得到了很多 renderflex 错误。 You all know the error logs - and even google give you some advice like " Have you considered using a Flex or Expanded parent? "你们都知道错误日志——甚至谷歌也会给你一些建议,比如“你考虑过使用 Flex 或 Expanded 父级吗?”

Now, for Text Widgets that go over, I use Expanded.现在,对于 go 结束的文本小部件,我使用扩展。 .. and that's great. ..那太好了。 That's super.太棒了I just wrap my Text in an Expanded and it "wraps" the text around so it fits within its container.我只是将我的文本包装在一个 Expanded 中,它会“包装”文本,使其适合其容器。

But what would be the equivalent of wrapping other widgets like rows or columns, or singlechildscrollviews?但是,与包装其他小部件(如行或列,或单子滚动视图)等效的是什么?

I tried to wrap them in an expanded, and I get the same error message.我试图将它们包装在一个扩展中,我得到了同样的错误信息。

I'm fed up.我受够了。

Here is an example of some code:这是一些代码的示例:

            Container(
             // width: MediaQuery.of(context).size.width,
             // height: MediaQuery.of(context).size.height,


              //TODO: checkboxes

              child: Center(
                child: Column(
                // mainAxisSize: MainAxisSize.max,
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: <Widget>[
                    Container(width: 200,height: 100,
                      child: Row(
                        mainAxisSize: MainAxisSize.max,
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: <Widget>[
                          checkbox(sun, days[sun]),
                          checkbox(mon, days[mon]),
                          checkbox(tue, days[tue]),
                          checkbox(wed, days[wed]),
                          checkbox(thu, days[thu]),
                          checkbox(fri, days[fri]),
                          checkbox(sat, days[sat]),

                        ],
                      ),
                    ),
                  ],
                ),
              )
          ),

Approach 1: Use ListView方法一:使用ListView

        child: Container(
          child: Center(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Container(
                  width: 200,
                  height: 100,
                  child: ListView(
                    scrollDirection: Axis.horizontal,
                    children: <Widget>[
                      Text("Example"),
                      SizedBox(width: 10),
                      Text("Example"),
                      SizedBox(width: 10),
                      Text("Example"),
                      SizedBox(width: 10),
                      Text("Example"),
                      SizedBox(width: 10),
                      Text("Example"),
                      SizedBox(width: 10),
                      Text("Example"),
                      SizedBox(width: 10),
                      Text("Example"),
                      SizedBox(width: 10),
                      Text("Example"),
                      SizedBox(width: 10),
                      Text("Example"),
                      SizedBox(width: 10),
                      Text("Example"),
                      SizedBox(width: 10),
                      Text("Example"),
                      SizedBox(width: 10),
                      Text("Example"),
                    ],
                  ),
                ),
              ],
            ),
          ),
         ),

在此处输入图像描述

Approach 2: You can use Wrap instead of ListView if you want show all items in that child.方法 2:如果要显示该子项中的所有项目,可以使用Wrap而不是ListView

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

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