Skip to content

feat: support Ruby control methods for focus, paging and tabs - #18

Merged
AdamMusa merged 2 commits into
codex/engine-initializationfrom
feat/control-methods
Oct 29, 2026
Merged

AdamMusa merged 2 commits into
codex/engine-initializationfrom
feat/control-methods

Conversation

@AdamMusa

@AdamMusa AdamMusa commented Oct 28, 2026 •

Copy link
Copy Markdown
Owner

Ruby counterpart: AdamMusa/ruflet#34

What

This is the client side of the new Ruby imperative control methods. The Ruby PR adds focus/blur, PageView paging, Tabs move_to and Canvas capture. Most handlers already existed in Dart; this PR fills the gaps those methods expose.

  • TextField blur (Material and Cupertino): new case "blur" unfocuses the field (both the normal and the shift_enter focus node), which also dismisses the soft keyboard. focus now targets the node that is actually rendered: shift_enter fields use a separate focus node, and focus used to request the unattached one.
  • SPEC §6 bug fix: honor Ruby delete_icon_tooltip on Chip #3, PageView nil args: Page#invoke sends "args" => nil when a method has no arguments, and page_view.dart indexed args[...] unconditionally, so next_page with no arguments threw on the client. _invokeMethod now treats a non-Map payload as {}. A missing index/value is a no-op, as before.
  • Material Tabs move_to: this handler passed args["index"] straight to TabController.animateTo, so a negative or out-of-range index asserted in debug and corrupted the index in release. It now resolves negative indexes from the end and clamps, exactly as the Cupertino handler and Material's own selected_index handling already do. That gives tabs.move_to(-1) the same meaning on both designs. The spec only asked to document the Cupertino-only behavior; I fixed Material instead because the new Ruby method makes that path easy to hit.

Wire protocol (invoke names and args)

Control Invoke name Args
TextField focus, blur {}
Button / FilledButton / FilledTonalButton / OutlinedButton / TextButton, IconButton family, Dropdown focus {} (unchanged handlers)
PageView go_to_page index, optional duration (ms), curve
PageView jump_to_page index
PageView jump_to value (scroll offset)
PageView next_page, previous_page optional duration, curve; nil args are accepted
Tabs move_to index (negative counts from the end, clamped), optional duration, curve
Canvas capture / get_capture / clear_capture pixel_ratio (capture only), unchanged

Events are unchanged. Focus changes fire focus/blur, and page and tab changes fire change with the new index.

Material vs Cupertino

  • TextField blur behaves identically on TextFormField and CupertinoTextField.
  • Button focus works on both designs. Dropdown focus works on Cupertino; on Material it only works for editable: true, because the M3 DropdownMenu focus node has canRequestFocus = editable (inherited Flet behavior, unchanged here).
  • PageView is design-neutral.
  • Tabs move_to now has the same index semantics on both designs.

Tests

test/widgets/ruby_control_methods_test.dart (8 tests, iOS and Android):

  • TextField: focus then blur move real focus and fire focus/blur. Nil args are tolerated. A shift_enter field focuses and blurs its own node, and unknown methods still throw.
  • Buttons and dropdowns: Button, FilledButton, IconButton and Dropdown (editable: true) take focus on focus and fire focus.
  • PageView: next_page with nil args turns the page, as do go_to_page with duration/curve, previous_page with nil and with args, jump_to_page, and jump_to. Missing index/value is a no-op. selected_index is synced and change events report every landing page.
  • Tabs: move_to(2), move_to(0), move_to(-2) → 1 and move_to(9) → clamped to 2. Each one syncs selected_index and fires change.

Before the fix the new test failed with Unknown TextField method: blur, a PageView NoSuchMethodError on null args, and the Android Tabs assertion.

verify_pr.sh (Flutter 3.41.2), run together with the Ruby PR:

PASS ruby:ruflet_core                   146/146 files, 626 runs
PASS engine:ruflet flutter test         +703: All tests passed!
PASS engine:ruflet analyze              No issues found!
INFO wire-key audit                     NEW vs baseline: 0
RESULT: PASS

Add the TextField blur invoke (Material and Cupertino) and focus the
node that is actually rendered for shift_enter fields. Make PageView
invoke handlers tolerate nil args, which Page#invoke sends for methods
without arguments (next_page used to throw). Resolve negative and
out-of-range Material Tabs move_to indexes like the Cupertino renderer
and selected_index already do, instead of asserting.
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