Unverified Commit 79146fd0 authored by Kate Lovett's avatar Kate Lovett Committed by GitHub

Fix SliverList scrollOffsetCorrection 0 case (#62615)

parent 4680ff3a
......@@ -169,22 +169,28 @@ class RenderSliverList extends RenderSliverMultiBoxAdaptor {
// If the scroll offset is at zero, we should make sure we are
// actually at the beginning of the list.
if (scrollOffset < precisionErrorTolerance) {
if (indexOf(firstChild) > 0) {
// We iterate from the firstChild in case the leading child has a 0 paint
// extent.
while (indexOf(firstChild) > 0) {
final double earliestScrollOffset = childScrollOffset(firstChild);
// We correct one child at a time. If there are more children before
// the earliestUsefulChild, we will correct it once the scroll offset
// reach zero again.
// reaches zero again.
earliestUsefulChild = insertAndLayoutLeadingChild(childConstraints, parentUsesSize: true);
assert(earliestUsefulChild != null);
final double firstChildScrollOffset = earliestScrollOffset - paintExtentOf(firstChild);
final SliverMultiBoxAdaptorParentData childParentData = firstChild.parentData as SliverMultiBoxAdaptorParentData;
childParentData.layoutOffset = 0.0;
// We only need to correct if the leading child actually has a
// paint extent.
if (firstChildScrollOffset < -precisionErrorTolerance) {
geometry = SliverGeometry(
scrollOffsetCorrection: -firstChildScrollOffset,
);
final SliverMultiBoxAdaptorParentData childParentData = firstChild.parentData as SliverMultiBoxAdaptorParentData;
childParentData.layoutOffset = 0.0;
return;
}
}
}
// At this point, earliestUsefulChild is the first child, and is a child
// whose scrollOffset is at or before the scrollOffset, and
......
......@@ -814,6 +814,31 @@ void main() {
expect(events, equals(<String>['tap']));
});
});
testWidgets('SliverList handles 0 scrollOffsetCorrection', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/62198
await tester.pumpWidget(MaterialApp(
home: Scaffold(
body: CustomScrollView(
physics: const BouncingScrollPhysics(parent: AlwaysScrollableScrollPhysics()),
slivers: <Widget>[
SliverList(
delegate: SliverChildListDelegate(
const <Widget>[
SizedBox.shrink(),
Text('index 1'),
Text('index 2'),
]
),
),
],
)
),
));
await tester.fling(find.byType(Scrollable), const Offset(0.0, -500.0), 10000.0);
await tester.pumpAndSettle();
expect(tester.takeException(), isNull);
});
}
bool isRight(Offset a, Offset b) => b.dx > a.dx;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment