diff --git a/packages/flutter/lib/src/rendering/proxy_box.dart b/packages/flutter/lib/src/rendering/proxy_box.dart index e593f59641b6..1a694486aaf4 100644 --- a/packages/flutter/lib/src/rendering/proxy_box.dart +++ b/packages/flutter/lib/src/rendering/proxy_box.dart @@ -1404,8 +1404,15 @@ abstract class _RenderCustomClip extends RenderProxyBox { } @override - Rect describeApproximatePaintClip(RenderObject child) { - return _clipper?.getApproximateClipRect(size) ?? Offset.zero & size; + Rect? describeApproximatePaintClip(RenderObject child) { + switch (clipBehavior) { + case Clip.none: + return null; + case Clip.hardEdge: + case Clip.antiAlias: + case Clip.antiAliasWithSaveLayer: + return _clipper?.getApproximateClipRect(size) ?? Offset.zero & size; + } } Paint? _debugPaint; diff --git a/packages/flutter/test/rendering/proxy_box_test.dart b/packages/flutter/test/rendering/proxy_box_test.dart index 1d6eaec5663c..edae97a7abab 100644 --- a/packages/flutter/test/rendering/proxy_box_test.dart +++ b/packages/flutter/test/rendering/proxy_box_test.dart @@ -686,6 +686,31 @@ void main() { expect(() => pumpFrame(phase: EnginePhase.composite), returnsNormally); }); + + test('RenderCustomClip extenders respect clipBehavior when asked to describeApproximateClip', () { + final RenderBox child = RenderConstrainedBox(additionalConstraints: const BoxConstraints.tightFor(width: 200, height: 200)); + final RenderClipRect renderClipRect = RenderClipRect(clipBehavior: Clip.none, child: child); + layout(renderClipRect); + expect( + renderClipRect.describeApproximatePaintClip(child), + null, + ); + renderClipRect.clipBehavior = Clip.hardEdge; + expect( + renderClipRect.describeApproximatePaintClip(child), + Offset.zero & renderClipRect.size, + ); + renderClipRect.clipBehavior = Clip.antiAlias; + expect( + renderClipRect.describeApproximatePaintClip(child), + Offset.zero & renderClipRect.size, + ); + renderClipRect.clipBehavior = Clip.antiAliasWithSaveLayer; + expect( + renderClipRect.describeApproximatePaintClip(child), + Offset.zero & renderClipRect.size, + ); + }); } class _TestRectClipper extends CustomClipper {