diff --git a/packages/flutter_test/lib/src/controller.dart b/packages/flutter_test/lib/src/controller.dart index d5763135a6..9ab37a45ed 100644 --- a/packages/flutter_test/lib/src/controller.dart +++ b/packages/flutter_test/lib/src/controller.dart @@ -242,23 +242,29 @@ class SemanticsController { /// * [flutter/engine/AccessibilityBridge.java#SemanticsNode.isFocusable()](https://github.com/flutter/engine/blob/main/shell/platform/android/io/flutter/view/AccessibilityBridge.java#L2641) /// * [flutter/engine/SemanticsObject.mm#SemanticsObject.isAccessibilityElement](https://github.com/flutter/engine/blob/main/shell/platform/darwin/ios/framework/Source/SemanticsObject.mm#L449) bool _isImportantForAccessibility(SemanticsNode node) { + if (node.isMergedIntoParent) { + // If this node is merged, all its information are present on an ancestor + // node. + return false; + } + final SemanticsData data = node.getSemanticsData(); // If the node scopes a route, it doesn't matter what other flags/actions it // has, it is _not_ important for accessibility, so we short circuit. - if (node.hasFlag(SemanticsFlag.scopesRoute)) { + if (data.hasFlag(SemanticsFlag.scopesRoute)) { return false; } - final bool hasNonScrollingAction = node.getSemanticsData().actions & ~_scrollingActions != 0; + final bool hasNonScrollingAction = data.actions & ~_scrollingActions != 0; if (hasNonScrollingAction) { return true; } - final bool hasImportantFlag = node.getSemanticsData().flags & _importantFlagsForAccessibility != 0; + final bool hasImportantFlag = data.flags & _importantFlagsForAccessibility != 0; if (hasImportantFlag) { return true; } - final bool hasContent = node.label.isNotEmpty || node.value.isNotEmpty || node.hint.isNotEmpty; + final bool hasContent = data.label.isNotEmpty || data.value.isNotEmpty || data.hint.isNotEmpty; if (hasContent) { return true; } diff --git a/packages/flutter_test/test/controller_test.dart b/packages/flutter_test/test/controller_test.dart index 0337264f36..c2ca9c9324 100644 --- a/packages/flutter_test/test/controller_test.dart +++ b/packages/flutter_test/test/controller_test.dart @@ -982,6 +982,38 @@ void main() { tester.semantics.simulatedAccessibilityTraversal(), containsAllInOrder(expectedMatchers)); }); + + testWidgets('merging node should not be visited', (WidgetTester tester) async { + await tester.pumpWidget( + MaterialApp( + home: MergeSemantics( + child: Column( + children: [ + Semantics( + container: true, + child: const Text('1'), + ), + Semantics( + container: true, + child: const Text('2'), + ), + Semantics( + container: true, + child: const Text('3'), + ), + ], + ), + ), + ), + ); + + expect( + tester.semantics.simulatedAccessibilityTraversal(), + orderedEquals( + [containsSemantics(label: '1\n2\n3')], + ), + ); + }); }); }); }