有人能帮我破译我一直遇到的异常吗?我不确定下一步要做什么,以便在面板展开时修复溢出.我曾try 将其包装成一个灵活的小部件,但似乎无法解决问题.

下面是显示错误的快速gif:https://imgur.com/itIYV8s

以下是我的例外:

flutter: ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY 
╞═════════════════════════════════════════════════════════
flutter: The following message was thrown during layout:
flutter: A RenderFlex overflowed by 74 pixels on the bottom.
flutter:
flutter: The overflowing RenderFlex has an orientation of Axis.vertical.
flutter: The edge of the RenderFlex that is overflowing has been marked 
in the rendering with a yellow and
flutter: black striped pattern. This is usually caused by the contents 
being too big for the RenderFlex.
flutter: Consider applying a flex factor (e.g. using an Expanded widget) 
to force the children of the
flutter: RenderFlex to fit within the available space instead of being 
sized to their natural size.
flutter: This is considered an error condition because it indicates that there is content that cannot be
flutter: seen. If the content is legitimately bigger than the available space, consider clipping it with a
flutter: ClipRect widget before putting it in the flex, or using a scrollable container rather than a Flex,
flutter: like a ListView.
flutter: The specific RenderFlex in question is:
flutter:   RenderFlex#ac136 OVERFLOWING
flutter:   creator: Column ← DecoratedBox ← ConstrainedBox ← Container ← AnimatedContainer ← Container ←
flutter:   Column ← DefaultTextStyle ← AnimatedDefaultTextStyle ← _InkFeatures-[GlobalKey#04b41 ink renderer]
flutter:   ← NotificationListener<LayoutChangedNotification> ← CustomPaint ← ⋯
flutter:   parentData: <none> (can use size)
flutter:   constraints: BoxConstraints(w=363.0, h=0.4)
flutter:   size: Size(363.0, 0.4)
flutter:   direction: vertical
flutter:   mainAxisAlignment: spaceBetween
flutter:   mainAxisSize: max
flutter:   crossAxisAlignment: center
flutter:   verticalDirection: down
flutter: ◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤
flutter: ════════════════════════════════════════════════════════════════════════════════════════════════════
flutter: Another exception was thrown: A RenderFlex overflowed by 74 pixels on the bottom.

以下是我的代码:

new SingleChildScrollView(
    child: new Card(
    margin: EdgeInsets.all(0.0),
    elevation: 2.0,
    color: MyApp.getTheme().canvasColor,
    child: new Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: <Widget>[
        new ListTile(
            title: new Text("FB", style: new TextStyle(
              fontWeight: FontWeight.bold,
            ),),
            subtitle: new Text("Facebook, Inc."),
            onTap: () {
              setState(() {
                if (this._bodyHeight == 200.0) {
                  this._bodyHeight = 0.0;
                } else {
                  this._bodyHeight = 200.0;
                }
              });
            },
            trailing: new FlatButton(
              shape: new RoundedRectangleBorder(
                borderRadius: new BorderRadius.all(new Radius.circular(20.0)),
              ),
              onPressed: () {
                setState(() {
                  mode++;
                  if (mode == 1) {
                    text = "+0.80%";
                  } else if (mode == 2) {
                    text = "+1.41";
                  } else {
                    text = "513.3B";
                    mode=0;
                  }
                });
              },
              child: new Text("+1.41", style: new TextStyle(
                color: Colors.white,
              ),),
              color: Colors.green,
            )
        ),
        new Container(
          child: new AnimatedContainer(
            child: new Column(
             mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: <Widget>[
                new Text(""),
                new Padding(
                  padding: new EdgeInsets.only(bottom: 5.0),
                  child: new Column(
                    children: <Widget>[
                      new Divider(),
                      new Row(
                        mainAxisAlignment: MainAxisAlignment.end,
                        children: <Widget>[
                          new FlatButton(
                            onPressed: () {
                              setState(() {
                                if (this._bodyHeight == 200.0) {
                                  this._bodyHeight = 0.0;
                                } else {
                                  this._bodyHeight = 200.0;
                                }
                              });
                             },
                            child: new Text(
                              "CANCEL",
                              style: new TextStyle(
                                color: Colors.grey,
                              ),
                            ),
                          ),
                          new FlatButton(
                            onPressed: null,
                            child: new Text(
                               "SAVE",
                              style: new TextStyle(
                                color: MyApp.getTheme().indicatorColor,
                              ),
                            ),
                          ),
                        ],
                      ),
                    ],
                  ),
                )
              ],
            ),
            width: 400.0,
            curve: Curves.easeInOut,
            duration: const Duration(milliseconds: 500),
            height: _bodyHeight,
            color: MyApp.getTheme().canvasColor,
          ),
        ),
      ],
    ),
  ),
),

非常感谢!

推荐答案

我判断了你的代码,错误的原因是FlatButton和分隔符中的Column部分.

new SingleChildScrollView(
        child: new Card(
          margin: EdgeInsets.all(0.0),
          elevation: 2.0,
          child: new Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              new ListTile(
                  title: new Text(
                    "FB",
                    style: new TextStyle(
                      fontWeight: FontWeight.bold,
                    ),
                  ),
                  subtitle: new Text("Facebook, Inc."),
                  onTap: () {
                    setState(() {
                      if (this._bodyHeight == 200.0) {
                        this._bodyHeight = 0.0;
                      } else {
                        this._bodyHeight = 200.0;
                      }
                    });
                  },
                  trailing: new FlatButton(
                    shape: new RoundedRectangleBorder(
                      borderRadius:
                          new BorderRadius.all(new Radius.circular(20.0)),
                    ),
                    onPressed: () {
                      setState(() {
                        mode++;
                        if (mode == 1) {
                          text = "+0.80%";
                        } else if (mode == 2) {
                          text = "+1.41";
                        } else {
                          text = "513.3B";
                          mode = 0;
                        }
                      });
                    },
                    child: new Text(
                      "+1.41",
                      style: new TextStyle(
                        color: Colors.white,
                      ),
                    ),
                    color: Colors.green,
                  )),
              new Container(
                child: new AnimatedContainer(
                  child: Align(
                      alignment: Alignment.bottomRight,
                      child: new SingleChildScrollView(
                        child: new Column(
                          mainAxisAlignment: MainAxisAlignment.end,
                          children: <Widget>[
                            new Divider(),
                            new Row(
                              mainAxisAlignment: MainAxisAlignment.end,
                              children: <Widget>[
                                new FlatButton(
                                  onPressed: () {
                                    setState(() {
                                      if (this._bodyHeight == 200.0) {
                                        this._bodyHeight = 0.0;
                                      } else {
                                        this._bodyHeight = 200.0;
                                      }
                                    });
                                  },
                                  child: new Text(
                                    "CANCEL",
                                    style: new TextStyle(
                                      color: Colors.grey,
                                    ),
                                  ),
                                ),
                                new FlatButton(
                                  onPressed: null,
                                  child: new Text(
                                    "SAVE",
                                  ),
                                ),
                              ],
                            ),
                          ],
                        ),
                      )),
                  width: 400.0,
                  curve: Curves.easeInOut,
                  duration: const Duration(milliseconds: 500),
                  height: _bodyHeight,
                ),
              ),
            ],
          ),
        ),
      ), // This trailing comma makes auto-formatting nicer for build methods.

并且在动画过程中,列是溢出的.因为Column不可见(并且应该是可见的),所以导致了这个错误.因此,我们将把该列放在SingleChildScrollView列中来解决问题,这样它就会考虑到它是可见的.

我希望一切都清楚了,如果有什么不清楚或代码不起作用,请告诉我.

Dart相关问答推荐

Dart中的运算符(){…}做什么?

数字到字符串的转换在 Dart 中总是不变的(即没有文化)?

Dart:当两个或多个任务等待同一个 Future 时会发生什么

将Card添加到 ListView

无法在Flutter中为 TabBarView 设置动态高度

如何使用我的 dart 包私有而不在 pub dart lang 上显示?

如何签署 Flutter 的应用程序

在Dart streams中,listen和forEach有什么区别?

判断 Future 是否完整

如何组织混合HTTP服务器+web客户端Dart元素文件?

如何在 Dart 中获取当前脚本的目录?

将Flutter的 PageView 与屏幕左侧对齐

Flutter:如何获取assets目录中所有图像的名称列表?

在 Dart 中使用固定长度列表有性能优势吗?

如何提高数据与二进制数据转换的 Dart 性能?

如何使异步 Dart 调用同步?

在 Dart 中覆盖哈希码的好方法是什么?

如何在 Dart 中定义接口?

在 Dart 中为数字添加前导零

Dart 中的全局变量