Unverified Commit f85630b1 authored by Dan Field's avatar Dan Field Committed by GitHub

Fix RenderFittedBox when child.size.isEmpty (#35487)

parent 05b4c675
......@@ -3614,7 +3614,7 @@ class _SemanticsGeometry {
assert(transform != null);
if (rect == null)
return null;
if (rect.isEmpty)
if (rect.isEmpty || transform.isZero())
return Rect.zero;
return MatrixUtils.inverseTransformRect(transform, rect);
}
......
......@@ -2311,7 +2311,7 @@ class RenderFittedBox extends RenderProxyBox {
@override
bool hitTestChildren(BoxHitTestResult result, { Offset position }) {
if (size.isEmpty)
if (size.isEmpty || child?.size?.isEmpty == true)
return false;
_updatePaintData();
return result.addWithPaintTransform(
......@@ -2325,7 +2325,7 @@ class RenderFittedBox extends RenderProxyBox {
@override
void applyPaintTransform(RenderBox child, Matrix4 transform) {
if (size.isEmpty) {
if (size.isEmpty || child.size.isEmpty) {
transform.setZero();
} else {
_updatePaintData();
......
......@@ -15,6 +15,23 @@ import '../flutter_test_alternative.dart';
import 'rendering_tester.dart';
void main() {
test('RenderFittedBox handles applying paint transform and hit-testing with empty size', () {
final RenderFittedBox fittedBox = RenderFittedBox(
child: RenderCustomPaint(
preferredSize: Size.zero,
painter: TestCallbackPainter(onPaint: () {}),
),
);
layout(fittedBox, phase: EnginePhase.flushSemantics);
final Matrix4 transform = Matrix4.identity();
fittedBox.applyPaintTransform(fittedBox.child, transform);
expect(transform, Matrix4.zero());
final BoxHitTestResult hitTestResult = BoxHitTestResult();
expect(fittedBox.hitTestChildren(hitTestResult), isFalse);
});
test('RenderFittedBox does not paint with empty sizes', () {
bool painted;
RenderFittedBox makeFittedBox(Size size) {
......
......@@ -61,6 +61,25 @@ class _UpdateCountedClipPath extends ClipPath {
}
void main() {
testWidgets('ClipRect with a FittedBox child sized to zero works with semantics', (WidgetTester tester) async {
await tester.pumpWidget(Directionality(
textDirection: TextDirection.ltr,
child: ClipRect(
child: FittedBox(
child: SizedBox.fromSize(
size: Size.zero,
child: Semantics(
image: true,
label: 'Image',
),
),
),
),
),
);
expect(find.byType(FittedBox), findsOneWidget);
});
testWidgets('ClipRect updates clipBehavior in updateRenderObject', (WidgetTester tester) async {
await tester.pumpWidget(const _UpdateCountedClipRect());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment