[英]Flutter: nested ListView works. Nested SliverList don't, yet ListView contains Slivers
我遇到了一個特定的問題。 我能夠組成一個包含水平ListView
的垂直外部ListView
。 將其視為 Facebook 上的多個朋友建議行堆疊在一起。 這工作正常。
因為我想利用SliverAppBar
附帶的特權,所以我需要有一個CustomScrollView
作為父Widget
,然后在其slivers
集合中只添加 slivers。
當我嘗試在SliverChildBuilderDelegate
SliverList
我得到了各種各樣的錯誤,主要是與渲染相關的類型錯誤。 似乎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
包裝在非 sliver 類型的 Widget 中,但無濟於事。
我嘗試使用NestedScrollView
解決它,但我不斷收到相同類型的錯誤。
有沒有人遇到過這種情況。 我瀏覽了源代碼,我可以看到ListView
基本上是一個帶有內部ScrollView
的BoxScrollView
。
我是否需要創建一個專門的 Widget 來完成這個布局設計。 如果是這樣的話,我已經對 Flutter 摸不着頭腦了。
解決了。 我所缺少的只是嵌套SliverList
的包含Container
中的height
和width
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.