Add button semantics in list tile (#151599)

fixes: https://github.com/flutter/flutter/issues/111960 

## 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].

<!-- 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:
hangyu
2024-07-26 16:34:53 -07:00
committed by GitHub
parent 4d12197ca6
commit 37dff27324
7 changed files with 11 additions and 0 deletions

View File

@@ -910,6 +910,7 @@ class ListTile extends StatelessWidget {
autofocus: autofocus,
enableFeedback: enableFeedback ?? tileTheme.enableFeedback ?? true,
child: Semantics(
button: onTap != null || onLongPress != null,
selected: selected,
enabled: enabled,
child: Ink(

View File

@@ -1184,6 +1184,7 @@ void main() {
));
expect(tester.getSemantics(find.byType(CheckboxListTile)), matchesSemantics(
isButton: true,
hasCheckedState: true,
isChecked: true,
hasEnabledState: true,

View File

@@ -727,6 +727,7 @@ void main() {
expect(
tester.getSemantics(find.byType(ListTile).first),
matchesSemantics(
isButton: true,
hasTapAction: true,
hasFocusAction: true,
hasEnabledState: true,
@@ -742,6 +743,7 @@ void main() {
expect(
tester.getSemantics(find.byType(ListTile).last),
matchesSemantics(
isButton: true,
hasTapAction: true,
hasFocusAction: true,
hasEnabledState: true,

View File

@@ -304,6 +304,7 @@ void main() {
),
TestSemantics.rootChild(
flags: <SemanticsFlag>[
SemanticsFlag.isButton,
SemanticsFlag.hasEnabledState,
SemanticsFlag.isEnabled,
SemanticsFlag.isFocusable,

View File

@@ -405,6 +405,7 @@ void main() {
TestSemantics(
id: 1,
flags: <SemanticsFlag>[
SemanticsFlag.isButton,
SemanticsFlag.hasCheckedState,
SemanticsFlag.hasEnabledState,
SemanticsFlag.isEnabled,
@@ -441,6 +442,7 @@ void main() {
TestSemantics(
id: 1,
flags: <SemanticsFlag>[
SemanticsFlag.isButton,
SemanticsFlag.hasCheckedState,
SemanticsFlag.isChecked,
SemanticsFlag.hasEnabledState,

View File

@@ -744,6 +744,7 @@ void main() {
return false;
});
expect(child, matchesSemantics(
isButton: true,
hasToggledState: true,
isToggled: true,
isEnabled: true,

View File

@@ -72,6 +72,7 @@ void main() {
id: 1,
rect: const Rect.fromLTWH(0.0, 0.0, 800.0, 56.0),
flags: <SemanticsFlag>[
SemanticsFlag.isButton,
SemanticsFlag.hasEnabledState,
SemanticsFlag.hasToggledState,
SemanticsFlag.isEnabled,
@@ -86,6 +87,7 @@ void main() {
rect: const Rect.fromLTWH(0.0, 0.0, 800.0, 56.0),
transform: Matrix4.translationValues(0.0, 56.0, 0.0),
flags: <SemanticsFlag>[
SemanticsFlag.isButton,
SemanticsFlag.hasCheckedState,
SemanticsFlag.hasEnabledState,
SemanticsFlag.isChecked,
@@ -100,6 +102,7 @@ void main() {
rect: const Rect.fromLTWH(0.0, 0.0, 800.0, 56.0),
transform: Matrix4.translationValues(0.0, 112.0, 0.0),
flags: <SemanticsFlag>[
SemanticsFlag.isButton,
SemanticsFlag.hasCheckedState,
SemanticsFlag.hasEnabledState,
SemanticsFlag.isEnabled,