简体   繁体   English

Flutter:嵌套 ListView 有效。 嵌套的 SliverList 没有,但 ListView 包含 Sliver

[英]Flutter: nested ListView works. Nested SliverList don't, yet ListView contains Slivers

I ran into a particular issue.我遇到了一个特定的问题。 I am able to compose a vertical outer ListView which contains horizontal ListView s.我能够组成一个包含水平ListView的垂直外部ListView Think of it as multiple Friend Suggestion Row on Facebook stacked on top of each other.将其视为 Facebook 上的多个朋友建议行堆叠在一起。 This works fine.这工作正常。

Because I want to utilize the perks that come with a SliverAppBar , I need to have a CustomScrollView as the parent Widget and then add only slivers in its slivers collection.因为我想利用SliverAppBar附带的特权,所以我需要有一个CustomScrollView作为父Widget ,然后在其slivers集合中只添加 slivers。

When I tried to add a SliverList inside the SliverChildBuilderDelegate , I get all sorts of errors, mostly, render-related types errors.当我尝试在SliverChildBuilderDelegate SliverList我得到了各种各样的错误,主要是与渲染相关的类型错误。 It seems like there is a constraint in the kind of child a SliverChildBuilderDelegate can build.似乎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

As you can see, I tried to wrap the SliverList in a non-sliver type of Widget, to no avail.如您所见,我尝试将SliverList包装在非 sliver 类型的 Widget 中,但无济于事。

I tried to solve it using NestedScrollView but I keep getting the same kind of errors.我尝试使用NestedScrollView解决它,但我不断收到相同类型的错误。

Has anyone run into this situation before.有没有人遇到过这种情况。 I went thru the source code and I can see that ListView is basically a BoxScrollView with an internal ScrollView .我浏览了源代码,我可以看到ListView基本上是一个带有内部ScrollViewBoxScrollView

Do I need to create a specialized Widget to fulfill this layout design.我是否需要创建一个专门的 Widget 来完成这个布局设计。 If that's the case, I am already scratching my head about Flutter.如果是这样的话,我已经对 Flutter 摸不着头脑了。

Solved.解决了。 All I was lacking was height and width in the containing Container of my nested SliverList .我所缺少的只是嵌套SliverList的包含Container中的heightwidth

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

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