-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Description
Summary
In Flutter 3.35.3, the new RadioGroup widget intercepts space key events, preventing space characters from being entered in TextField or EditableText widgets nested within the RadioGroup.
Platform
- Platform: Web
- Flutter Version: 3.35.3 (introduced with RadioGroup widget)
- Browser: Chrome, Firefox (likely all browsers)
Steps to Reproduce
- Create a
RadioGroupcontainingRadiowidgets and aTextField - Run on Flutter Web
- Select a radio option and focus the
TextField - Try typing space characters
- Observe that spaces are ignored while other characters work fine
Expected Behavior
Space characters should be inserted into the TextField just like any other character.
Actual Behavior
Space key presses are consumed by the RadioGroup widget and never reach the TextField.
Code Sample
RadioGroup<TestOption>(
groupValue: _selectedOption,
onChanged: (value) => setState(() => _selectedOption = value!),
child: Column(
children: [
ListTile(
title: Text('Text Input Option'),
leading: Radio<TestOption>(value: TestOption.textInput),
),
if (_selectedOption == TestOption.textInput)
TextField(
// Space key input is ignored here
decoration: InputDecoration(hintText: 'Spaces ignored...'),
),
],
),
)Root Cause
The RadioGroup widget defines a space key shortcut that intercepts all space key events within its widget tree. In the Flutter source code (radio_group.dart lines 94 and 118-132), RadioGroup registers this shortcut:
const SingleActivator(LogicalKeyboardKey.space): VoidCallbackIntent(_toggleFocusedRadio),The _toggleFocusedRadio() method:
- Finds the currently focused radio button
- If the radio isn't selected, selects it by calling
onChanged(radio.radioValue) - If the radio supports tristate and is already selected, deselects it by calling
onChanged(null)
This shortcut mechanism consumes space key events before they can bubble down to nested TextField or EditableText widgets, preventing space characters from being entered in text inputs that are children of the RadioGroup.
Source Reference: Flutter SDK radio_group.dart at /packages/flutter/lib/src/widgets/radio_group.dart:94
Workaround
Use the deprecated individual Radio properties (groupValue, onChanged) instead of RadioGroup:
// Instead of RadioGroup, use individual Radio widgets
Radio<TestOption>(
value: TestOption.textInput,
groupValue: _selectedOption, // deprecated but functional
onChanged: (value) => setState(() => _selectedOption = value!),
)Impact
This breaks common UI patterns where radio buttons control the visibility/behavior of text input fields, which is a standard form design pattern.
Reproduction Project
flutter_radiogroup_bug_repro.zip
Complete reproduction case can be created following the code sample above.
Test Instructions:
- Create a Flutter web app with the code sample
- Run
flutter run -d chrome - Select "Text Input Option" radio button
- Try typing spaces in the text field - they will be ignored
- Compare behavior outside RadioGroup - spaces work there
Metadata
Metadata
Assignees
Labels
Type
Projects
Status