Repository navigation
fix: render Image from Ruby src_base64 - #8
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Ruby's
ImageControl(packages/ruflet_core/lib/ruflet_ui/ruflet/ui/controls/shared/image_control.rb) and the DSL helperimage(src = nil, src_base64: nil, ...)send base64 image data as thesrc_base64wire key. If the caller passes a byte array,normalize_image_sourcepacks it into a binary string, which arrives as bytes.image.dartonly readsrc. Whensrcwas absent it returnedErrorControl("Image must have \"src\" specified."), soimage(src_base64: ...)drew an error box on both designs.QA finding #4.
Fix
ImageControlnow falls back tosrc_base64whensrcis absent (control.get("src") ?? control.get("src_base64")) and passes the value to the existingbuildImagehelper.ResolvedAssetSource.fromalready decodes plain base64 and stripsdata:*;base64,headers. It also accepts raw bytes. Sosrc_base64goes through the same decoding as base64, data-URI and byte values ofsrc. No new decoding code was added.srcwins.ErrorControlis shown only when neither key is present. Its message now names both keys.ImageControlis 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):src_base64renders oneImageat the Ruby 10x10 size, with noErrorControl. The image is aMemoryImagewhose bytes equal the decoded PNG.src_base64given as adata:image/png;base64,URI, or as raw bytes, also renders.srcimage is rendered.ErrorControlis still shown.Results (Flutter 3.41.2):
ruby_image_test.dartgave+4 -4: Some tests failed.The foursrc_base64cases showedErrorControl.+8: All tests passed!. The QA reproqa_wire_key_repro_test.dart --name "Image accepts"gave+2: All tests passed!verify_pr.sh <worktree> "":