Skip to content

Commit 243413f

Browse files
authored
Add role check in SemanticsNode._isDifferentFromCurrentSemanticAnnotation function. (#162578)
Fixes flutter/flutter#162577 ### Description - Adds `role` check in `SemanticsNode._isDifferentFromCurrentSemanticAnnotation` function. - Adds `SemanticsNode.debugIsDirty` property to check in tests whether the node is marked as dirty. ## Pre-launch Checklist - [X] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [X] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [X] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [X] I signed the [CLA]. - [X] I listed at least one issue that this PR fixes in the description above. - [ ] I updated/added relevant documentation (doc comments with `///`). - [X] I added new tests to check the change I am making, or this PR is [test-exempt]. - [X] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [X] All existing and new tests are passing.
1 parent ce6817b commit 243413f

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

packages/flutter/lib/src/semantics/semantics.dart

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2429,6 +2429,22 @@ class SemanticsNode with DiagnosticableTreeMixin {
24292429
}
24302430
}
24312431

2432+
/// When asserts are enabled, returns whether node is marked as dirty.
2433+
///
2434+
/// Otherwise, returns null.
2435+
///
2436+
/// This getter is intended for use in framework unit tests. Applications must
2437+
/// not depend on its value.
2438+
@visibleForTesting
2439+
bool? get debugIsDirty {
2440+
bool? isDirty;
2441+
assert(() {
2442+
isDirty = _dirty;
2443+
return true;
2444+
}());
2445+
return isDirty;
2446+
}
2447+
24322448
bool _isDifferentFromCurrentSemanticAnnotation(SemanticsConfiguration config) {
24332449
return _attributedLabel != config.attributedLabel ||
24342450
_attributedHint != config.attributedHint ||
@@ -2454,7 +2470,7 @@ class SemanticsNode with DiagnosticableTreeMixin {
24542470
_areUserActionsBlocked != config.isBlockingUserActions ||
24552471
_headingLevel != config._headingLevel ||
24562472
_linkUrl != config._linkUrl ||
2457-
_linkUrl != config._linkUrl;
2473+
_role != config.role;
24582474
}
24592475

24602476
// TAGS, LABELS, ACTIONS

packages/flutter/test/semantics/semantics_test.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,19 @@ void main() {
464464
expect(root.debugSemantics!.getSemanticsData().actions, expectedActions);
465465
},
466466
);
467+
468+
test('updateWith marks node as dirty when role changes', () {
469+
final SemanticsNode node = SemanticsNode();
470+
471+
expect(node.role, SemanticsRole.none);
472+
expect(node.debugIsDirty, isFalse);
473+
474+
final SemanticsConfiguration config = SemanticsConfiguration()..role = SemanticsRole.tab;
475+
node.updateWith(config: config);
476+
477+
expect(node.role, config.role);
478+
expect(node.debugIsDirty, isTrue);
479+
});
467480
});
468481

469482
test('toStringDeep() does not throw with transform == null', () {

0 commit comments

Comments
 (0)