Skip to content

[flutter_svg] add imageBuilder property to SvgPicture#11615

Merged
auto-submit[bot] merged 5 commits intoflutter:mainfrom
suojae:feat/add-svg-picture-image-builder
May 8, 2026
Merged

[flutter_svg] add imageBuilder property to SvgPicture#11615
auto-submit[bot] merged 5 commits intoflutter:mainfrom
suojae:feat/add-svg-picture-image-builder

Conversation

@suojae
Copy link
Copy Markdown
Contributor

@suojae suojae commented Apr 30, 2026

related with flutter/flutter#182635

This PR exposes the imageBuilder support added to VectorGraphic in #11094 through SvgPicture.

SvgPicture already supports placeholderBuilder and errorBuilder, but it did not provide a success-state builder. Without this API, callers have to wrap SvgPicture externally, which also wraps the placeholder and error states.

Adding imageBuilder lets callers decorate or wrap only the successfully loaded SVG, while keeping loading and error UI separate.

Alternatives considered

  • I chose imageBuilder because it follows the success-state wrapping pattern used by widgets like CachedNetworkImage

Changes

  • Added SvgImageWidgetBuilder.
  • Added imageBuilder to all SvgPicture constructors.
  • Forwarded imageBuilder to createCompatVectorGraphic.
  • Added tests for successful load and placeholder states.
  • Bumped flutter_svg to 2.3.0 and vector_graphics to ^1.2.0.

Pre-Review Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the AI contribution guidelines and understand my responsibilities, or I am not using AI tools.
  • I read the Tree Hygiene page, which explains my responsibilities.
  • I read and followed the relevant style guides and ran the auto-formatter.
  • I signed the CLA.
  • The title of the PR starts with the name of the package surrounded by square brackets.
  • I linked to at least one issue in the description above.
  • I followed the version and CHANGELOG instructions.
  • I updated/added any relevant documentation.
  • I added new tests to check the change I am making.
  • All existing and new tests are passing.

@github-actions github-actions Bot added p: flutter_svg triage-engine Should be looked at in engine triage labels Apr 30, 2026
@suojae suojae marked this pull request as ready for review April 30, 2026 01:18
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds an imageBuilder property to the SvgPicture widget, enabling custom wrapping of successfully loaded SVGs. The implementation includes a new SvgImageWidgetBuilder typedef, updates to all SvgPicture constructors, and a version bump to 2.3.0. The vector_graphics dependency is also updated to 1.2.0, supported by new unit tests for the imageBuilder functionality. I have no feedback to provide.

@gaaclarke
Copy link
Copy Markdown
Member

Can you spend some more time explaining in the description why you think we need this API. What problem is it solving and what alternatives did you consider?

Copy link
Copy Markdown
Member

@gaaclarke gaaclarke left a comment

Choose a reason for hiding this comment

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

(requested more information in description above)

@suojae
Copy link
Copy Markdown
Contributor Author

suojae commented May 5, 2026

Oh, sorry for the thin description. I've updated the PR description to explain why this API is needed, what problem it solves, and the alternatives I considered.

Copy link
Copy Markdown
Member

@gaaclarke gaaclarke left a comment

Choose a reason for hiding this comment

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

Okay, thanks for expanding on why we are doing this. While there was technically a way to achieve this before the PR, it required a lot of boilerplate code (like ByteLoader subclass). It's unreasonable to expect all users to implement that. This is consistent with existing APIs and sounds good to me.

My only concern is I believe the new tests operate with the svg cache so there can be bleeding state between tests. I think it would be prudent to clear the cache between tests:

  setUp(() {
    svg.cache.clear();
  });

@gaaclarke
Copy link
Copy Markdown
Member

Also a friendly reminder: when you want me to re-review things, please press the "re-request review" button otherwise I may miss it.

@gaaclarke gaaclarke added the CICD Run CI/CD label May 5, 2026
@github-actions github-actions Bot removed the CICD Run CI/CD label May 8, 2026
@suojae
Copy link
Copy Markdown
Contributor Author

suojae commented May 8, 2026

Okay, thanks for expanding on why we are doing this. While there was technically a way to achieve this before the PR, it required a lot of boilerplate code (like ByteLoader subclass). It's unreasonable to expect all users to implement that. This is consistent with existing APIs and sounds good to me.

My only concern is I believe the new tests operate with the svg cache so there can be bleeding state between tests. I think it would be prudent to clear the cache between tests:

  setUp(() {
    svg.cache.clear();
  });

I added a setUp in the SvgPicture imageBuilder test group to clear svg.cache before each test. Thanks!

@suojae suojae requested a review from gaaclarke May 8, 2026 00:19
@gaaclarke gaaclarke added the CICD Run CI/CD label May 8, 2026
Copy link
Copy Markdown
Member

@gaaclarke gaaclarke left a comment

Choose a reason for hiding this comment

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

lgtm! thanks

@gaaclarke gaaclarke requested a review from b-luk May 8, 2026 21:06
@gaaclarke
Copy link
Copy Markdown
Member

@b-luk can you be a secondary reviewer for me please. I've considered the design of the PR and it sounds good.

@gaaclarke gaaclarke added the autosubmit Merge PR when tree becomes green via auto submit App label May 8, 2026
@auto-submit auto-submit Bot merged commit ddc9430 into flutter:main May 8, 2026
83 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App CICD Run CI/CD p: flutter_svg triage-engine Should be looked at in engine triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants