Relax assertion for adding semantics locale (#178140)

<!--
Thanks for filing a pull request!
Reviewers are typically assigned within a week of filing a request.
To learn more about code review, see our documentation on Tree Hygiene:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
-->

instead forcing a contain: true, uses isCompatibleWith to prevent
implicit merge

## Pre-launch Checklist

- [ ] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [ ] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [ ] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [ ] I signed the [CLA].
- [ ] I listed at least one issue that this PR fixes in the description
above.
- [ ] I updated/added relevant documentation (doc comments with `///`).
- [ ] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [ ] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [ ] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

**Note**: The Flutter team is currently trialing the use of [Gemini Code
Assist for
GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code).
Comments from the `gemini-code-assist` bot should not be taken as
authoritative feedback from the Flutter team. If you find its comments
useful you can update your code accordingly, but if you are unsure or
disagree with the feedback, please feel free to wait for a Flutter team
member's review for guidance on which automated comments should be
addressed.

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
This commit is contained in:
chunhtai 2025-12-09 12:46:18 -08:00 committed by GitHub
parent 8cdb466a8a
commit 2e2d655be8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 913 additions and 700 deletions

View File

@ -4789,7 +4789,9 @@ mixin SemanticsAnnotationsMixin on RenderObject {
config.isSemanticBoundary = container;
config.explicitChildNodes = explicitChildNodes;
config.isBlockingUserActions = blockUserActions;
config.localeForSubtree = localeForSubtree;
if (localeForSubtree != null) {
config.localeForSubtree = localeForSubtree;
}
assert(
((_properties.scopesRoute ?? false) && explicitChildNodes) ||
!(_properties.scopesRoute ?? false),

View File

@ -5006,12 +5006,9 @@ class SemanticsConfiguration {
Locale? get localeForSubtree => _localeForSubtree;
Locale? _localeForSubtree;
set localeForSubtree(Locale? value) {
assert(
value == null || _isSemanticBoundary,
'to set locale for subtree, this configuration must also be a semantics '
'boundary.',
);
assert(value != null);
_localeForSubtree = value;
_hasBeenAnnotated = true;
}
/// The locale of the resulting semantics node if this configuration formed
@ -6520,6 +6517,9 @@ class SemanticsConfiguration {
if (_attributedValue.string.isNotEmpty && other._attributedValue.string.isNotEmpty) {
return false;
}
if (_localeForSubtree != other._localeForSubtree) {
return false;
}
if (_hasExplicitRole && other._hasExplicitRole) {
return false;
}

View File

@ -4150,11 +4150,7 @@ sealed class _SemanticsBase extends SingleChildRenderObjectWidget {
required this.blockUserActions,
required this.localeForSubtree,
required this.properties,
}) : assert(
localeForSubtree == null || container,
'To assign locale for subtree, this widget needs to be a '
'container',
);
});
/// Contains properties used by assistive technologies to make the application
/// more accessible.

View File

@ -1465,6 +1465,7 @@ void main() {
label: 'Flexible Space',
textDirection: TextDirection.ltr,
),
TestSemantics(
id: 7,
flags: <SemanticsFlag>[

View File

@ -1453,75 +1453,84 @@ void main() {
TestSemantics.root(
children: <TestSemantics>[
TestSemantics.rootChild(
actions: <SemanticsAction>[SemanticsAction.tap, SemanticsAction.dismiss],
label: 'Dismiss',
textDirection: TextDirection.ltr,
children: <TestSemantics>[
TestSemantics(
role: SemanticsRole.menu,
flags: <SemanticsFlag>[SemanticsFlag.scopesRoute, SemanticsFlag.namesRoute],
label: 'Popup menu',
children: <TestSemantics>[
TestSemantics(
role: SemanticsRole.menu,
flags: <SemanticsFlag>[SemanticsFlag.scopesRoute, SemanticsFlag.namesRoute],
label: 'Popup menu',
children: <TestSemantics>[
TestSemantics(
flags: <SemanticsFlag>[SemanticsFlag.hasImplicitScrolling],
children: <TestSemantics>[
TestSemantics(
role: SemanticsRole.menuItem,
label: 'one',
textDirection: TextDirection.ltr,
flags: <SemanticsFlag>[
SemanticsFlag.isButton,
SemanticsFlag.isFocused,
SemanticsFlag.isFocusable,
],
tags: <SemanticsTag>[const SemanticsTag('RenderViewport.twoPane')],
actions: <SemanticsAction>[
SemanticsAction.tap,
SemanticsAction.focus,
],
),
TestSemantics(
role: SemanticsRole.menuItem,
label: 'two',
textDirection: TextDirection.ltr,
flags: <SemanticsFlag>[
SemanticsFlag.isButton,
SemanticsFlag.isFocusable,
],
tags: <SemanticsTag>[const SemanticsTag('RenderViewport.twoPane')],
actions: <SemanticsAction>[
SemanticsAction.tap,
SemanticsAction.focus,
],
),
TestSemantics(
role: SemanticsRole.menuItem,
label: 'three',
textDirection: TextDirection.ltr,
flags: <SemanticsFlag>[
SemanticsFlag.isButton,
SemanticsFlag.isFocusable,
],
tags: <SemanticsTag>[const SemanticsTag('RenderViewport.twoPane')],
actions: <SemanticsAction>[
SemanticsAction.tap,
SemanticsAction.focus,
],
),
TestSemantics(
role: SemanticsRole.menuItem,
label: 'four',
textDirection: TextDirection.ltr,
flags: <SemanticsFlag>[
SemanticsFlag.isButton,
SemanticsFlag.isFocusable,
],
tags: <SemanticsTag>[const SemanticsTag('RenderViewport.twoPane')],
actions: <SemanticsAction>[
SemanticsAction.tap,
SemanticsAction.focus,
flags: <SemanticsFlag>[SemanticsFlag.hasImplicitScrolling],
children: <TestSemantics>[
TestSemantics(
role: SemanticsRole.menuItem,
label: 'one',
textDirection: TextDirection.ltr,
flags: <SemanticsFlag>[
SemanticsFlag.isButton,
SemanticsFlag.isFocused,
SemanticsFlag.isFocusable,
],
tags: <SemanticsTag>[
const SemanticsTag('RenderViewport.twoPane'),
],
actions: <SemanticsAction>[
SemanticsAction.tap,
SemanticsAction.focus,
],
),
TestSemantics(
role: SemanticsRole.menuItem,
label: 'two',
textDirection: TextDirection.ltr,
flags: <SemanticsFlag>[
SemanticsFlag.isButton,
SemanticsFlag.isFocusable,
],
tags: <SemanticsTag>[
const SemanticsTag('RenderViewport.twoPane'),
],
actions: <SemanticsAction>[
SemanticsAction.tap,
SemanticsAction.focus,
],
),
TestSemantics(
role: SemanticsRole.menuItem,
label: 'three',
textDirection: TextDirection.ltr,
flags: <SemanticsFlag>[
SemanticsFlag.isButton,
SemanticsFlag.isFocusable,
],
tags: <SemanticsTag>[
const SemanticsTag('RenderViewport.twoPane'),
],
actions: <SemanticsAction>[
SemanticsAction.tap,
SemanticsAction.focus,
],
),
TestSemantics(
role: SemanticsRole.menuItem,
label: 'four',
textDirection: TextDirection.ltr,
flags: <SemanticsFlag>[
SemanticsFlag.isButton,
SemanticsFlag.isFocusable,
],
tags: <SemanticsTag>[
const SemanticsTag('RenderViewport.twoPane'),
],
actions: <SemanticsAction>[
SemanticsAction.tap,
SemanticsAction.focus,
],
),
],
),
],
@ -1530,6 +1539,11 @@ void main() {
),
],
),
TestSemantics(
actions: <SemanticsAction>[SemanticsAction.tap, SemanticsAction.dismiss],
label: 'Dismiss',
textDirection: TextDirection.ltr,
),
],
),
],

View File

@ -6196,10 +6196,14 @@ TestSemantics _expectedSemantics({bool scrollable = false}) {
TestSemantics(
children: <TestSemantics>[
TestSemantics(
flags: <SemanticsFlag>[SemanticsFlag.scopesRoute],
children: <TestSemantics>[
TestSemantics(children: destinations),
TestSemantics(label: 'body', textDirection: TextDirection.ltr),
TestSemantics(
flags: <SemanticsFlag>[SemanticsFlag.scopesRoute],
children: <TestSemantics>[
TestSemantics(children: destinations),
TestSemantics(label: 'body', textDirection: TextDirection.ltr),
],
),
],
),
],

View File

@ -6078,12 +6078,9 @@ void main() {
final expectedSemantics = TestSemantics.root(
children: <TestSemantics>[
TestSemantics.rootChild(
label: 'Tab 1 of 2',
id: 1,
rect: TestSemantics.fullScreen,
children: <TestSemantics>[
TestSemantics(
id: 2,
role: SemanticsRole.tabBar,
children: <TestSemantics>[
TestSemantics(
@ -6093,7 +6090,6 @@ void main() {
SemanticsFlag.isSelected,
SemanticsFlag.hasSelectedState,
],
id: 3,
rect: TestSemantics.fullScreen,
actions: 1 | SemanticsAction.focus.index,
role: SemanticsRole.tab,
@ -6101,7 +6097,6 @@ void main() {
TestSemantics(
label: 'TAB2${kIsWeb ? '' : '\nTab 2 of 2'}',
flags: <SemanticsFlag>[SemanticsFlag.isFocusable, SemanticsFlag.hasSelectedState],
id: 4,
rect: TestSemantics.fullScreen,
actions: <SemanticsAction>[SemanticsAction.tap, SemanticsAction.focus],
role: SemanticsRole.tab,
@ -6109,16 +6104,13 @@ void main() {
],
),
TestSemantics(
id: 5,
rect: TestSemantics.fullScreen,
children: <TestSemantics>[
TestSemantics(
id: 7,
rect: TestSemantics.fullScreen,
actions: <SemanticsAction>[SemanticsAction.scrollLeft],
children: <TestSemantics>[
TestSemantics(
id: 6,
rect: TestSemantics.fullScreen,
label: 'PAGE1',
role: SemanticsRole.tabPanel,
@ -6127,12 +6119,16 @@ void main() {
),
],
),
TestSemantics(label: 'Tab 1 of 2', textDirection: TextDirection.ltr),
],
),
],
);
expect(semantics, hasSemantics(expectedSemantics, ignoreRect: true, ignoreTransform: true));
expect(
semantics,
hasSemantics(expectedSemantics, ignoreRect: true, ignoreTransform: true, ignoreId: true),
);
semantics.dispose();
});

File diff suppressed because it is too large Load Diff

View File

@ -1617,21 +1617,22 @@ void main() {
TestSemantics.root(
children: <TestSemantics>[
TestSemantics.rootChild(
id: 1,
actions: <SemanticsAction>[SemanticsAction.longPress],
textDirection: TextDirection.ltr,
inputType: ui.SemanticsInputType.text,
children: <TestSemantics>[
TestSemantics(
id: 2,
actions: <SemanticsAction>[SemanticsAction.longPress],
inputType: ui.SemanticsInputType.text,
children: <TestSemantics>[
TestSemantics(id: 3, label: 'text', textDirection: TextDirection.ltr),
TestSemantics(
id: 4,
flags: <SemanticsFlag>[SemanticsFlag.isLink],
actions: <SemanticsAction>[SemanticsAction.tap],
label: 'link',
textDirection: TextDirection.ltr,
children: <TestSemantics>[
TestSemantics(label: 'text', textDirection: TextDirection.ltr),
TestSemantics(
flags: <SemanticsFlag>[SemanticsFlag.isLink],
actions: <SemanticsAction>[SemanticsAction.tap],
label: 'link',
textDirection: TextDirection.ltr,
),
],
),
],
),
@ -1639,6 +1640,7 @@ void main() {
),
],
),
ignoreId: true,
ignoreTransform: true,
ignoreRect: true,
),
@ -2166,20 +2168,24 @@ void main() {
TestSemantics.root(
children: <TestSemantics>[
TestSemantics.rootChild(
id: 1,
textDirection: TextDirection.ltr,
value: 'Guten Tag',
actions: <SemanticsAction>[SemanticsAction.longPress],
inputType: ui.SemanticsInputType.text,
flags: <SemanticsFlag>[
SemanticsFlag.isTextField,
SemanticsFlag.isFocusable,
SemanticsFlag.isReadOnly,
SemanticsFlag.isMultiline,
children: <TestSemantics>[
TestSemantics.rootChild(
textDirection: TextDirection.ltr,
value: 'Guten Tag',
actions: <SemanticsAction>[SemanticsAction.longPress],
inputType: ui.SemanticsInputType.text,
flags: <SemanticsFlag>[
SemanticsFlag.isTextField,
SemanticsFlag.isFocusable,
SemanticsFlag.isReadOnly,
SemanticsFlag.isMultiline,
],
),
],
),
],
),
ignoreId: true,
ignoreTransform: true,
ignoreRect: true,
),
@ -2197,27 +2203,31 @@ void main() {
TestSemantics.root(
children: <TestSemantics>[
TestSemantics.rootChild(
id: 1,
textDirection: TextDirection.ltr,
value: 'Guten Tag',
textSelection: const TextSelection.collapsed(offset: 9),
inputType: ui.SemanticsInputType.text,
actions: <SemanticsAction>[
SemanticsAction.longPress,
SemanticsAction.moveCursorBackwardByCharacter,
SemanticsAction.moveCursorBackwardByWord,
SemanticsAction.setSelection,
],
flags: <SemanticsFlag>[
SemanticsFlag.isReadOnly,
SemanticsFlag.isTextField,
SemanticsFlag.isFocusable,
SemanticsFlag.isMultiline,
SemanticsFlag.isFocused,
children: <TestSemantics>[
TestSemantics(
textDirection: TextDirection.ltr,
value: 'Guten Tag',
textSelection: const TextSelection.collapsed(offset: 9),
inputType: ui.SemanticsInputType.text,
actions: <SemanticsAction>[
SemanticsAction.longPress,
SemanticsAction.moveCursorBackwardByCharacter,
SemanticsAction.moveCursorBackwardByWord,
SemanticsAction.setSelection,
],
flags: <SemanticsFlag>[
SemanticsFlag.isReadOnly,
SemanticsFlag.isTextField,
SemanticsFlag.isFocusable,
SemanticsFlag.isMultiline,
SemanticsFlag.isFocused,
],
),
],
),
],
),
ignoreId: true,
ignoreTransform: true,
ignoreRect: true,
),
@ -2232,29 +2242,33 @@ void main() {
TestSemantics.root(
children: <TestSemantics>[
TestSemantics.rootChild(
id: 1,
textDirection: TextDirection.ltr,
textSelection: const TextSelection.collapsed(offset: 4),
value: 'Guten Tag',
inputType: ui.SemanticsInputType.text,
actions: <SemanticsAction>[
SemanticsAction.longPress,
SemanticsAction.moveCursorBackwardByCharacter,
SemanticsAction.moveCursorForwardByCharacter,
SemanticsAction.moveCursorBackwardByWord,
SemanticsAction.moveCursorForwardByWord,
SemanticsAction.setSelection,
],
flags: <SemanticsFlag>[
SemanticsFlag.isReadOnly,
SemanticsFlag.isTextField,
SemanticsFlag.isFocusable,
SemanticsFlag.isMultiline,
SemanticsFlag.isFocused,
children: <TestSemantics>[
TestSemantics(
textDirection: TextDirection.ltr,
textSelection: const TextSelection.collapsed(offset: 4),
value: 'Guten Tag',
inputType: ui.SemanticsInputType.text,
actions: <SemanticsAction>[
SemanticsAction.longPress,
SemanticsAction.moveCursorBackwardByCharacter,
SemanticsAction.moveCursorForwardByCharacter,
SemanticsAction.moveCursorBackwardByWord,
SemanticsAction.moveCursorForwardByWord,
SemanticsAction.setSelection,
],
flags: <SemanticsFlag>[
SemanticsFlag.isReadOnly,
SemanticsFlag.isTextField,
SemanticsFlag.isFocusable,
SemanticsFlag.isMultiline,
SemanticsFlag.isFocused,
],
),
],
),
],
),
ignoreId: true,
ignoreTransform: true,
ignoreRect: true,
),
@ -2269,27 +2283,31 @@ void main() {
TestSemantics.root(
children: <TestSemantics>[
TestSemantics.rootChild(
id: 1,
textDirection: TextDirection.ltr,
textSelection: const TextSelection.collapsed(offset: 0),
value: 'Guten Tag',
inputType: ui.SemanticsInputType.text,
actions: <SemanticsAction>[
SemanticsAction.longPress,
SemanticsAction.moveCursorForwardByCharacter,
SemanticsAction.moveCursorForwardByWord,
SemanticsAction.setSelection,
],
flags: <SemanticsFlag>[
SemanticsFlag.isReadOnly,
SemanticsFlag.isTextField,
SemanticsFlag.isFocusable,
SemanticsFlag.isMultiline,
SemanticsFlag.isFocused,
children: <TestSemantics>[
TestSemantics(
textDirection: TextDirection.ltr,
textSelection: const TextSelection.collapsed(offset: 0),
value: 'Guten Tag',
inputType: ui.SemanticsInputType.text,
actions: <SemanticsAction>[
SemanticsAction.longPress,
SemanticsAction.moveCursorForwardByCharacter,
SemanticsAction.moveCursorForwardByWord,
SemanticsAction.setSelection,
],
flags: <SemanticsFlag>[
SemanticsFlag.isReadOnly,
SemanticsFlag.isTextField,
SemanticsFlag.isFocusable,
SemanticsFlag.isMultiline,
SemanticsFlag.isFocused,
],
),
],
),
],
),
ignoreId: true,
ignoreTransform: true,
ignoreRect: true,
),
@ -2317,14 +2335,18 @@ void main() {
hasSemantics(
TestSemantics.root(
children: <TestSemantics>[
TestSemantics(
id: 1,
actions: <SemanticsAction>[SemanticsAction.longPress],
label: 'German greeting for good day',
textDirection: TextDirection.ltr,
TestSemantics.rootChild(
children: <TestSemantics>[
TestSemantics(
actions: <SemanticsAction>[SemanticsAction.longPress],
label: 'German greeting for good day',
textDirection: TextDirection.ltr,
),
],
),
],
),
ignoreId: true,
ignoreTransform: true,
ignoreRect: true,
),
@ -2351,30 +2373,34 @@ void main() {
TestSemantics.root(
children: <TestSemantics>[
TestSemantics.rootChild(
id: 1,
value: 'Guten Tag',
textDirection: TextDirection.ltr,
inputType: ui.SemanticsInputType.text,
actions: <SemanticsAction>[
SemanticsAction.longPress,
// Absent the following because enableInteractiveSelection: false
// SemanticsAction.moveCursorBackwardByCharacter,
// SemanticsAction.moveCursorBackwardByWord,
// SemanticsAction.setSelection,
// SemanticsAction.paste,
],
flags: <SemanticsFlag>[
SemanticsFlag.isReadOnly,
SemanticsFlag.isTextField,
SemanticsFlag.isFocusable,
SemanticsFlag.isMultiline,
// SelectableText act like a text widget when enableInteractiveSelection
// is false. It will not respond to any pointer event.
// SemanticsFlag.isFocused,
children: <TestSemantics>[
TestSemantics(
value: 'Guten Tag',
textDirection: TextDirection.ltr,
inputType: ui.SemanticsInputType.text,
actions: <SemanticsAction>[
SemanticsAction.longPress,
// Absent the following because enableInteractiveSelection: false
// SemanticsAction.moveCursorBackwardByCharacter,
// SemanticsAction.moveCursorBackwardByWord,
// SemanticsAction.setSelection,
// SemanticsAction.paste,
],
flags: <SemanticsFlag>[
SemanticsFlag.isReadOnly,
SemanticsFlag.isTextField,
SemanticsFlag.isFocusable,
SemanticsFlag.isMultiline,
// SelectableText act like a text widget when enableInteractiveSelection
// is false. It will not respond to any pointer event.
// SemanticsFlag.isFocused,
],
),
],
),
],
),
ignoreId: true,
ignoreTransform: true,
ignoreRect: true,
),
@ -2398,20 +2424,24 @@ void main() {
TestSemantics.root(
children: <TestSemantics>[
TestSemantics.rootChild(
id: 1,
value: 'Hello',
textDirection: TextDirection.ltr,
inputType: ui.SemanticsInputType.text,
actions: <SemanticsAction>[SemanticsAction.longPress],
flags: <SemanticsFlag>[
SemanticsFlag.isReadOnly,
SemanticsFlag.isTextField,
SemanticsFlag.isFocusable,
SemanticsFlag.isMultiline,
children: <TestSemantics>[
TestSemantics(
value: 'Hello',
textDirection: TextDirection.ltr,
inputType: ui.SemanticsInputType.text,
actions: <SemanticsAction>[SemanticsAction.longPress],
flags: <SemanticsFlag>[
SemanticsFlag.isReadOnly,
SemanticsFlag.isTextField,
SemanticsFlag.isFocusable,
SemanticsFlag.isMultiline,
],
),
],
),
],
),
ignoreId: true,
ignoreTransform: true,
ignoreRect: true,
),
@ -2430,27 +2460,31 @@ void main() {
TestSemantics.root(
children: <TestSemantics>[
TestSemantics.rootChild(
id: 1,
value: 'Hello',
textSelection: const TextSelection.collapsed(offset: 5),
textDirection: TextDirection.ltr,
inputType: ui.SemanticsInputType.text,
actions: <SemanticsAction>[
SemanticsAction.longPress,
SemanticsAction.moveCursorBackwardByCharacter,
SemanticsAction.moveCursorBackwardByWord,
SemanticsAction.setSelection,
],
flags: <SemanticsFlag>[
SemanticsFlag.isReadOnly,
SemanticsFlag.isTextField,
SemanticsFlag.isFocusable,
SemanticsFlag.isMultiline,
SemanticsFlag.isFocused,
children: <TestSemantics>[
TestSemantics(
value: 'Hello',
textSelection: const TextSelection.collapsed(offset: 5),
textDirection: TextDirection.ltr,
inputType: ui.SemanticsInputType.text,
actions: <SemanticsAction>[
SemanticsAction.longPress,
SemanticsAction.moveCursorBackwardByCharacter,
SemanticsAction.moveCursorBackwardByWord,
SemanticsAction.setSelection,
],
flags: <SemanticsFlag>[
SemanticsFlag.isReadOnly,
SemanticsFlag.isTextField,
SemanticsFlag.isFocusable,
SemanticsFlag.isMultiline,
SemanticsFlag.isFocused,
],
),
],
),
],
),
ignoreId: true,
ignoreTransform: true,
ignoreRect: true,
),
@ -2465,30 +2499,34 @@ void main() {
TestSemantics.root(
children: <TestSemantics>[
TestSemantics.rootChild(
id: 1,
value: 'Hello',
textSelection: const TextSelection(baseOffset: 5, extentOffset: 3),
textDirection: TextDirection.ltr,
inputType: ui.SemanticsInputType.text,
actions: <SemanticsAction>[
SemanticsAction.longPress,
SemanticsAction.moveCursorBackwardByCharacter,
SemanticsAction.moveCursorForwardByCharacter,
SemanticsAction.moveCursorBackwardByWord,
SemanticsAction.moveCursorForwardByWord,
SemanticsAction.setSelection,
SemanticsAction.copy,
],
flags: <SemanticsFlag>[
SemanticsFlag.isReadOnly,
SemanticsFlag.isTextField,
SemanticsFlag.isFocusable,
SemanticsFlag.isMultiline,
SemanticsFlag.isFocused,
children: <TestSemantics>[
TestSemantics(
value: 'Hello',
textSelection: const TextSelection(baseOffset: 5, extentOffset: 3),
textDirection: TextDirection.ltr,
inputType: ui.SemanticsInputType.text,
actions: <SemanticsAction>[
SemanticsAction.longPress,
SemanticsAction.moveCursorBackwardByCharacter,
SemanticsAction.moveCursorForwardByCharacter,
SemanticsAction.moveCursorBackwardByWord,
SemanticsAction.moveCursorForwardByWord,
SemanticsAction.setSelection,
SemanticsAction.copy,
],
flags: <SemanticsFlag>[
SemanticsFlag.isReadOnly,
SemanticsFlag.isTextField,
SemanticsFlag.isFocusable,
SemanticsFlag.isMultiline,
SemanticsFlag.isFocused,
],
),
],
),
],
),
ignoreId: true,
ignoreTransform: true,
ignoreRect: true,
),
@ -2609,7 +2647,7 @@ void main() {
controller.selection = const TextSelection(baseOffset: 5, extentOffset: 5);
await tester.pump();
const inputFieldId = 1;
const inputFieldId = 2;
expect(
semantics,
@ -2617,23 +2655,28 @@ void main() {
TestSemantics.root(
children: <TestSemantics>[
TestSemantics.rootChild(
id: inputFieldId,
value: 'Hello',
textSelection: const TextSelection.collapsed(offset: 5),
textDirection: TextDirection.ltr,
inputType: ui.SemanticsInputType.text,
actions: <SemanticsAction>[
SemanticsAction.longPress,
SemanticsAction.moveCursorBackwardByCharacter,
SemanticsAction.moveCursorBackwardByWord,
SemanticsAction.setSelection,
],
flags: <SemanticsFlag>[
SemanticsFlag.isReadOnly,
SemanticsFlag.isTextField,
SemanticsFlag.isFocusable,
SemanticsFlag.isMultiline,
SemanticsFlag.isFocused,
id: 1,
children: <TestSemantics>[
TestSemantics(
id: inputFieldId,
value: 'Hello',
textSelection: const TextSelection.collapsed(offset: 5),
textDirection: TextDirection.ltr,
inputType: ui.SemanticsInputType.text,
actions: <SemanticsAction>[
SemanticsAction.longPress,
SemanticsAction.moveCursorBackwardByCharacter,
SemanticsAction.moveCursorBackwardByWord,
SemanticsAction.setSelection,
],
flags: <SemanticsFlag>[
SemanticsFlag.isReadOnly,
SemanticsFlag.isTextField,
SemanticsFlag.isFocusable,
SemanticsFlag.isMultiline,
SemanticsFlag.isFocused,
],
),
],
),
],
@ -2672,24 +2715,29 @@ void main() {
TestSemantics.root(
children: <TestSemantics>[
TestSemantics.rootChild(
id: inputFieldId,
value: 'Hello',
textSelection: const TextSelection(baseOffset: 0, extentOffset: 5),
textDirection: TextDirection.ltr,
inputType: ui.SemanticsInputType.text,
actions: <SemanticsAction>[
SemanticsAction.longPress,
SemanticsAction.moveCursorBackwardByCharacter,
SemanticsAction.moveCursorBackwardByWord,
SemanticsAction.setSelection,
SemanticsAction.copy,
],
flags: <SemanticsFlag>[
SemanticsFlag.isReadOnly,
SemanticsFlag.isTextField,
SemanticsFlag.isFocusable,
SemanticsFlag.isMultiline,
SemanticsFlag.isFocused,
id: 1,
children: <TestSemantics>[
TestSemantics(
id: inputFieldId,
value: 'Hello',
textSelection: const TextSelection(baseOffset: 0, extentOffset: 5),
textDirection: TextDirection.ltr,
inputType: ui.SemanticsInputType.text,
actions: <SemanticsAction>[
SemanticsAction.longPress,
SemanticsAction.moveCursorBackwardByCharacter,
SemanticsAction.moveCursorBackwardByWord,
SemanticsAction.setSelection,
SemanticsAction.copy,
],
flags: <SemanticsFlag>[
SemanticsFlag.isReadOnly,
SemanticsFlag.isTextField,
SemanticsFlag.isFocusable,
SemanticsFlag.isMultiline,
SemanticsFlag.isFocused,
],
),
],
),
],
@ -2715,25 +2763,30 @@ void main() {
await tester.pumpWidget(overlay(child: SelectableText(testValue, key: key)));
const inputFieldId = 1;
const inputFieldId = 2;
expect(
semantics,
hasSemantics(
TestSemantics.root(
children: <TestSemantics>[
TestSemantics(
id: inputFieldId,
inputType: ui.SemanticsInputType.text,
flags: <SemanticsFlag>[
SemanticsFlag.isReadOnly,
SemanticsFlag.isTextField,
SemanticsFlag.isFocusable,
SemanticsFlag.isMultiline,
TestSemantics.rootChild(
id: 1,
children: <TestSemantics>[
TestSemantics(
id: inputFieldId,
inputType: ui.SemanticsInputType.text,
flags: <SemanticsFlag>[
SemanticsFlag.isReadOnly,
SemanticsFlag.isTextField,
SemanticsFlag.isFocusable,
SemanticsFlag.isMultiline,
],
actions: <SemanticsAction>[SemanticsAction.longPress],
value: testValue,
textDirection: TextDirection.ltr,
),
],
actions: <SemanticsAction>[SemanticsAction.longPress],
value: testValue,
textDirection: TextDirection.ltr,
),
],
),
@ -2750,28 +2803,33 @@ void main() {
hasSemantics(
TestSemantics.root(
children: <TestSemantics>[
TestSemantics(
id: inputFieldId,
inputType: ui.SemanticsInputType.text,
flags: <SemanticsFlag>[
SemanticsFlag.isReadOnly,
SemanticsFlag.isTextField,
SemanticsFlag.isFocusable,
SemanticsFlag.isMultiline,
SemanticsFlag.isFocused,
TestSemantics.rootChild(
id: 1,
children: <TestSemantics>[
TestSemantics(
id: inputFieldId,
inputType: ui.SemanticsInputType.text,
flags: <SemanticsFlag>[
SemanticsFlag.isReadOnly,
SemanticsFlag.isTextField,
SemanticsFlag.isFocusable,
SemanticsFlag.isMultiline,
SemanticsFlag.isFocused,
],
actions: <SemanticsAction>[
SemanticsAction.longPress,
SemanticsAction.moveCursorBackwardByCharacter,
SemanticsAction.moveCursorBackwardByWord,
SemanticsAction.setSelection,
],
value: testValue,
textDirection: TextDirection.ltr,
textSelection: const TextSelection(
baseOffset: testValue.length,
extentOffset: testValue.length,
),
),
],
actions: <SemanticsAction>[
SemanticsAction.longPress,
SemanticsAction.moveCursorBackwardByCharacter,
SemanticsAction.moveCursorBackwardByWord,
SemanticsAction.setSelection,
],
value: testValue,
textDirection: TextDirection.ltr,
textSelection: const TextSelection(
baseOffset: testValue.length,
extentOffset: testValue.length,
),
),
],
),

View File

@ -184,6 +184,43 @@ void main() {
semantics.dispose();
});
testWidgets('different locale will not merge', (WidgetTester tester) async {
final semantics = SemanticsTester(tester);
final GlobalKey key = GlobalKey();
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: Semantics(
localeForSubtree: const Locale('AB', 'CD'),
child: Semantics(
key: key,
localeForSubtree: const Locale('DE', 'FG'),
child: const SizedBox(width: 10, height: 10),
),
),
),
);
expect(
semantics,
hasSemantics(
TestSemantics.root(
children: <TestSemantics>[
TestSemantics.rootChild(
locale: const Locale('AB', 'CD'),
children: <TestSemantics>[TestSemantics(locale: const Locale('DE', 'FG'))],
),
],
),
ignoreId: true,
ignoreRect: true,
ignoreTransform: true,
),
);
semantics.dispose();
});
testWidgets('Semantics and Directionality - RTL', (WidgetTester tester) async {
final semantics = SemanticsTester(tester);

View File

@ -63,6 +63,7 @@ class TestSemantics {
this.identifier = '',
this.traversalParentIdentifier,
this.traversalChildIdentifier,
this.locale,
this.hintOverrides,
}) : assert(flags is int || flags is List<SemanticsFlag> || flags is SemanticsFlags),
assert(actions is int || actions is List<SemanticsAction>),
@ -97,6 +98,7 @@ class TestSemantics {
this.identifier = '',
this.traversalParentIdentifier,
this.traversalChildIdentifier,
this.locale,
this.hintOverrides,
}) : id = 0,
assert(flags is int || flags is List<SemanticsFlag> || flags is SemanticsFlags),
@ -143,6 +145,7 @@ class TestSemantics {
this.identifier = '',
this.traversalParentIdentifier,
this.traversalChildIdentifier,
this.locale,
this.hintOverrides,
}) : assert(flags is int || flags is List<SemanticsFlag> || flags is SemanticsFlags),
assert(actions is int || actions is List<SemanticsAction>),
@ -301,6 +304,11 @@ class TestSemantics {
/// Defaults to null if not set.
final Object? traversalChildIdentifier;
/// The expected locale for the node.
///
/// Defaults to null if not set.
final Locale? locale;
/// The expected hint overrides for the node.
///
/// Defaults to null if not set.
@ -515,6 +523,11 @@ class TestSemantics {
'expected node id $id to have hint overrides $hintOverrides but found hint overrides ${node.hintOverrides}',
);
}
if (locale != null && locale != node.getSemanticsData().locale) {
return fail(
'expected node id $id to have locale $locale but found locale ${node.getSemanticsData().locale}',
);
}
if (children.isEmpty) {
return true;