Skip to content

SliverGrid with zero childCount throws The "scrollExtent" is negative. #59663

@ammarhemani

Description

@ammarhemani

Code to Reproduce

GridView.builder(
        shrinkWrap: true,
        physics: NeverScrollableScrollPhysics(),
        padding: EdgeInsets.only(top: 15),
        gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
          crossAxisCount: 1,
          mainAxisSpacing: 10,
          childAspectRatio: 2.1,
        ),
        itemCount: 0,
        itemBuilder: (context, index) {
          return getWidget(index);
        })

The itemCount parameter is, of course, dynamic, and in the rare situation that its set to 0, and the mainAxisSpacing is also defined, it throws an exception.

The exception doesn't occur if I remove the mainAxisSpacing value, OR if I increase the itemCount to something greater than 0.

Exception:

flutter: The following assertion was thrown during performLayout():
flutter: SliverGeometry is not valid: The "scrollExtent" is negative.
flutter: The RenderSliver that returned the offending geometry was: RenderSliverGrid#fe95d relayoutBoundary=up14 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE:
flutter:   creator: SliverGrid ← SliverPadding ← ShrinkWrappingViewport ← IgnorePointer-[GlobalKey#fd570] ←
flutter:     Semantics ← _PointerListener ← Listener ← _GestureSemantics ←
flutter:     RawGestureDetector-[LabeledGlobalKey<RawGestureDetectorState>#af9cf] ← _PointerListener ← Listener
flutter:     ← _ScrollableScope ← ⋯
flutter:   parentData: paintOffset=Offset(0.0, 15.0) (can use size)
flutter:   constraints: SliverConstraints(AxisDirection.down, GrowthDirection.forward, ScrollDirection.idle,
flutter:     scrollOffset: 0.0, remainingPaintExtent: Infinity, crossAxisExtent: 384.0, crossAxisDirection:
flutter:     AxisDirection.right, viewportMainAxisExtent: Infinity, remainingCacheExtent: Infinity,
flutter:     cacheOrigin: 0.0)
flutter:   geometry: SliverGeometry(scrollExtent: -10.0, hidden, maxPaintExtent: -10.0)
flutter:   no children current live
flutter:
flutter: The relevant error-causing widget was:
flutter:   GridView

Side note: The widget tree looks like this: CustomScrollView -> SliverList -> Column -> GridView.builder

Flutter (Channel master, 1.18.0-10.0.pre)
Dart version 2.9.0 (build 2.9.0-3.0.dev a69cb6d700)

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work lista: error messageError messages from the Flutter frameworkc: crashStack traces logged to the consoled: api docsIssues with https://api.flutter.dev/f: material designflutter/packages/flutter/material repository.f: scrollingViewports, list views, slivers, etc.found in release: 3.3Found to occur in 3.3found in release: 3.7Found to occur in 3.7frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work on

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions