Skip to content

Commit 36a5a0f

Browse files
authored
Avoid sending zero transform semantic nodes to the engine (#111843)
1 parent 70b19ff commit 36a5a0f

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4433,7 +4433,7 @@ class _SemanticsGeometry {
44334433
/// by this object can be dropped from the semantics tree without losing
44344434
/// semantics information.
44354435
bool get dropFromTree {
4436-
return _rect.isEmpty;
4436+
return _rect.isEmpty || _transform.isZero();
44374437
}
44384438

44394439
/// Whether the [SemanticsNode] annotated with the geometric information

packages/flutter/test/widgets/semantics_test.dart

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1632,6 +1632,33 @@ void main() {
16321632
textDirection: TextDirection.ltr,
16331633
));
16341634
});
1635+
1636+
testWidgets('Semantics with zero transform gets dropped', (WidgetTester tester) async {
1637+
// Regression test for https://github.com/flutter/flutter/issues/110671.
1638+
// Construct a widget tree that will end up with a fitted box that applies
1639+
// a zero transform because it does not actually draw its children.
1640+
// Assert that this subtree gets dropped (the root node has no children).
1641+
await tester.pumpWidget(Column(
1642+
children: <Widget>[
1643+
SizedBox(
1644+
height: 0,
1645+
width: 500,
1646+
child: FittedBox(
1647+
child: SizedBox(
1648+
height: 55,
1649+
width: 266,
1650+
child: SingleChildScrollView(child: Column()),
1651+
),
1652+
),
1653+
),
1654+
],
1655+
));
1656+
1657+
final SemanticsNode node = RendererBinding.instance.renderView.debugSemantics!;
1658+
1659+
expect(node.transform, null); // Make sure the zero transform didn't end up on the root somehow.
1660+
expect(node.childrenCount, 0);
1661+
});
16351662
}
16361663

16371664
class CustomSortKey extends OrdinalSortKey {

0 commit comments

Comments
 (0)