Skip to content

fix: read the alignment, padding and radius shapes Ruby sends as defaults - #119

Merged
AdamMusa merged 6 commits into
codex/engine-initializationfrom
fix/parse-named-alignment-and-all-shapes
Nov 20, 2026
Merged

AdamMusa merged 6 commits into
codex/engine-initializationfrom
fix/parse-named-alignment-and-all-shapes

Conversation

@AdamMusa

@AdamMusa AdamMusa commented Nov 20, 2026 •

Copy link
Copy Markdown
Owner

Fixes #118

What changed

ruflet_core gives some controls default values in shapes the parsers did not read. Every published gem (0.0.13 to 0.0.23) sends them. The renderer now reads them:

  • parseAlignment (utils/alignment.dart) also reads the nine named alignments: top_left, top_center, top_right, center_left, center, center_right, bottom_left, bottom_center, bottom_right. Names are folded like parseEnum, so topLeft and TOP_LEFT also work. An unknown name gives the caller's default.
    • Before this change, any string threw _TypeError: type 'String' is not a subtype of type 'int' of 'index'. Flutter then showed its error widget in place of FilledIconButton, FilledTonalIconButton and OutlinedIconButton (both designs), Button/FilledButton/FilledTonalButton from cupertino_*_button (both designs), and TimerPicker (iOS). On desktop, the Window service threw the same error while reading its props, and its catch only logs it.
  • parseEdgeInsets, parseEdgeInsetsDirectional and parseBorderRadius read an "all" key as the value for every side or corner the map does not name. Before, {"all": 8} parsed to EdgeInsets.zero and {"all": 8.0} to BorderRadius.zero.

Unchanged: numbers, {x, y} maps, side maps and corner maps without "all", and null. The new tests assert each of these.

Tests only: TimerPicker is dropped from the coverage check's knownGaps, because the new test covers it on both designs and the check reported it as "covered now".

The fix is in the engine because the published gems cannot be changed. The Ruby defaults are fixed separately in AdamMusa/ruflet#100, so new gems also render on today's template. This reaches published gems only through a ruflet-template engine sync (D1: prepared, merged by the owner). Template PR #2 syncs f44e7df and does not include this change.

How verified

Final head a7ba175 (base 1da4885 merged in), flutter 3.41.2. The PR diff against the base is the same as at e762730.

  • Merge gate, first on a merge with base 6263f98: flutter test in packages/ruflet +2336, all pass; packages/ruflet_charts (reads parseBorderRadius/parseEdgeInsets) analyze clean, +90, all pass.
  • a7ba175 redoes that merge on 1da4885. Against the tree above it changes one knownGaps line in packages/ruflet and packages/ruflet_lottie only. On a7ba175: test/contract plus both new test files +45, all pass; flutter analyze on the 6 touched files: no issues; packages/ruflet_lottie (reads getAlignment) analyze clean, +19, all pass.

The new tests, and the author's earlier runs:

  • New packages/ruflet/test/widgets/ruby_default_shapes_test.dart (28 tests). On both designs it mounts the exact wire to_patch gives for filled_icon_button, filled_tonal_icon_button, outlined_icon_button, cupertino_button, cupertino_filled_button, cupertino_tinted_button, cupertino_timer_picker and cupertino_text_field with default arguments. That wire is the same on ruflet main a9b58473. It asserts:

    • no exception and no ErrorWidget
    • IconButton/CupertinoButton padding EdgeInsets.all(8) and alignment Alignment.center
    • CupertinoButton.borderRadius BorderRadius.circular(8)
    • CupertinoTimerPicker.alignment Alignment.center
    • CupertinoTextField.padding EdgeInsets.all(7)

    It also covers every named alignment, unknown names, and the shapes that parsed before.

  • New packages/ruflet/test/widgets/window_named_alignment_test.dart (10 tests). On macOS and Windows it mounts Page{title, window{alignment, width: 500, height: 400}} (the wire Ruby sends for alignment: "center"), mocks the window_manager and screen_retriever channels, and asserts the calls that reach the platform: the title, the size, the aligned position, then the title bar style. "center", "bottom_right" and "bottomRight" give the same calls as {x: 0, y: 0} and {x: 1, y: 1}.

  • Bug planted back: with all three parser changes reverted, ruby_default_shapes_test.dart fails +5 -23. The 5 that still pass are the "keeps the old meaning" tests and the android picker and text field, which never read these keys. With alignment.dart reverted, window_named_alignment_test.dart fails +4 -6: no call at all reaches the platform for any of the 6 string cases. The 4 map cases still pass.

  • flutter test in packages/ruflet on da00f29: +2336, all tests pass.

  • On e762730: test/contract and both new test files, +45, all pass.

  • flutter analyze on the 6 touched files: no issues.

  • Ruby side (ruflet main a9b58473): WindowControl.new(alignment: "center", width: 500, height: 400).to_patch gives {"_c":"Window","_i":2,"alignment":"center","width":500,"height":400}. The H1 goldens pass there (compat.rb --jobs 4: 290 goldens; compat_goldens_test.rb: 298 runs, 0 failures). This PR changes no Ruby code.

Behavior changes

All bug fixes (D6). No app code change is needed for any of them.

  1. Crash becomes a rendered control. Any control with a named alignment string now renders instead of showing the error widget. That includes the controls above built with default arguments, and any alignment: "top_left"-style value an app passes. No input that rendered before changes.
  2. Desktop window updates are no longer dropped. page.window.alignment given as a named string (for example "center") made the Window service throw before it applied anything. The catch only logged it, so the window's title, size, position, opacity and every other window prop were silently dropped, in every window update (including a page title change) for as long as the alignment stayed a named string. Now all of them apply and the window moves to the named alignment, the same as the matching {x, y} value.
  3. "all" padding is applied instead of dropped.
    • filled_icon_button, filled_tonal_icon_button and outlined_icon_button built with an explicit alignment used to get 0 padding. They now get the 8 that Ruby's default intends (Flet's and Flutter's IconButton default).
    • cupertino_text_field on iOS goes from 0 inner padding to 7. That is the engine's own declared default for this key and CupertinoTextField's Flutter default. This is the most visible change: every Cupertino text field built with default arguments gains its 7 px inset.
  4. "all" radius is applied instead of dropped. cupertino_*_button on iOS with an explicit alignment went from square corners to radius 8. Radius 8 is the engine's own default when no radius is sent.
  5. Mixed maps. A map with "all" plus some named sides or corners (for example {"all": 8, "left": 2}) used to give 0 for the unnamed sides. It now gives the all value for them.

If the owner wants the crash fixes (1 and 2) shipped without the visual changes in 3 to 5, the alignment.dart hunk can be taken on its own. It is independent of the edge_insets.dart and borders.dart hunks.

…ults

ruflet_core gives several controls default values in shapes the parsers
did not read:

- alignment "center" (FilledIconButton, FilledTonalIconButton,
  OutlinedIconButton, the cupertino_* buttons, TimerPicker): parseAlignment
  indexed the String like a map and threw, so the control built with
  default arguments showed Flutter's error widget.
- padding {"all": 8} (the icon buttons) and {"all": 7}
  (cupertino_text_field), border_radius {"all": 8.0} (the cupertino_*
  buttons): read as zero, so IconButton lost its padding, CupertinoButton
  its default radius of 8 and CupertinoTextField its default padding of 7.

Every published gem sends these values, so the renderer has to read them:

- parseAlignment also reads the nine named alignments (top_left ...
  bottom_right), folded like parseEnum; an unknown name gives the default.
- parseEdgeInsets, parseEdgeInsetsDirectional and parseBorderRadius read
  "all" as the value of every side/corner the map does not name.

Numbers, {x, y} maps and side/corner maps without "all" parse as before.

Fixes #118
Before #118's alignment fix, page.window.alignment = "center" threw while
the Window service read its props, so the title, size and position were all
dropped. The test fails that way with alignment.dart reverted (+4 -6) and
checks the named values give the same window update as their {x, y} maps.
ruby_default_shapes_test.dart covers it on both designs; the check reports
it as covered now.
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.

parseAlignment throws on named alignment strings; {"all": n} padding and border radius parse to zero

1 participant