Fix SliverList scrollOffsetCorrection 0 case (#62615)
This commit is contained in:
parent
4680ff3a79
commit
79146fd0a6
@ -169,20 +169,26 @@ 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);
|
||||
geometry = SliverGeometry(
|
||||
scrollOffsetCorrection: -firstChildScrollOffset,
|
||||
);
|
||||
final SliverMultiBoxAdaptorParentData childParentData = firstChild.parentData as SliverMultiBoxAdaptorParentData;
|
||||
childParentData.layoutOffset = 0.0;
|
||||
return;
|
||||
// We only need to correct if the leading child actually has a
|
||||
// paint extent.
|
||||
if (firstChildScrollOffset < -precisionErrorTolerance) {
|
||||
geometry = SliverGeometry(
|
||||
scrollOffsetCorrection: -firstChildScrollOffset,
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user