Skip to content

Crash when using SliverGrid, findChildIndexCallback, a sparsely populated grid and updating the children #138749

@dowski

Description

@dowski

Is there an existing issue for this?

Steps to reproduce

In the app I'm working on, we have a custom SliverGrid layout. It does a somewhat sparse layout of grid items, with a contiguous series of items and other items interspersed along the way. Some actions performed in the app causes the grid contents to be limited - thus items are removed from the grid.

We also use a findChildIndexCallback with SliverChildBuilderDelegate. It seems like that combination can lead to places in the grid where removing items leads to a crash.

  1. Open https://dartpad.dev/?id=d9f723468f22d4035dfcf90366802151
  2. Run app
  3. Scroll down until "grid item 7" just scrolls into view in the left column
  4. Press the FAB/refresh button in the bottom right

Expected results

No crashes or issues.

Actual results

══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
The following assertion was thrown during performLayout():
Assertion failed:
file:///opt/flutter/packages/flutter/lib/src/rendering/sliver_multi_box_adaptor.dart:508:12
childCount >= leadingGarbage + trailingGarbage
is not true

Widget creation tracking is currently disabled. Enabling it enables improved error messages. It can
be enabled by passing `--track-widget-creation` to `flutter run` or `flutter test`.

When the exception was thrown, this was the stack

The following RenderObject was being processed when the exception was fired: RenderSliverGrid#255ad relayoutBoundary=up1 NEEDS-LAYOUT NEEDS-COMPOSITING-BITS-UPDATE:
  needs compositing
  creator: SliverGrid ← Viewport ← IgnorePointer-[GlobalKey#e6cb3] ← Semantics ← Listener ←
    _GestureSemantics ← RawGestureDetector-[LabeledGlobalKey<RawGestureDetectorState>#04dfe] ←
    Listener ← _ScrollableScope ← _ScrollSemantics-[GlobalKey#8e450] ←
    NotificationListener<ScrollMetricsNotification> ← RepaintBoundary ← ⋯
  parentData: paintOffset=Offset(0.0, 0.0) (can use size)
  constraints: SliverConstraints(AxisDirection.down, GrowthDirection.forward, ScrollDirection.idle,
    scrollOffset: 6878.2, remainingPaintExtent: 805.0, crossAxisExtent: 826.0, crossAxisDirection:
    AxisDirection.right, viewportMainAxisExtent: 805.0, remainingCacheExtent: 1305.0, cacheOrigin:
    -250.0)
  geometry: SliverGeometry(scrollExtent: 21000.0, paintExtent: 805.0, maxPaintExtent: 21000.0,
    hasVisualOverflow: true, cacheExtent: 1305.0)
  currently live children: 1 to 6
This RenderObject had the following descendants (showing up to depth 5):
    child with index 1: RenderIndexedSemantics#9f23a
      child: RenderRepaintBoundary#89623 NEEDS-PAINT
        child: _RenderColoredBox#da96c NEEDS-PAINT
          child: RenderPositionedBox#60e7f NEEDS-LAYOUT
            child: RenderParagraph#3e200 relayoutBoundary=up1 NEEDS-LAYOUT
    child with index 2: RenderIndexedSemantics#cd9d3
      child: RenderRepaintBoundary#04b11 NEEDS-PAINT
        child: _RenderColoredBox#d3dc9 NEEDS-PAINT
          child: RenderPositionedBox#d0f81 NEEDS-LAYOUT
            child: RenderParagraph#6065a relayoutBoundary=up1 NEEDS-LAYOUT
    child with index 5: RenderIndexedSemantics#5f68d NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
      child: RenderRepaintBoundary#ed0b9 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
        child: _RenderColoredBox#b737d NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
          child: RenderPositionedBox#2daac NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
            child: RenderParagraph#26a3e NEEDS-LAYOUT NEEDS-PAINT
    child with index 6: RenderIndexedSemantics#4b2f1 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
      child: RenderRepaintBoundary#93339 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
        child: _RenderColoredBox#10147 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
          child: RenderPositionedBox#a9025 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
            child: RenderParagraph#23002 NEEDS-LAYOUT NEEDS-PAINT
════════════════════════════════════════════════════════════════════════════════════════════════════

Code sample

Code sample

See https://dartpad.dev/?id=d9f723468f22d4035dfcf90366802151.

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

Logs
[Paste your logs here]

Flutter Doctor output

Doctor output
[Paste your output here]

Metadata

Metadata

Labels

P0Critical issues such as a build break or regressiona: error messageError messages from the Flutter frameworkf: scrollingViewports, list views, slivers, etc.found in release: 3.16Found to occur in 3.16found in release: 3.17Found to occur in 3.17frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onr: fixedIssue is closed as already fixed in a newer versionteam-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions