mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
### Issue - Fix https://github.com/flutter/flutter/issues/170422 ### Description This PR proposes a fix by adding a hint to Semantics here:b220f5a2ab/packages/flutter/lib/src/widgets/raw_radio.dart (L217-L222)The hint is only available on iOS &macOS platforms with a localized string for `unselected` state to prevent regression on Android, which works as expected currently and this seems to be the only solution as investigated below ⬇️ <details open> <summary>Demo the fix</summary> https://github.com/user-attachments/assets/56c1c6c9-5178-45be-a633-47145a0543d6 </details> #### Why can't we make it simpler with Semantics flags only? - I looked at [UIAccessibilityTraits](https://developer.apple.com/documentation/uikit/uiaccessibilitytraits), it seems the [selected](https://developer.apple.com/documentation/uikit/uiaccessibilitytraits/selected) property does announce `selected` state, but it does not mention or give hints for `unselected` state. - [L824-L828](e8bef98051/engine/src/flutter/shell/platform/darwin/ios/framework/Source/SemanticsObject.mm (L824-L828)) in Flutter source code does mention radio button: Looks like I can try marking both toggle and check, but it's impossible, due to an assertion: [A semantics node cannot be toggled and checked at the same time](35375e43fb/packages/flutter/lib/src/rendering/object.dart (L4807-L4809)) ➡️ Not sure which flags can trigger `unselected` state implicitly. #### How do iOS native apps work? I did test with two approaches: 1. iOS Reminders app: VoiceOver vocalizes as follows: Unchecked radio: "...Incomplete..." checked radio:"...Completed..." <details> <summary>Demo video</summary> https://github.com/user-attachments/assets/6bed5d14-ded8-47c2-9c09-7afc266898cc </details> 2. Build Radio with SwiftUI Looks like [there is no built-in widget for Radio provided by Apple](https://www.reddit.com/r/SwiftUI/comments/1gsh7zo/does_swiftui_have_a_builtin_radiobutton_in_2024/?utm_source=share&utm_medium=web3x&utm_name=web3xcss&utm_term=1&utm_content=share_button). [Is it really a native iOS component?](https://www.reddit.com/r/SwiftUI/comments/1gsh7zo/comment/lxea1uf/?utm_source=share&utm_medium=web3x&utm_name=web3xcss&utm_term=1&utm_content=share_button) Most of results I have found suggest building radio from a button with changing image source(selected/unselected, respectively), as I do in this SwiftUI code here: https://gist.github.com/huycozy/93b12c030651c4fde6fe8fceda1ba1ee. We can control what the reader vocalizes by setting traits and value for it manually. This being said, setting accessibility hint or value from Flutter side makes sense in this case. Please let me know if I am missing something. <details> <summary>Demo video</summary> https://github.com/user-attachments/assets/118c89c5-46a3-497f-8b2a-6f7c5ae8edf3 </details> ## 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. 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 --------- Signed-off-by: huycozy <huy@nevercode.io> Co-authored-by: chunhtai <47866232+chunhtai@users.noreply.github.com>