Skip to content

feat(a2ui_flutter): render data: image URLs in Image - #3963

Merged
nan-yu merged 25 commits into
a2ui-project:mainfrom
karolkulesza:feat/flutter-image-data-urls
Dec 1, 2026
Merged

nan-yu merged 25 commits into
a2ui-project:mainfrom
karolkulesza:feat/flutter-image-data-urls

Conversation

@karolkulesza

Copy link
Copy Markdown
Contributor

Description

The basic Image in a2ui_flutter showed the broken-image icon for every URL that wasn't http:// or https://, so an inline base64 data: image rendered on the web but not in Flutter. web_core has allowed data: media URLs since #3108, and #3766 does the same for SwiftUI.

Changes:

  • Image renders a data: URL whose MIME type is image/* from its bytes. The type check ignores case, so DATA:IMAGE/PNG;... works too. fit, variant and description work as they do for network images.
  • A data: URL of another type (including data:;base64,..., whose type defaults to text/plain), one that doesn't parse, or image bytes that don't decode show the broken-image icon. The icon is labelled by description, as for a network image that fails to load.
  • The bytes go into a private MemoryImage subclass that compares equal by URL. A plain MemoryImage compares by the identity of its bytes, so every rebuild would have decoded the image again. With this subclass, a rebuild with the same URL uses the cached image.
  • Image.network(url) is now Image(image: NetworkImage(url)). Image.network builds the same thing when no cache size is given, so network images don't change.

Flutter accepts only image/* data URLs, while web_core accepts any data: URL and leaves the rest to the browser. Image can't show other types anyway. Video, AudioPlayer and the Video poster are unchanged.

Two known differences from the browser, which I left for a follow-up if anyone needs them: base64 with line breaks or spaces doesn't parse in Dart, so it shows the broken icon, and the base64 is decoded again on each rebuild before the cache lookup.

Fixes #3960

Related: #3108, #3766

Testing:

  • New widget tests in test/catalog/basic/image_test.dart: a 1×1 PNG data URL renders from its bytes at its natural size with fit applied and no network request; an upper-case scheme and MIME type; the description label; a rebuild keeps the same image provider; a non-image type, a missing type and malformed base64 fall back to the labelled broken icon; image bytes that don't decode fall back without an exception.
  • flutter test in dart/a2ui_flutter: 420 tests pass.
  • dart analyze: no issues. dart format: no changes. prettier --check CHANGELOG.md: clean.

Pre-launch Checklist

One time:

For this PR:

  • I have updated the relevant CHANGELOG.md file.
  • I updated/added relevant documentation. (No docs change: the README doesn't list which URLs Image accepts.)
  • My code changes (if any) have tests.
  • If my branch is on a fork, I have verified that scripts/e2e_test.sh passes.

If you need help, consider asking for advice on the discussion board.

web_core accepts data: media URLs since a2ui-project#3108, but the Flutter Image
showed the broken-image icon for anything other than http(s). Decode a
data: URL of an image/* type into a MemoryImage that compares by URL, so
a rebuild reuses the cached decode. Other types and undecodable content
keep the broken-image icon.
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

Gemini encountered an error creating the review. You can try again by commenting /gemini review.

@github-actions github-actions Bot added the status: needs-triage auto-managed: https://github.com/a2ui-project/a2ui/blob/main/scripts/triage.mjs label Nov 3, 2026
@Varun-S10 Varun-S10 self-assigned this Nov 4, 2026
@Varun-S10

Copy link
Copy Markdown
Collaborator

Hi @karolkulesza, Thank you for raising the pr to fix the issue. We have verified the pr and it does resolve the issue. I will escalate this to team to review. Thank you for your patience and understanding.
Hi @gspencergoog, Could you please take a look?

@Varun-S10 Varun-S10 added status: needs review and removed status: needs-triage auto-managed: https://github.com/a2ui-project/a2ui/blob/main/scripts/triage.mjs labels Nov 4, 2026
@github-actions github-actions Bot added the status: needs-triage auto-managed: https://github.com/a2ui-project/a2ui/blob/main/scripts/triage.mjs label Nov 20, 2026
@polina-c

polina-c commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

From triage bot, analysis:

For humans

TL;DR
Case: this small Flutter bug fix by an external contributor overlaps with #4120, a draft by nan-yu that also renders data: images.
Suggestion: add status: needs-team-input to decide which PR lands the fix.

Summary:
The PR makes the basic Image in a2ui_flutter render a data: URL with an image/* MIME type from its bytes. Today it shows the broken-image icon for any URL that is not http or https. It closes #3960 (P2) and adds widget tests.

Targeted issues:
#3960

Suggestion:
Add status: needs-team-input with this question for the team: should this PR land first, with #4120 rebased on it, or should #4120 replace it? nan-yu, who wrote #4120 and is assigned to #4045, is the expert to answer. Also add type: bug, component: flutter adapter and lang: dart, and keep Varun-S10 assigned.

No team member has reviewed the PR yet. Varun-S10 verified the fix and asked gspencergoog to review on 2026-11-04.

The PR meets two of the review criteria:

  1. It is a small bug fix with tests (169 lines added, 8 removed, in 3 files) that closes #3960.
  2. The team can maintain it: web_core accepts data: media URLs since #3108, and #3766 does the same for SwiftUI.

It fails the overlap criterion. #4120, a draft from 2026-11-10, routes the Flutter media URLs through the URL security policy of #4045. Its new mediaImage helper also decodes an allowed data: image in memory, and it removes the same http check in image.dart. #4120 is stacked on #4114, also a draft, and neither has changed since 2026-11-10. This PR came first and is ready, so declining it for that reason is the team's call, not a clear case.

#4280, which migrates a2ui_flutter to material_ui, also touches image.dart and its tests, so the second one to land may need a rebase. GitHub reports no merge conflict with main.

  1. Add labels: status: needs-team-input, type: bug, component: flutter adapter, lang: dart
  2. Related items: feat(flutter): route media and Markdown URLs through the URL security policy #4120, feat(dart): add URL security policy to a2ui_core #4114, core: configurable URL security policy and domain allowlists across SDKs to mitigate data exfiltration #4045, fix(swiftui): accept only http(s), data: and relative media URLs #3766, feat(a2ui_flutter)!: migrate from flutter/material.dart to material_ui (#3235) #4280

To adjust the analysis and apply its suggestion, run in your a2ui checkout:

tools/internal/triage/triage_ui.sh https://github.com/a2ui-project/a2ui/pull/3963
For software
<a2ui>
root = TriageAnalysis(
  tldr="""Case: this small Flutter bug fix by an external contributor overlaps with [#4120](https://github.com/a2ui-project/a2ui/pull/4120), a draft by `nan-yu` that also renders `data:` images.
Suggestion: add `status: needs-team-input` to decide which PR lands the fix.""",
  summary="""The PR makes the basic `Image` in `a2ui_flutter` render a `data:` URL with an `image/*` MIME type from its bytes. Today it shows the broken-image icon for any URL that is not `http` or `https`. It closes [#3960](https://github.com/a2ui-project/a2ui/issues/3960) (P2) and adds widget tests.""",
  suggestion="""Add `status: needs-team-input` with this question for the team: should this PR land first, with [#4120](https://github.com/a2ui-project/a2ui/pull/4120) rebased on it, or should [#4120](https://github.com/a2ui-project/a2ui/pull/4120) replace it? `nan-yu`, who wrote [#4120](https://github.com/a2ui-project/a2ui/pull/4120) and is assigned to [#4045](https://github.com/a2ui-project/a2ui/issues/4045), is the expert to answer. Also add `type: bug`, `component: flutter adapter` and `lang: dart`, and keep `Varun-S10` assigned.

No team member has reviewed the PR yet. `Varun-S10` [verified the fix](https://github.com/a2ui-project/a2ui/pull/3963#issuecomment-6629440720) and asked `gspencergoog` to review on 2026-11-04.

The PR meets two of the review criteria:

1. It is a small bug fix with tests (169 lines added, 8 removed, in 3 files) that closes [#3960](https://github.com/a2ui-project/a2ui/issues/3960).
2. The team can maintain it: web_core accepts `data:` media URLs since [#3108](https://github.com/a2ui-project/a2ui/pull/3108), and [#3766](https://github.com/a2ui-project/a2ui/pull/3766) does the same for SwiftUI.

It fails the overlap criterion. [#4120](https://github.com/a2ui-project/a2ui/pull/4120), a draft from 2026-11-10, routes the Flutter media URLs through the URL security policy of [#4045](https://github.com/a2ui-project/a2ui/issues/4045). Its new `mediaImage` helper also decodes an allowed `data:` image in memory, and it removes the same `http` check in [`image.dart`](https://github.com/a2ui-project/a2ui/blob/172cf31e1acbce31c4e60d82b2edbd923b279dd8/dart/a2ui_flutter/lib/src/catalog/basic/image.dart#L46-L56). [#4120](https://github.com/a2ui-project/a2ui/pull/4120) is stacked on [#4114](https://github.com/a2ui-project/a2ui/pull/4114), also a draft, and neither has changed since 2026-11-10. This PR came first and is ready, so declining it for that reason is the team's call, not a clear case.

[#4280](https://github.com/a2ui-project/a2ui/pull/4280), which migrates `a2ui_flutter` to `material_ui`, also touches `image.dart` and its tests, so the second one to land may need a rebase. GitHub reports no merge conflict with `main`.""",
  added_labels=["status: needs-team-input", "type: bug", "component: flutter adapter", "lang: dart"],
  targeted_issues=[3960],
  related_items=[4120, 4114, 4045, 3766, 4280]
)
</a2ui>

This analysis is auto-created to help humans to triage this item. Please, do not treat it as a team decision.

🤖 Agent-generated

@polina-c

Copy link
Copy Markdown
Collaborator

Thanks for the fix and the tests. Before we review it, the team needs to decide how it fits with #4120, a draft that also renders data: images in Flutter, as part of the URL security policy in #4045. We will follow up here after that discussion.

@polina-c polina-c removed the status: needs-triage auto-managed: https://github.com/a2ui-project/a2ui/blob/main/scripts/triage.mjs label Nov 20, 2026
@polina-c polina-c added component: flutter adapter Affects the Flutter framework adapter lang: dart Affects SDKs or apps in the Dart programming language status: assigned-for-triage issue/pr is assigned to a domain expert for further triage type: bug Something isn't working labels Nov 20, 2026
@polina-c
polina-c requested review from Varun-S10 and nan-yu November 26, 2026 03:41

@nan-yu nan-yu left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix looks good. Thanks for the contribution.

@nan-yu nan-yu left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing to fix before this merges: the CHANGELOG entry is in an already-released section. Details inline.

🤖 Agent-generated

Comment thread dart/a2ui_flutter/CHANGELOG.md Resolved
@nan-yu
nan-yu merged commit 90f4a8c into a2ui-project:main Dec 1, 2026
51 checks passed
nan-yu added a commit that referenced this pull request Dec 3, 2026
…Image (#4045)

Main's Image gained data: image support (#3963) while this branch added
A2uiMediaImage for the same job. Merge them into A2uiMediaImage: it fetches
http(s) URLs with NetworkImage, decodes data: URLs of an image/* type with
main's cache-friendly provider, and builds its error widget for any other
URL (such as a relative one) without loading anything. Image, the Video
poster, and the Markdown image builders all use it, so every image URL goes
through the URL security policy first. Main's data: tests are kept; the
non-image and MIME-less data: URLs they used now count as blocked by the
baseline and render nothing.
nan-yu added a commit that referenced this pull request Dec 3, 2026
…Image (#4045)

Main's Image gained data: image support (#3963) while this branch added
A2uiMediaImage for the same job. Merge them into A2uiMediaImage: it fetches
http(s) URLs with NetworkImage, decodes data: URLs of an image/* type with
main's cache-friendly provider, and builds its error widget for any other
URL (such as a relative one) without loading anything. Image, the Video
poster, and the Markdown image builders all use it, so every image URL goes
through the URL security policy first. Main's data: tests are kept; the
non-image and MIME-less data: URLs they used now count as blocked by the
baseline and render nothing.
nan-yu added a commit that referenced this pull request Dec 3, 2026
…Image (#4045)

Main's Image gained data: image support (#3963) while this branch added
A2uiMediaImage for the same job. Merge them into A2uiMediaImage: it fetches
http(s) URLs with NetworkImage, decodes data: URLs of an image/* type with
main's cache-friendly provider, and builds its error widget for any other
URL (such as a relative one) without loading anything. Image, the Video
poster, and the Markdown image builders all use it, so every image URL goes
through the URL security policy first. Main's data: tests are kept; the
non-image and MIME-less data: URLs they used now count as blocked by the
baseline and render nothing.
nan-yu added a commit that referenced this pull request Dec 3, 2026
…Image (#4045)

Main's Image gained data: image support (#3963) while this branch added
A2uiMediaImage for the same job. Merge them into A2uiMediaImage: it fetches
http(s) URLs with NetworkImage, decodes data: URLs of an image/* type with
main's cache-friendly provider, and builds its error widget for any other
URL (such as a relative one) without loading anything. Image, the Video
poster, and the Markdown image builders all use it, so every image URL goes
through the URL security policy first. Main's data: tests are kept; the
non-image and MIME-less data: URLs they used now count as blocked by the
baseline and render nothing.
nan-yu added a commit that referenced this pull request Dec 3, 2026
…Image (#4045)

Main's Image gained data: image support (#3963) while this branch added
A2uiMediaImage for the same job. Merge them into A2uiMediaImage: it fetches
http(s) URLs with NetworkImage, decodes data: URLs of an image/* type with
main's cache-friendly provider, and builds its error widget for any other
URL (such as a relative one) without loading anything. Image, the Video
poster, and the Markdown image builders all use it, so every image URL goes
through the URL security policy first. Main's data: tests are kept; the
non-image and MIME-less data: URLs they used now count as blocked by the
baseline and render nothing.
nan-yu added a commit that referenced this pull request Dec 3, 2026
…Image (#4045)

Main's Image gained data: image support (#3963) while this branch added
A2uiMediaImage for the same job. Merge them into A2uiMediaImage: it fetches
http(s) URLs with NetworkImage, decodes data: URLs of an image/* type with
main's cache-friendly provider, and builds its error widget for any other
URL (such as a relative one) without loading anything. Image, the Video
poster, and the Markdown image builders all use it, so every image URL goes
through the URL security policy first. Main's data: tests are kept; the
non-image and MIME-less data: URLs they used now count as blocked by the
baseline and render nothing.
nan-yu added a commit that referenced this pull request Dec 3, 2026
…Image (#4045)

Main's Image gained data: image support (#3963) while this branch added
A2uiMediaImage for the same job. Merge them into A2uiMediaImage: it fetches
http(s) URLs with NetworkImage, decodes data: URLs of an image/* type with
main's cache-friendly provider, and builds its error widget for any other
URL (such as a relative one) without loading anything. Image, the Video
poster, and the Markdown image builders all use it, so every image URL goes
through the URL security policy first. Main's data: tests are kept; the
non-image and MIME-less data: URLs they used now count as blocked by the
baseline and render nothing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: flutter adapter Affects the Flutter framework adapter lang: dart Affects SDKs or apps in the Dart programming language status: assigned-for-triage issue/pr is assigned to a domain expert for further triage status: needs review type: bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

a2ui_flutter Image shows a broken icon for data: URLs

4 participants