Skip to content

fix: honor TextField focused border and background on iOS - #67

Merged
AdamMusa merged 2 commits into
codex/engine-initializationfrom
fix/cupertino-textfield-focus-styling
Nov 2, 2026
Merged

AdamMusa merged 2 commits into
codex/engine-initializationfrom
fix/cupertino-textfield-focus-styling

Conversation

@AdamMusa

Copy link
Copy Markdown
Owner

Stacked on #53 (fix/cupertino-textfield-border-none, approved at 54c2709). This branch contains #53's commit plus one commit (456a98f). Please review only the last commit; once #53 merges, this PR's diff shrinks to it.

What

The iOS TextField ignored focused_border_color, focused_border_width and focused_bgcolor. The Cupertino renderer already tracks focus, including the separate shift_enter focus node, through _focused and setState. #53's _decoration() helper now applies the focused styling:

While focused iOS rendering
focused_border_color / focused_border_width restyle the drawn border: outline → Border.all, underline → the bottom rule, a Border map → each non-none side. They fall back to border_color/border_width, then to the native hairline.
border: "none" stays borderless, as on Material, where InputBorder.none.copyWith(...) is still none
focused_bgcolor replaces the background (bgcolor/fill/native white). It works with border: "none" too, then giving a decoration only while focused.
border styling without a border keyword implies "outline", as Material does. Unfocused it is identical to the native field (Border.all(native hairline)).

Visible change on top of #53: border_color/border_width without a border keyword now apply on iOS. Previously they were ignored there, but they applied on Material.

Material is unchanged (form_field.dart/textfield.dart untouched). This PR does not fix a pre-existing Material bug found while testing: Material's _onFocusChange never calls setState, so focused_bgcolor (and focused_color) never refresh on focus. It is reported to the lead as a follow-up.

Tests

test/widgets/ruby_text_field_focus_styling_test.dart (7 tests):

  • iOS colors: unfocused, a gray border on the native white fill. Focused (via showKeyboard), a red border and yellow fill. Back to gray and white on unfocus. The focus/blur events fire.
  • iOS focused_border_width: 2: the border widens, and the field grows by 2 dp because border width insets the content.
  • iOS without a border keyword: unfocused it equals the native decoration; focused it shows a red outline ring with the native radius.
  • iOS underline and Border map: only the drawn sides are recolored. The previously focused field returns to its resting color.
  • iOS border: "none": decoration is null at rest; focused it has no border but the focused_bgcolor fill; null again on unfocus.
  • iOS shift_enter: a field focused on its own node is styled too.
  • Material: the focused border color is unchanged, and no Cupertino widgets appear.

Before the fix, the 6 iOS tests failed. Together with #53's 6 border tests and the validation tests, all pass.

verify_pr.sh (Flutter 3.41.2) at 456a98f:

PASS engine:ruflet flutter test         +708: All tests passed!
PASS engine:ruflet analyze              No issues found!
RESULT: PASS

On iOS, border: "none" still drew the native rounded border and white
fill: the string reached the Border-map parser, which threw, and a null
border left CupertinoTextField's default decoration in place. This broke
form_row(text_field(border: "none"), ...) layouts.

Resolve the border style explicitly. none paints nothing (decoration
null, so disabled fields get no gray box either); outline and underline
use the native hairline unless border_color/border_width are given
(width 0 removes the line) instead of a hard-coded 1 dp black line;
underline has square corners and no fill; absent or a Border map keeps
the native field. filled/fill_color now paint a background on iOS too.
Material is unchanged.
The Cupertino renderer ignored focused_border_color, focused_border_width
and focused_bgcolor. The field already tracks focus (including the
shift_enter node), so the decoration now restyles the drawn border and
replaces the background while focused. As on Material, border "none"
stays borderless when focused, and border styling without a border
keyword implies an outline.
@AdamMusa
AdamMusa merged commit eb278e4 into codex/engine-initialization Nov 2, 2026
AdamMusa pushed a commit that referenced this pull request Nov 3, 2026
Follow-up to #67 (iOS TextField focus styling). With `filled: true`,
`fill_color` and `focused_bgcolor`, iOS showed focused_bgcolor while the
field had focus but Material kept fill_color, because
buildInputDecoration only fell back to focused_bgcolor when no
fill_color was set (`fillColor ?? (focused ? focusedBgcolor ?? bgcolor :
bgcolor)`, unchanged since the engine was extracted).

Both designs now follow one rule: while focused, `focused_bgcolor` (when
set) is the background; otherwise `fill_color`, then `bgcolor`. That is
what the keyword means (Flet documents it as the TextField's background
colour in the focused state, and Ruby passes it through unchanged on
TextField and CupertinoTextField), so a field-specific focus colour no
longer disappears because a resting fill is also set. The iOS renderer
already did this; the Material decoration (shared with the Material
DropdownM2) now does too. Without fill_color nothing changes.

ruby_text_field_focus_colors_test.dart checks fill_color at rest,
focused_bgcolor while focused and fill_color after blur on iOS and
Android; the Android case fails without the fix (it stayed 0xFF00FF00).
TextField, dropdown and form widget tests plus test/architecture:
418/418.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MqfxcsDiEUZngybe9L72JQ
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant