flutter - Renderflex溢出-如何克服抖动?

标签 flutter dart flutter-layout

我知道这个问题会给我很多负面评价,但我真的很沮丧。
我在新的iPhone 11pro上测试了我的应用程序,现在出现很多renderflex错误。大家都知道错误日志-甚至Google也给您一些建议,例如“您是否考虑过使用Flex或Expanded parent?”

现在,对于过去的文本小部件,我使用扩展。 ..那太好了。太好了!我只是将我的文本包装在Expanded中,然后将其“包装”在文本中,使其适合其容器。

但是包装其他小部件(如行或列或singlechildscrollviews)相当于什么呢?

我试图将它们包装在扩展中,并且得到相同的错误消息。

我受够了。

这是一些代码的示例:

            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]),

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

最佳答案

方法1:使用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"),
                    ],
                  ),
                ),
              ],
            ),
          ),
         ),

enter image description here

方法2:如果要显示该子级中的所有项目,可以使用Wrap代替ListView

关于flutter - Renderflex溢出-如何克服抖动?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58232869/

相关文章:

string - 如何创建字符串作为另一个列表的一部分的列表

flutter 如何更改容器上的一个边框并保持 borderRadius?

flutter - flutter 有像 android "addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK)"这样的概念

android - Webview 中的全屏视频在 Flutter 中不起作用

flutter - 如何从ListView获取值列表

iOS FirebaseCloudMessaging 通知在调试/测试飞行或发布中不起作用

flutter - flutter中如何实现多行水平滚动

listview - 插入新记录后如何重新加载列表?

flutter - 用 Dart 条件设置变量

dart - 有没有一种方法可以通过一个按钮一次控制在不同时间在同一 route 以不同方式显示两个小部件?