Skip to content

Conversation

@ksokolovskyi
Copy link
Contributor

Fixes #175511

Description

  • Fixes key events interception by RadioGroup when no Radio is focused.

Pre-launch Checklist

@github-actions github-actions bot added the framework flutter/packages/flutter repository. See also f: labels. label Oct 1, 2025
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request effectively resolves an issue where RadioGroup would incorrectly intercept key events even when no Radio button within it had focus. The solution introduces a custom _RadioGroupShortcutManager which intelligently filters key events based on the focus state of the radio buttons. The implementation is clean, includes necessary resource management by disposing the new shortcut manager, and is accompanied by a thorough regression test that validates the fix. The changes are well-contained and correctly address the problem. I have one minor suggestion for improving code clarity.

@ksokolovskyi ksokolovskyi requested a review from chunhtai October 1, 2025 06:34
Copy link
Contributor

@chunhtai chunhtai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for fixing this, just left a minor suggestion

(RadioClient<T> radio) => radio.focusNode.hasFocus,
);
if (!hasFocusedRadio) {
// Ignore the event if no radio is focused.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is not useful, maybe give example why this can be a problem

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review. I added some more details to the comment.

// Ignore the event if no radio is focused. This prevents this handler
// from unintentionally consuming an event meant for a non-radio widget
// that currently has focus.

Do you like it, or do you have any suggestions?

@chunhtai chunhtai requested a review from justinmc October 7, 2025 18:53
Copy link
Contributor

@justinmc justinmc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

Comment on lines +98 to +99
late final _RadioGroupShortcutManager<T> _radioGroupShortcutManager =
_RadioGroupShortcutManager<T>(shortcuts: _radioGroupShortcuts, state: this);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for late if it's assigned here, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, we are forced to use late as, although the assignment comes next, we use late _radioGroupShortcuts and this.


@override
KeyEventResult handleKeypress(BuildContext context, KeyEvent event) {
final bool hasFocusedRadio = state._radios.any(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I would change the name to radioHasFocus. The current name made me think it would be an instance of a radio or something.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for your review!
I updated the name in the latest commit as you suggested.

@chunhtai chunhtai added the autosubmit Merge PR when tree becomes green via auto submit App label Oct 14, 2025
@auto-submit
Copy link
Contributor

auto-submit bot commented Oct 14, 2025

autosubmit label was removed for flutter/flutter/176335, because - The status or check suite Mac_arm64 build_tests_2_4 has failed. Please fix the issues identified (or deflake) before re-applying this label.

@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Oct 14, 2025
@ksokolovskyi ksokolovskyi added the autosubmit Merge PR when tree becomes green via auto submit App label Oct 14, 2025
@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Oct 14, 2025
@auto-submit
Copy link
Contributor

auto-submit bot commented Oct 14, 2025

autosubmit label was removed for flutter/flutter/176335, because - The status or check suite Mac_arm64 build_tests_3_4 has failed. Please fix the issues identified (or deflake) before re-applying this label.

@ksokolovskyi ksokolovskyi added the autosubmit Merge PR when tree becomes green via auto submit App label Oct 14, 2025
@auto-submit auto-submit bot added this pull request to the merge queue Oct 15, 2025
Merged via the queue into flutter:master with commit 9bd44f5 Oct 15, 2025
78 of 79 checks passed
@flutter-dashboard flutter-dashboard bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Oct 15, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 16, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 16, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 16, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 16, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 16, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 16, 2025
auto-submit bot pushed a commit to flutter/packages that referenced this pull request Oct 16, 2025
Manual roll requested by tarrinneal@google.com

flutter/flutter@7cd821c...a873a27

2025-10-16 30870216+gaaclarke@users.noreply.github.com [tool] makes listing a shader also as an asset a build failure (flutter/flutter#176866)
2025-10-16 engine-flutter-autoroll@skia.org Roll Packages from d062181 to 835dccb (7 revisions) (flutter/flutter#177100)
2025-10-16 jason-simmons@users.noreply.github.com Handle the new location of Perfetto in create_updated_flutter_deps.py (flutter/flutter#177099)
2025-10-16 matt.kosarek@canonical.com Implement dialog windows for the win32 platform (flutter/flutter#176309)
2025-10-16 rmolivares@renzo-olivares.dev `SelectableRegion` should not show flutter rendered context menu when web context menu is enabled (flutter/flutter#176855)
2025-10-16 jason-simmons@users.noreply.github.com Manual roll Skia to 2d9df7c70b6f (flutter/flutter#177074)
2025-10-16 31685655+SalehTZ@users.noreply.github.com feat: add `OptionsViewOpenDirection.mostSpace` to `RawAutocomplete` (flutter/flutter#172997)
2025-10-16 43054281+camsim99@users.noreply.github.com [Android] Refactor `ImageReaderSurfaceProducer` restoration after app resumes (flutter/flutter#175937)
2025-10-15 34465683+rkishan516@users.noreply.github.com Refactor: migrate fade upwards page transition builder to widgets (flutter/flutter#175560)
2025-10-15 fluttergithubbot@gmail.com Marks Windows windowing_test to be unflaky (flutter/flutter#176701)
2025-10-15 72062416+Yash-Dhrangdhariya@users.noreply.github.com fix: 🐛 Add equality and hashCode implementations to ScrollAwareImageProvider (flutter/flutter#175038)
2025-10-15 mohellebiabdessalem@gmail.com Updates `sliver_tree.1.dart‎` to use `MediaQuery.widthOf(context)`  (flutter/flutter#176888)
2025-10-15 mdebbar@google.com [web] Fix focus issues in newer versions of Chrome (flutter/flutter#176938)
2025-10-15 jessiewong401@gmail.com [Android 16] Update `android_engine_vulkan_tests` to Test Against SDK 36 Emulator (flutter/flutter#176985)
2025-10-15 sokolovskyi.konstantin@gmail.com Fix key events interception by RadioGroup when no Radio is focused. (flutter/flutter#176335)
2025-10-15 21270878+elliette@users.noreply.github.com Update cherry-pick instructions to include instructions for pre-release CPs (flutter/flutter#177020)
2025-10-15 jason-simmons@users.noreply.github.com Manual roll Skia to c501c727a007 (flutter/flutter#177015)
2025-10-15 robert.ancell@canonical.com Update examples to latest Linux runner style (flutter/flutter#177033)
2025-10-15 59215665+davidhicks980@users.noreply.github.com [material/menu_anchor.dart] Create internal menu controller if external controller is changed to null. (flutter/flutter#176375)
2025-10-15 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Fix - TalkBack does not announce list information (#174374)" (flutter/flutter#177062)
2025-10-14 robert.ancell@canonical.com Implement Regular Windows for Linux (flutter/flutter#176187)
2025-10-14 31510811+jwlilly@users.noreply.github.com Fix - TalkBack does not announce list information (flutter/flutter#174374)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC stuartmorgan@google.com,tarrinneal@google.com on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
reidbaker pushed a commit to AbdeMohlbi/flutter that referenced this pull request Dec 10, 2025
…lutter#176335)

Fixes flutter#175511

### Description

- Fixes key events interception by `RadioGroup` when no `Radio` is
focused.

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

<!-- 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
@nietsmmar
Copy link

Will this be in the next flutter version?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RadioGroup intercepts space key events preventing text input in nested TextField/EditableText widgets

4 participants