Skip to content

svg: Add Svg widget for static SVG rendering - #40

Open
seobinpark wants to merge 1 commit into
thorvg:mainfrom
seobinpark:seobinpark/picture-svg
Open

svg: Add Svg widget for static SVG rendering#40
seobinpark wants to merge 1 commit into
thorvg:mainfrom
seobinpark:seobinpark/picture-svg

Conversation

@seobinpark

Copy link
Copy Markdown
Collaborator

ThorVG's Picture::load() already supports the SVG MIME type, but the Flutter plugin only exposed it through the Lottie-specific native binding and build configuration.

Add a new Svg widget (Svg.asset/file/memory/network) that renders static SVG through the same native pipeline as Lottie. Generalize the previously Lottie-only native class into a format-neutral one that accepts the MIME type as a parameter, and include the SVG loader in the iOS/Android build scripts, which had excluded it from the compiled engine.

issue: #38

@seobinpark
seobinpark requested a review from tinyjin as a code owner July 30, 2026 15:35
@hermet
hermet requested a review from Copilot July 30, 2026 17:21
@hermet hermet added the feature New feature additions label Jul 30, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR adds first-class Flutter support for static SVG rendering using ThorVG’s existing Picture::load() SVG support, reusing the same native rendering pipeline previously exposed only for Lottie. It also generalizes the native “Lottie animation” binding into a format-neutral animation/picture wrapper that accepts a MIME type at load time, and updates mobile build scripts to compile the SVG loader into the embedded ThorVG engine.

Changes:

  • Introduces a new Svg widget (Svg.asset/file/memory/network) for static SVG rendering via the ThorVG native pipeline.
  • Generalizes the native/Dart FFI API from Lottie-specific to format-neutral by adding a mimetype parameter to load and renaming the binding types.
  • Enables the ThorVG SVG loader in iOS/Android build scripts so SVG parsing is available in the compiled engine.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/tvgFlutterAnimation.h Renames/modernizes the exported C API type to a format-neutral FlutterAnimation.
src/tvgFlutterAnimation.cpp Generalizes native load to accept a MIME type (e.g., lottie+json, svg).
lottie/meson.build Switches the built source from the Lottie-specific native file to the generalized one.
lottie/flutter_build.ios.sh Enables the svg loader in the iOS ThorVG build configuration.
lottie/flutter_build.android.sh Enables the svg loader in the Android ThorVG build configuration.
lib/thorvg.dart Exposes the new Svg widget from the public package entrypoint.
lib/src/thorvg.dart Updates the Dart wrapper to use the generalized native binding and pass MIME types.
lib/src/thorvg_bindings_generated.dart Updates generated FFI bindings to use FlutterAnimation instead of Lottie-specific types.
lib/src/svg.dart Adds the new Svg widget implementation (async load + native render to ui.Image).
lib/src/lottie.dart Updates Lottie to pass its MIME type (lottie+json) into the generalized loader.
ffigen.yaml Points ffigen at the new generalized native header for binding generation.
CONTRIBUTORS.md Adds a new contributor entry.
Comments suppressed due to low confidence (2)

lib/src/svg.dart:183

  • Calling tvg.load(..., 0, 0, ...) propagates a 0x0 size into the native resize() path (via load()), which reallocates a 0-byte buffer and targets the canvas with a null/invalid buffer. Use a minimal non-zero size for the initial load (you can still resize later for the actual render).
  void _tvgLoad() {
    try {
      tvg!.load(data, 'svg', 0, 0, false, false, false);

lib/src/svg.dart:200

  • _tvgRender() can attempt to resize/render/decode with a 0 width/height (e.g., before constraints are resolved), which will throw in decodeImageFromPixels and can also trigger native issues. Guard against non-positive dimensions and avoid calling setState after dispose (async decode).
  void _tvgRender() async {
    try {
      tvg!.resize(renderWidth.toInt(), renderHeight.toInt());
      final buffer = tvg!.render();
      if (buffer == null) return;

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/src/svg.dart Outdated
Comment thread lib/src/thorvg.dart Outdated

@tinyjin tinyjin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks please check comments

Comment thread lib/src/svg.dart Outdated
Comment thread src/tvgFlutterAnimation.cpp Outdated
Comment thread lib/src/svg.dart Outdated
Comment thread lib/src/svg.dart Outdated
@tinyjin
tinyjin self-requested a review August 26, 2026 10:21

@tinyjin tinyjin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@seobinpark

Image

Need 3 commits? Please clean up the commit history.

Plus, good to add SVG example

ThorVG's Picture::load() already supports the SVG MIME type, but the
Flutter plugin only exposed it through the Lottie-specific native
binding and build configuration.

Add a new Svg widget (Svg.asset/file/memory/network) that renders
static SVG through the same native pipeline as Lottie. Generalize
the previously Lottie-only native class into a format-neutral one
that accepts the MIME type as a parameter, and include the SVG
loader in the iOS/Android build scripts, which had excluded it from
the compiled engine.

issue: thorvg#38
@seobinpark
seobinpark force-pushed the seobinpark/picture-svg branch from 621388a to 8bb2684 Compare August 31, 2026 10:40
@seobinpark
seobinpark requested a review from tinyjin August 31, 2026 10:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature additions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants