Add button flag to NavigationDestination (#161568)

This PR is to add `Semantics.button` to `NavigationDestination` so that
when the switch control on iOS is turned on, it can traverse the
unselected destinations.

Fixes https://github.com/flutter/flutter/issues/161563



https://github.com/user-attachments/assets/b761aea6-d1d3-468b-b0a5-249fb03e08e3



## 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.
- [x] 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.
This commit is contained in:
Qun Cheng 2025-02-03 15:58:39 -08:00 committed by GitHub
parent 13e5f8c91d
commit 56190fb35b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 36 additions and 4 deletions

View File

@ -996,6 +996,7 @@ class _NavigationBarDestinationSemantics extends StatelessWidget {
return Semantics(
selected: destinationInfo.selectedAnimation.isForwardOrCompleted,
container: true,
button: true,
child: child,
);
},

View File

@ -460,6 +460,7 @@ void main() {
destinations: const <Widget>[
NavigationDestination(icon: Icon(Icons.ac_unit), label: 'AC'),
NavigationDestination(icon: Icon(Icons.access_alarm), label: 'Alarm'),
NavigationDestination(icon: Icon(Icons.abc), label: 'ABC'),
],
),
);
@ -470,10 +471,11 @@ void main() {
expect(
tester.getSemantics(find.text('AC')),
matchesSemantics(
label: 'AC\nTab 1 of 2',
label: 'AC\nTab 1 of 3',
textDirection: TextDirection.ltr,
isFocusable: true,
isSelected: true,
isButton: true,
hasTapAction: true,
hasFocusAction: true,
),
@ -481,9 +483,21 @@ void main() {
expect(
tester.getSemantics(find.text('Alarm')),
matchesSemantics(
label: 'Alarm\nTab 2 of 2',
label: 'Alarm\nTab 2 of 3',
textDirection: TextDirection.ltr,
isFocusable: true,
isButton: true,
hasTapAction: true,
hasFocusAction: true,
),
);
expect(
tester.getSemantics(find.text('ABC')),
matchesSemantics(
label: 'ABC\nTab 3 of 3',
textDirection: TextDirection.ltr,
isFocusable: true,
isButton: true,
hasTapAction: true,
hasFocusAction: true,
),
@ -494,9 +508,10 @@ void main() {
expect(
tester.getSemantics(find.text('AC')),
matchesSemantics(
label: 'AC\nTab 1 of 2',
label: 'AC\nTab 1 of 3',
textDirection: TextDirection.ltr,
isFocusable: true,
isButton: true,
hasTapAction: true,
hasFocusAction: true,
),
@ -504,10 +519,22 @@ void main() {
expect(
tester.getSemantics(find.text('Alarm')),
matchesSemantics(
label: 'Alarm\nTab 2 of 2',
label: 'Alarm\nTab 2 of 3',
textDirection: TextDirection.ltr,
isFocusable: true,
isSelected: true,
isButton: true,
hasTapAction: true,
hasFocusAction: true,
),
);
expect(
tester.getSemantics(find.text('ABC')),
matchesSemantics(
label: 'ABC\nTab 3 of 3',
textDirection: TextDirection.ltr,
isFocusable: true,
isButton: true,
hasTapAction: true,
hasFocusAction: true,
),
@ -537,6 +564,7 @@ void main() {
textDirection: TextDirection.ltr,
isFocusable: true,
isSelected: true,
isButton: true,
hasTapAction: true,
hasFocusAction: true,
),
@ -547,6 +575,7 @@ void main() {
label: 'Alarm\nTab 2 of 2',
textDirection: TextDirection.ltr,
isFocusable: true,
isButton: true,
hasTapAction: true,
hasFocusAction: true,
),
@ -560,6 +589,7 @@ void main() {
label: 'AC\nTab 1 of 2',
textDirection: TextDirection.ltr,
isFocusable: true,
isButton: true,
hasTapAction: true,
hasFocusAction: true,
),
@ -571,6 +601,7 @@ void main() {
textDirection: TextDirection.ltr,
isFocusable: true,
isSelected: true,
isButton: true,
hasTapAction: true,
hasFocusAction: true,
),