From 101ff6fe7d34fe26e158d0e46a727e889c2f92d9 Mon Sep 17 00:00:00 2001 From: LongCatIsLooong <31859944+LongCatIsLooong@users.noreply.github.com> Date: Fri, 26 Apr 2024 12:06:09 +0800 Subject: [PATCH] zero-sized RenderConstraintsTransformBox respects clipBehavior (#147349) Fixes https://github.com/flutter/flutter/issues/146840 --- .../flutter/lib/src/rendering/shifted_box.dart | 7 ++++--- packages/flutter/test/rendering/box_test.dart | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/packages/flutter/lib/src/rendering/shifted_box.dart b/packages/flutter/lib/src/rendering/shifted_box.dart index 4b8ec8b5c0..735b613257 100644 --- a/packages/flutter/lib/src/rendering/shifted_box.dart +++ b/packages/flutter/lib/src/rendering/shifted_box.dart @@ -896,9 +896,7 @@ class RenderConstraintsTransformBox extends RenderAligningShiftedBox with DebugO @override void paint(PaintingContext context, Offset offset) { - // There's no point in drawing the child if we're empty, or there is no - // child. - if (child == null || size.isEmpty) { + if (child == null) { return; } @@ -919,6 +917,9 @@ class RenderConstraintsTransformBox extends RenderAligningShiftedBox with DebugO // Display the overflow indicator if clipBehavior is Clip.none. assert(() { + if (size.isEmpty) { + return true; + } switch (clipBehavior) { case Clip.none: paintOverflowIndicator(context, offset, _overflowContainerRect, _overflowChildRect); diff --git a/packages/flutter/test/rendering/box_test.dart b/packages/flutter/test/rendering/box_test.dart index 25a11b7d55..015e72465e 100644 --- a/packages/flutter/test/rendering/box_test.dart +++ b/packages/flutter/test/rendering/box_test.dart @@ -503,6 +503,23 @@ void main() { // At least 2 lines. expect(constrainedHeight, greaterThanOrEqualTo(2 * unconstrainedHeight)); }); + + test('paints even when its size is empty', () { + // Regression test for https://github.com/flutter/flutter/issues/146840. + final RenderParagraph child = RenderParagraph( + const TextSpan(text: ''), + textDirection: TextDirection.ltr, + ); + final RenderConstraintsTransformBox box = RenderConstraintsTransformBox( + alignment: Alignment.center, + textDirection: TextDirection.ltr, + constraintsTransform: (BoxConstraints constraints) => constraints.copyWith(maxWidth: double.infinity), + child: child, + ); + + layout(box, constraints: BoxConstraints.tight(Size.zero), phase: EnginePhase.paint); + expect(box, paints..paragraph()); + }); }); test ('getMinIntrinsicWidth error handling', () {