Skip to content

fix: render Image from Ruby src_base64 - #8

Merged
AdamMusa merged 2 commits into
codex/engine-initializationfrom
fix/image-src-base64
Oct 28, 2026
Merged

AdamMusa merged 2 commits into
codex/engine-initializationfrom
fix/image-src-base64

Conversation

@AdamMusa

Copy link
Copy Markdown
Owner

Problem

Ruby's ImageControl (packages/ruflet_core/lib/ruflet_ui/ruflet/ui/controls/shared/image_control.rb) and the DSL helper image(src = nil, src_base64: nil, ...) send base64 image data as the src_base64 wire key. If the caller passes a byte array, normalize_image_source packs it into a binary string, which arrives as bytes.

image.dart only read src. When src was absent it returned ErrorControl("Image must have \"src\" specified."), so image(src_base64: ...) drew an error box on both designs.

QA finding #4.

Fix

ImageControl now falls back to src_base64 when src is absent (control.get("src") ?? control.get("src_base64")) and passes the value to the existing buildImage helper. ResolvedAssetSource.from already decodes plain base64 and strips data:*;base64, headers. It also accepts raw bytes. So src_base64 goes through the same decoding as base64, data-URI and byte values of src. No new decoding code was added.

  • If both keys are set, src wins.
  • The ErrorControl is shown only when neither key is present. Its message now names both keys.

ImageControl is a single widgets-layer renderer, so Material and Cupertino behave the same way.

Tests

New packages/ruflet/test/widgets/ruby_image_test.dart. Each case runs on a Cupertino target (iOS, CupertinoApp) and a Material target (Android, MaterialApp):

  • A 1x1 PNG passed only as src_base64 renders one Image at the Ruby 10x10 size, with no ErrorControl. The image is a MemoryImage whose bytes equal the decoded PNG.
  • src_base64 given as a data:image/png;base64, URI, or as raw bytes, also renders.
  • When both keys are set, the src image is rendered.
  • With neither key, the ErrorControl is still shown.

Results (Flutter 3.41.2):

  • Before the fix: ruby_image_test.dart gave +4 -4: Some tests failed. The four src_base64 cases showed ErrorControl.
  • After the fix: +8: All tests passed!. The QA repro qa_wire_key_repro_test.dart --name "Image accepts" gave +2: All tests passed!
  • verify_pr.sh <worktree> "":
    PASS engine:ruflet flutter test         +703: All tests passed!
    PASS engine:ruflet analyze              No issues found!
    RESULT: PASS
    

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