BoxConstraints会导致无限的高度误差

问题描述

目标:我需要使此列(垂直)滚动。

已执行:此列可滚动。

实际:我的控制台出现错误,我的应用是空白的空白屏幕。

要提一下,我确实在这里阅读了有关Stack Overflow的另一个BoxConstraints问题。

不幸的是,它没有用。

最终,我有一个专栏,上面有各种身高的孩子。子项的组合高度大于视口高度。

我使用了SingleChildScrollview并遵循以下指示:

https://api.flutter.dev/flutter/widgets/SingleChildScrollView-class.html

LayoutBuilder,ConstrainedBoxBoxConstraints和IntrinsicHeight都被使用了,但我仍然遇到该错误

我的手机当前是空白的空白屏幕(右上角为“调试”)。

这就是我的理解:

SingleChildScrollView通过授予无限的高度,使其中的内容可滚动。

列自然占据了其父级的全部高度。

2的组合意味着一列将一直持续下去,直到应用崩溃。

LayoutBuilder用于获取视口的大小。

ConstrainedBox用于设置列的MINIMUM高度。这对我来说说,列不能小于给定的高度,而可以和无穷大一样大。

“魔术”发生在IntrinsicHeight上,它迫使列与内容完全一样大。这就是阻止色谱柱进入无穷大的原因。

尽管一切,我仍然遇到错误

我希望有人能提供帮助;以下是我的代码

              padding: EdgeInsets.all(15),color: Colors.white,child: LayoutBuilder(
                builder:
                    (BuildContext context,BoxConstraints viewportConstraints) {
                  return SingleChildScrollView(
                    child: ConstrainedBox(
                      constraints: BoxConstraints(
                        minHeight: viewportConstraints.maxHeight,),child: IntrinsicHeight(
                        child: Column(
                          children: <Widget>[
                            Column(
                              children: [
                                Text(),RaisedButton(),Text(),],Column(
                              children: [
                                Text(),

抛出的错误是这样的:

══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
The following assertion was thrown during performlayout():
BoxConstraints forces an infinite height.
These invalid constraints were provided to RenderIntrinsicHeight's layout() function by the
following function,which probably computed the invalid constraints in question:
  RenderConstrainedBox.performlayout (package:Flutter/src/rendering/proxy_Box.dart:270:13)
The offending constraints were:
  BoxConstraints(0.0<=w<=330.0,h=Infinity)
The relevant error-causing widget was:
  ConstrainedBox

这行有趣的内容是:

The following RenderObject was being processed when the exception was fired: RenderConstrainedBox#d1ae8 relayoutBoundary=up15 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE:
  creator: ConstrainedBox ← _SingleChildViewport ← IgnorePointer-[GlobalKey#f983f] ← Semantics ←
    _PointerListener ← Listener ← _GestureSemantics ←
    RawGestureDetector-[LabeledGlobalKey<RawGestureDetectorState>#d70da] ← _PointerListener ← Listener
    ← _ScrollableScope ← _ScrollSemantics-[GlobalKey#d055d] ← ⋯
  parentData: <none> (can use size)
  constraints: BoxConstraints(0.0<=w<=330.0,0.0<=h<=Infinity)
  **size: MISSING**
  additionalConstraints: BoxConstraints(0.0<=w<=Infinity,h=Infinity)

在此先感谢所有提供帮助的人!

解决方法

我已经将listView(以及所有其他可滚动的小部件)包裹在一列中。我最初使用一列将所有内容堆叠在一起,但显然listView可以做到这一点。