引发了另一个异常: RenderBox 未布置:CustomRenderShrinkWrappingViewport#f6727 relayoutBoundary=up17 NEEDS-PAINT N

Posted

技术标签:

【中文标题】引发了另一个异常: RenderBox 未布置:CustomRenderShrinkWrappingViewport#f6727 relayoutBoundary=up17 NEEDS-PAINT NEEDS-COMPOSITING【英文标题】:Another exception was thrown: RenderBox was not laid out: CustomRenderShrinkWrappingViewport#f6727 relayoutBoundary=up17 NEEDS-PAINT NEEDS-COMPOSITING 【发布时间】:2022-01-19 12:38:46 【问题描述】:

我需要水平生成一个列表。但是,我面临以下问题:

发生异常时正在处理以下 RenderObject 解雇:CustomRenderShrinkWrappingViewport#f6727 relayoutBoundary=up17 需要-布局需要-油漆需要-合成-位-更新:需要 合成创建者:CustomShrinkWrappingViewport ← IgnorePointer-[GlobalKey#952f0] ← 语义 ← 监听器 ← _GestureSemantics ← RawGestureDetector-[LabeledGlobalKey#f0fc7] ← 监听器 ← _ScrollableScope ← _ScrollSemantics-[GlobalKey#c0651] ← RepaintBoundary ← CustomPaint ← RepaintBoundary ← ⋯ parentData:(可以使用大小)约束:BoxConstraints(0.0 RangeMaintainingScrollPhysics, IdleScrollActivity#d7dd2, ScrollDirection.idle) 锚点:0.0 此 RenderObject 具有以下后代(显示深度为 5): 子 0:RenderSliv​​erPadding#963bb 需要-布局需要-绘制需要-合成-位更新 孩子:RenderSliv​​erList#5357f 需要-布局需要-油漆 孩子 1:RenderSliv​​erPadding#2291f 需要 - 布局需要 - 油漆需要 - 合成 - 位更新 child: RenderSliv​​erList#6db77 需要-布局需要-油漆══════════════════════════════════ ══════════════════════════════════════════════════ ═══════════

抛出了另一个异常:RenderBox 未布局: CustomRenderShrinkWrappingViewport#f6727 relayoutBoundary=up17 需要-油漆需要-合成-位-更新

代码是:

CustomScrollView(
      // physics: ScrollPhysics(),
      scrollDirection: Axis.vertical,

      slivers: [
        SliverList(
          delegate: SliverChildBuilderDelegate(
            (context, index) => ScrollablePositionedList.builder(
              shrinkWrap: true,
              scrollDirection: Axis.horizontal,
              itemScrollController: _scrollController,
              itemCount: dummyQuestions.length,
              itemBuilder: (context, index) 
              currentPageIndex = index;
              return dummyQuestions[index];
              ,
            ),
          ),
        ),
      ],
    ),

【问题讨论】:

【参考方案1】:

请参考以下代码:

CustomScrollView(
      controller: scrollController,
      scrollDirection: Axis.horizontal,
      slivers: <Widget>[
        SliverList(
          delegate: SliverChildBuilderDelegate(
            (_, int index) 
             return Container(
             child: Text(list[index]['index'],),
             );
            ,
            childCount: list.length,
          )
        ),
      ],
    ))

【讨论】:

以上是关于引发了另一个异常: RenderBox 未布置:CustomRenderShrinkWrappingViewport#f6727 relayoutBoundary=up17 NEEDS-PAINT N的主要内容,如果未能解决你的问题,请参考以下文章

错误:未布置 RenderBox,断言失败:第 1940 行 pos 12:'hasSize'

RenderBox 未布局,Flutter Listview Builder 未显示

Flutter:未布置RenderBox:RenderRepaintBoundary#58c65 relayoutBoundary = up1 NEEDS-PAINT

RenderBox 未布置:RenderFlex#4a60a 需要-油漆需要-合成-位-更新

垂直视口被赋予了无限的高度。 RenderBox 未布置:RenderViewport#34d12 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UP

例外:-尽管删除了扩展的小部件,但没有布置 RenderBox