Skip to content

Commit

Permalink
zero-sized RenderConstraintsTransformBox respects clipBehavior (#147349)
Browse files Browse the repository at this point in the history
  • Loading branch information
LongCatIsLooong authored Apr 26, 2024
1 parent 014cf33 commit 101ff6f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
7 changes: 4 additions & 3 deletions packages/flutter/lib/src/rendering/shifted_box.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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);
Expand Down
17 changes: 17 additions & 0 deletions packages/flutter/test/rendering/box_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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', () {
Expand Down

0 comments on commit 101ff6f

Please sign in to comment.