Skip to content

Commit 9e0ad4c

Browse files
authored
Fix paint offset in reverse for 2D (flutter#128724)
Fixes flutter#128723 The paint offset was incorrectly being computed when one or both axis was in the reverse direction. Instead of using the paint extent, the child's size should be used.
1 parent 9af6bae commit 9e0ad4c

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

packages/flutter/lib/src/widgets/two_dimensional_viewport.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,7 +1149,6 @@ abstract class RenderTwoDimensionalViewport extends RenderBox implements RenderA
11491149
childParentData.paintOffset = computeAbsolutePaintOffsetFor(
11501150
child,
11511151
layoutOffset: childParentData.layoutOffset!,
1152-
paintExtent: childParentData._paintExtent!,
11531152
);
11541153
// If the child is partially visible, or not visible at all, there is
11551154
// visual overflow.
@@ -1243,14 +1242,15 @@ abstract class RenderTwoDimensionalViewport extends RenderBox implements RenderA
12431242
Offset computeAbsolutePaintOffsetFor(
12441243
RenderBox child, {
12451244
required Offset layoutOffset,
1246-
required Size paintExtent,
12471245
}) {
1248-
assert(hasSize); // this is only usable once we have a size
1246+
// This is only usable once we have sizes.
1247+
assert(hasSize);
1248+
assert(child.hasSize);
12491249
final double xOffset;
12501250
final double yOffset;
12511251
switch (verticalAxisDirection) {
12521252
case AxisDirection.up:
1253-
yOffset = viewportDimension.height - (layoutOffset.dy + paintExtent.height);
1253+
yOffset = viewportDimension.height - (layoutOffset.dy + child.size.height);
12541254
case AxisDirection.down:
12551255
yOffset = layoutOffset.dy;
12561256
case AxisDirection.right:
@@ -1261,7 +1261,7 @@ abstract class RenderTwoDimensionalViewport extends RenderBox implements RenderA
12611261
case AxisDirection.right:
12621262
xOffset = layoutOffset.dx;
12631263
case AxisDirection.left:
1264-
xOffset = viewportDimension.width - (layoutOffset.dx + paintExtent.width);
1264+
xOffset = viewportDimension.width - (layoutOffset.dx + child.size.width);
12651265
case AxisDirection.up:
12661266
case AxisDirection.down:
12671267
throw Exception('This should not happen');

packages/flutter/test/widgets/two_dimensional_viewport_test.dart

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,7 +1189,8 @@ void main() {
11891189
}, variant: TargetPlatformVariant.all());
11901190

11911191
testWidgets('sets up parent data', (WidgetTester tester) async {
1192-
// Also tests computeChildPaintOffset & computeChildPaintExtent
1192+
// Also tests computeAbsolutePaintOffsetFor & computeChildPaintExtent
1193+
// Regression test for https://github.com/flutter/flutter/issues/128723
11931194
final Map<ChildVicinity, UniqueKey> childKeys = <ChildVicinity, UniqueKey>{};
11941195
final TwoDimensionalChildBuilderDelegate delegate = TwoDimensionalChildBuilderDelegate(
11951196
maxXIndex: 5,
@@ -1250,7 +1251,7 @@ void main() {
12501251
childParentData = parentDataOf(viewport.lastChild!);
12511252
expect(childParentData.vicinity, const ChildVicinity(xIndex: 5, yIndex: 5));
12521253
expect(childParentData.isVisible, isFalse);
1253-
expect(childParentData.paintOffset, const Offset(1000.0, -400.0));
1254+
expect(childParentData.paintOffset, const Offset(1000.0, -600.0));
12541255
expect(childParentData.layoutOffset, const Offset(1000.0, 1000.0));
12551256

12561257
// - horizontal reverse
@@ -1271,7 +1272,7 @@ void main() {
12711272
childParentData = parentDataOf(viewport.lastChild!);
12721273
expect(childParentData.vicinity, const ChildVicinity(xIndex: 5, yIndex: 5));
12731274
expect(childParentData.isVisible, isFalse);
1274-
expect(childParentData.paintOffset, const Offset(-200.0, 1000.0));
1275+
expect(childParentData.paintOffset, const Offset(-400.0, 1000.0));
12751276
expect(childParentData.layoutOffset, const Offset(1000.0, 1000.0));
12761277

12771278
// - both reverse
@@ -1293,7 +1294,7 @@ void main() {
12931294
childParentData = parentDataOf(viewport.lastChild!);
12941295
expect(childParentData.vicinity, const ChildVicinity(xIndex: 5, yIndex: 5));
12951296
expect(childParentData.isVisible, isFalse);
1296-
expect(childParentData.paintOffset, const Offset(-200.0, -400.0));
1297+
expect(childParentData.paintOffset, const Offset(-400.0, -600.0));
12971298
expect(childParentData.layoutOffset, const Offset(1000.0, 1000.0));
12981299

12991300
// Change the scroll positions to test partially visible.

0 commit comments

Comments
 (0)