Skip to content

Commit a0862f1

Browse files
author
Jonah Williams
authored
[framework] use ImageFilter for stretch overscroll. (#133613)
Rather than changing the size of the child elements (relaying out text and potentially changing glyph shape and position due to pixel snapping), apply the stretch effect as a compositing effect - render the children to a texture and stretch the texture. If we end up using an image shader to apply an custom shader we'll need to do this anyway. Fixes flutter/flutter#129528 ### Before https://github.com/flutter/flutter/assets/8975114/16e9eb57-f864-4093-b4a4-461082b89b43 ### After https://github.com/flutter/flutter/assets/8975114/14cf0167-8922-4876-a325-e3bc154b084f
1 parent 5296f84 commit a0862f1

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -786,10 +786,10 @@ class _StretchingOverscrollIndicatorState extends State<StretchingOverscrollIndi
786786
);
787787

788788
final double viewportDimension = _lastOverscrollNotification?.metrics.viewportDimension ?? mainAxisSize;
789-
790789
final Widget transform = Transform(
791790
alignment: alignment,
792791
transform: Matrix4.diagonal3Values(x, y, 1.0),
792+
filterQuality: stretch == 0 ? null : FilterQuality.low,
793793
child: widget.child,
794794
);
795795

packages/flutter/test/widgets/overscroll_stretch_indicator_test.dart

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,4 +1124,29 @@ void main() {
11241124

11251125
await gesture.up();
11261126
});
1127+
1128+
testWidgets('Stretch overscroll only uses image filter during stretch effect', (WidgetTester tester) async {
1129+
final GlobalKey box1Key = GlobalKey();
1130+
final GlobalKey box2Key = GlobalKey();
1131+
final GlobalKey box3Key = GlobalKey();
1132+
final ScrollController controller = ScrollController();
1133+
await tester.pumpWidget(
1134+
buildTest(
1135+
box1Key,
1136+
box2Key,
1137+
box3Key,
1138+
controller,
1139+
axis: Axis.horizontal,
1140+
)
1141+
);
1142+
1143+
expect(tester.layers, isNot(contains(isA<ImageFilterLayer>())));
1144+
1145+
final TestGesture gesture = await tester.startGesture(tester.getCenter(find.byType(CustomScrollView)));
1146+
// Overscroll
1147+
await gesture.moveBy(const Offset(200.0, 0.0));
1148+
await tester.pumpAndSettle();
1149+
1150+
expect(tester.layers, contains(isA<ImageFilterLayer>()));
1151+
});
11271152
}

0 commit comments

Comments
 (0)