Skip to content

Commit 101ff6f

Browse files
zero-sized RenderConstraintsTransformBox respects clipBehavior (#147349)
Fixes flutter/flutter#146840
1 parent 014cf33 commit 101ff6f

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

packages/flutter/lib/src/rendering/shifted_box.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -896,9 +896,7 @@ class RenderConstraintsTransformBox extends RenderAligningShiftedBox with DebugO
896896

897897
@override
898898
void paint(PaintingContext context, Offset offset) {
899-
// There's no point in drawing the child if we're empty, or there is no
900-
// child.
901-
if (child == null || size.isEmpty) {
899+
if (child == null) {
902900
return;
903901
}
904902

@@ -919,6 +917,9 @@ class RenderConstraintsTransformBox extends RenderAligningShiftedBox with DebugO
919917

920918
// Display the overflow indicator if clipBehavior is Clip.none.
921919
assert(() {
920+
if (size.isEmpty) {
921+
return true;
922+
}
922923
switch (clipBehavior) {
923924
case Clip.none:
924925
paintOverflowIndicator(context, offset, _overflowContainerRect, _overflowChildRect);

packages/flutter/test/rendering/box_test.dart

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,23 @@ void main() {
503503
// At least 2 lines.
504504
expect(constrainedHeight, greaterThanOrEqualTo(2 * unconstrainedHeight));
505505
});
506+
507+
test('paints even when its size is empty', () {
508+
// Regression test for https://github.com/flutter/flutter/issues/146840.
509+
final RenderParagraph child = RenderParagraph(
510+
const TextSpan(text: ''),
511+
textDirection: TextDirection.ltr,
512+
);
513+
final RenderConstraintsTransformBox box = RenderConstraintsTransformBox(
514+
alignment: Alignment.center,
515+
textDirection: TextDirection.ltr,
516+
constraintsTransform: (BoxConstraints constraints) => constraints.copyWith(maxWidth: double.infinity),
517+
child: child,
518+
);
519+
520+
layout(box, constraints: BoxConstraints.tight(Size.zero), phase: EnginePhase.paint);
521+
expect(box, paints..paragraph());
522+
});
506523
});
507524

508525
test ('getMinIntrinsicWidth error handling', () {

0 commit comments

Comments
 (0)