diff --git a/packages/flutter/lib/src/rendering/shifted_box.dart b/packages/flutter/lib/src/rendering/shifted_box.dart index 4b8ec8b5c0f2..735b613257e3 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 25a11b7d55aa..015e72465e04 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', () {