Skip to content

MultiSliver fails in a shrinkwrapped, unconstrained CustomScrollView #95

@HeinrichJanzing

Description

@HeinrichJanzing

MultiSliver calculates an invalid SliverGeometry when the incoming SliverConstraints.remainingCacheExtent is infinity. Infinity should be accepted: according to the docs, remainingPaintExtent can be infinity and remainingCacheExtent is always >= remainingPaintExtent. One situation in which this occurs is a shrinkwrapped CustomScrollView unconstrained on its main axis.

Specifically, RenderMultiSliver sets its SliverGeometry.cacheExtent to NaN, by subtracting infinity from infinity in this calculation in RenderMultiSliver._layoutChildSequence. This causes a series of assertion failures and incomplete rendering.

I suspect the code should instead accumulate the cacheExtent of the children to determine its own cacheExtent, as it does for the paintExtent already.

This app reproduces the problem for me, using sliver_tools 0.2.12:

import 'package:flutter/material.dart';
import 'package:sliver_tools/sliver_tools.dart';

void main() {
  runApp(const MainApp());
}

class MainApp extends StatelessWidget {
  const MainApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        home: UnconstrainedBox(
            constrainedAxis: Axis.horizontal,
            child: CustomScrollView(shrinkWrap: true, slivers: [
              MultiSliver(children: const [SizedBox(height: 100)])
            ])));
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions