Menu

Patches Welcome #3: The Checkbox That Stole Focus
📰

Patches Welcome #3: The Checkbox That Stole Focus

DEV Community: dart·Sagar Ghag·4 days ago
#5KtgycTi
#devtodart#devto#dev#focus#value
Reading 0:00
15s threshold

A user types into a text field. Their onChanged programmatically toggles a checkbox. The text field loses focus mid-keystroke. The keyboard might dismiss on mobile. The user's cursor is gone and they don't know why.

That's issue #1495 in flutter_form_builder , a package with 1,900+ likes on pub.dev. The checkbox was stealing focus every time its value changed, even when no human touched it.

Root cause

_FormBuilderCheckboxState overrides didChange to call focus() before delegating to super.didChange(value) . Every programmatic value change (not just taps) triggers didChange . So any code path that sets the checkbox value also yanks focus to the checkbox.

@override void didChange ( bool ? value ) { focus (); // <-- this fires on EVERY value change, not just user taps super . didChange ( value ); }

Enter fullscreen mode

Exit fullscreen mode

The focus() call was probably added for keyboard accessibility on direct taps. But CheckboxListTile already handles tap-based focus through its focusNode parameter.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.