svg: Add Svg widget for static SVG rendering - #40
Open
seobinpark wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
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
Svgwidget (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
mimetypeparameter 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 nativeresize()path (viaload()), 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 indecodeImageFromPixelsand can also trigger native issues. Guard against non-positive dimensions and avoid callingsetStateafter 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.
tinyjin
requested changes
Aug 9, 2026
tinyjin
self-requested a review
August 26, 2026 10:21
tinyjin
reviewed
Aug 28, 2026
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
force-pushed
the
seobinpark/picture-svg
branch
from
August 31, 2026 10:40
621388a to
8bb2684
Compare
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.

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