From d71bbfb490357eaf804c7e3abe0713b6bc94f221 Mon Sep 17 00:00:00 2001 From: Ian Hickson Date: Mon, 10 Jul 2023 23:44:33 -0700 Subject: [PATCH] Implement preferPaintInterior correctly for _CompoundBorder (#129851) --- .../flutter/lib/src/painting/borders.dart | 2 +- .../flutter/test/painting/border_test.dart | 67 +++++++++++++++++++ 2 files changed, 68 insertions(+), 1 deletion(-) diff --git a/packages/flutter/lib/src/painting/borders.dart b/packages/flutter/lib/src/painting/borders.dart index b96713cdfc..82282a6d88 100644 --- a/packages/flutter/lib/src/painting/borders.dart +++ b/packages/flutter/lib/src/painting/borders.dart @@ -840,7 +840,7 @@ class _CompoundBorder extends ShapeBorder { } @override - bool get preferPaintInterior => true; + bool get preferPaintInterior => borders.every((ShapeBorder border) => border.preferPaintInterior); @override void paint(Canvas canvas, Rect rect, { TextDirection? textDirection }) { diff --git a/packages/flutter/test/painting/border_test.dart b/packages/flutter/test/painting/border_test.dart index db0fdc4522..f2f2aebe5e 100644 --- a/packages/flutter/test/painting/border_test.dart +++ b/packages/flutter/test/painting/border_test.dart @@ -402,4 +402,71 @@ void main() { await tester.pumpWidget(buildWidget(border: allowedBorderDirectionalVariations, boxShape: BoxShape.circle)); expect(tester.takeException(), isNull); }); + + test('Compound borders with differing preferPaintInteriors', () { + expect(ShapeWithInterior().preferPaintInterior, isTrue); + expect(ShapeWithoutInterior().preferPaintInterior, isFalse); + expect((ShapeWithInterior() + ShapeWithInterior()).preferPaintInterior, isTrue); + expect((ShapeWithInterior() + ShapeWithoutInterior()).preferPaintInterior, isFalse); + expect((ShapeWithoutInterior() + ShapeWithInterior()).preferPaintInterior, isFalse); + expect((ShapeWithoutInterior() + ShapeWithoutInterior()).preferPaintInterior, isFalse); + }); +} + +class ShapeWithInterior extends ShapeBorder { + @override + bool get preferPaintInterior => true; + + @override + ShapeBorder scale(double t) { + return this; + } + + @override + EdgeInsetsGeometry get dimensions => EdgeInsets.zero; + + @override + Path getInnerPath(Rect rect, { TextDirection? textDirection }) { + return Path(); + } + + @override + Path getOuterPath(Rect rect, { TextDirection? textDirection }) { + return Path(); + } + + @override + void paintInterior(Canvas canvas, Rect rect, Paint paint, { TextDirection? textDirection }) { } + + @override + void paint(Canvas canvas, Rect rect, { TextDirection? textDirection }) { } +} + +class ShapeWithoutInterior extends ShapeBorder { + @override + bool get preferPaintInterior => false; + + @override + ShapeBorder scale(double t) { + return this; + } + + @override + EdgeInsetsGeometry get dimensions => EdgeInsets.zero; + + @override + Path getInnerPath(Rect rect, { TextDirection? textDirection }) { + return Path(); + } + + @override + Path getOuterPath(Rect rect, { TextDirection? textDirection }) { + return Path(); + } + + @override + void paintInterior(Canvas canvas, Rect rect, Paint paint, { TextDirection? textDirection }) { } + + @override + void paint(Canvas canvas, Rect rect, { TextDirection? textDirection }) { } }