问题描述
我遇到了一个特定的问题。我能够组成一个包含水平 ListView
的垂直外部 ListView
。可以将其视为 Facebook 上的多个好友建议行堆叠在一起。这工作正常。
因为我想利用 SliverAppBar
附带的特权,我需要将 CustomScrollView
作为父 Widget
,然后在其 slivers
中仅添加条子收藏。
当我尝试在 SliverList
中添加 SliverChildBuilderDelegate
时,我收到各种错误,主要是与渲染相关的类型错误。 SliverChildBuilderDelegate
可以构建的孩子类型似乎存在限制。
NEEDS-COMPOSITING-BITS-UPDATE:
needs compositing
creator: Viewport ← IgnorePointer-[GlobalKey#a5a09] ← Semantics ← Listener ← _GestureSemantics ←
RawGestureDetector-[LabeledGlobalKey<RawGestureDetectorState>#db221] ← Listener ← _ScrollableScope
← _ScrollSemantics-[GlobalKey#57142] ← Scrollable ← CustomScrollView ← Padding ← ⋯
parentData: <none> (can use size)
constraints: BoxConstraints(w=412.0,0.0<=h<=Infinity)
size: MISSING
axisDirection: right
crossAxisDirection: down
offset: ScrollPositionWithSingleContext#415a2(offset: 0.0,range: null..null,viewport: null,ScrollableState,BouncingScrollPhysics -> RangeMaintainingScrollPhysics,IdleScrollActivity#74aea,ScrollDirection.idle)
anchor: 0.0
This RenderObject had the following child:
center child: RenderSliverList#5219f NEEDS-LAYOUT NEEDS-PAINT
════════════════════════════════════════════════════════════════════════════════════════════════════
Another exception was thrown: RenderBox was not laid out: RenderViewport#e26b4 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
Another exception was thrown: RenderBox was not laid out: RenderViewport#e26b4 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
Another exception was thrown: RenderBox was not laid out: RenderIgnorePointer#e30f7 relayoutBoundary=up10 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
Another exception was thrown: RenderBox was not laid out: RenderSemanticsAnnotations#d70ab relayoutBoundary=up9 NEEDS-PAINT
NEEDS-COMPOSITING-BITS-UPDATE
如您所见,我尝试将 SliverList
包装在非银条类型的 Widget 中,但无济于事。
我尝试使用 nestedScrollView
解决它,但我不断收到相同类型的错误。
有没有人遇到过这种情况。我查看了源代码,可以看到 ListView
基本上是一个带有内部 BoxScrollView
的 ScrollView
。
我是否需要创建一个专门的 Widget 来完成这个布局设计。如果是这样的话,我已经对 Flutter 抓狂了。
解决方法
解决了。我所缺少的只是嵌套 height
的包含 width
中的 Container
和 SliverList
。