From 37dff27324ce429173482482304c859d7d1a4646 Mon Sep 17 00:00:00 2001 From: hangyu Date: Fri, 26 Jul 2024 16:34:53 -0700 Subject: [PATCH] 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]. [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 --- packages/flutter/lib/src/material/list_tile.dart | 1 + packages/flutter/test/material/checkbox_list_tile_test.dart | 1 + packages/flutter/test/material/expansion_tile_test.dart | 2 ++ packages/flutter/test/material/list_tile_test.dart | 1 + packages/flutter/test/material/radio_list_tile_test.dart | 2 ++ packages/flutter/test/material/reorderable_list_test.dart | 1 + packages/flutter/test/material/switch_list_tile_test.dart | 3 +++ 7 files changed, 11 insertions(+) diff --git a/packages/flutter/lib/src/material/list_tile.dart b/packages/flutter/lib/src/material/list_tile.dart index 19af6616fd..8c50e88c09 100644 --- a/packages/flutter/lib/src/material/list_tile.dart +++ b/packages/flutter/lib/src/material/list_tile.dart @@ -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( diff --git a/packages/flutter/test/material/checkbox_list_tile_test.dart b/packages/flutter/test/material/checkbox_list_tile_test.dart index 3f897b934b..da32288f0b 100644 --- a/packages/flutter/test/material/checkbox_list_tile_test.dart +++ b/packages/flutter/test/material/checkbox_list_tile_test.dart @@ -1184,6 +1184,7 @@ void main() { )); expect(tester.getSemantics(find.byType(CheckboxListTile)), matchesSemantics( + isButton: true, hasCheckedState: true, isChecked: true, hasEnabledState: true, diff --git a/packages/flutter/test/material/expansion_tile_test.dart b/packages/flutter/test/material/expansion_tile_test.dart index 78c4d96833..32e299658b 100644 --- a/packages/flutter/test/material/expansion_tile_test.dart +++ b/packages/flutter/test/material/expansion_tile_test.dart @@ -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, diff --git a/packages/flutter/test/material/list_tile_test.dart b/packages/flutter/test/material/list_tile_test.dart index 97d8ea6abe..68aa2cb058 100644 --- a/packages/flutter/test/material/list_tile_test.dart +++ b/packages/flutter/test/material/list_tile_test.dart @@ -304,6 +304,7 @@ void main() { ), TestSemantics.rootChild( flags: [ + SemanticsFlag.isButton, SemanticsFlag.hasEnabledState, SemanticsFlag.isEnabled, SemanticsFlag.isFocusable, diff --git a/packages/flutter/test/material/radio_list_tile_test.dart b/packages/flutter/test/material/radio_list_tile_test.dart index b2a4a40ab5..0d042c1a56 100644 --- a/packages/flutter/test/material/radio_list_tile_test.dart +++ b/packages/flutter/test/material/radio_list_tile_test.dart @@ -405,6 +405,7 @@ void main() { TestSemantics( id: 1, flags: [ + SemanticsFlag.isButton, SemanticsFlag.hasCheckedState, SemanticsFlag.hasEnabledState, SemanticsFlag.isEnabled, @@ -441,6 +442,7 @@ void main() { TestSemantics( id: 1, flags: [ + SemanticsFlag.isButton, SemanticsFlag.hasCheckedState, SemanticsFlag.isChecked, SemanticsFlag.hasEnabledState, diff --git a/packages/flutter/test/material/reorderable_list_test.dart b/packages/flutter/test/material/reorderable_list_test.dart index fcd36d7d5c..7ca97032a9 100644 --- a/packages/flutter/test/material/reorderable_list_test.dart +++ b/packages/flutter/test/material/reorderable_list_test.dart @@ -744,6 +744,7 @@ void main() { return false; }); expect(child, matchesSemantics( + isButton: true, hasToggledState: true, isToggled: true, isEnabled: true, diff --git a/packages/flutter/test/material/switch_list_tile_test.dart b/packages/flutter/test/material/switch_list_tile_test.dart index 5d5c8b43e9..db1c308037 100644 --- a/packages/flutter/test/material/switch_list_tile_test.dart +++ b/packages/flutter/test/material/switch_list_tile_test.dart @@ -72,6 +72,7 @@ void main() { id: 1, rect: const Rect.fromLTWH(0.0, 0.0, 800.0, 56.0), flags: [ + 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.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.isButton, SemanticsFlag.hasCheckedState, SemanticsFlag.hasEnabledState, SemanticsFlag.isEnabled,