Skip to content

Repository files navigation

CodeFactor License Wikipedia Discord OpenCollective pub package

ThorVG for Flutter

This project provides the ThorVG runtime for Flutter, including efficient Lottie animation and SVG rendering support.

Supported Platforms

Platform Architecture
Android arm64-v8a, armeabi-v7a, x86_64
iOS arm64, x86_64, x86_64(simulator)

Usage

Lottie

The Lottie implementation aims to maintain the same interface as lottie-flutter. If you are currently using it, you can simply replace the import statement with import 'package:thorvg/thorvg.dart' to utilize the code.

import 'package:thorvg/thorvg.dart';
// ...
class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Column(
          children: [
            // Load a Lottie animation from the assets
            Lottie.asset('assets/lottie/dancing_star.json'),

            // Load a Lottie animation from a url
            Lottie.network(
              'https://lottie.host/6d7dd6e2-ab92-4e98-826a-2f8430768886/NGnHQ6brWA.json'
            ),
          ],
        ),
      ),
    );
  }
}

Generate Flutter binding

If you change the binding interface in these files

  • tvgFlutterView.h
  • tvgFlutterView.cpp

You must always run the following script:

# Run for the first time
flutter pub get
# Generate bindings with ffigen
flutter pub run ffigen --config ffigen.yaml

You will get ./lib/src/thorvg_bindings_generated.dart.

Build

Specify the ThorVG version in the .gitmodules file.

[submodule "thorvg"]
  path = thorvg
  url = git@github.com:thorvg/thorvg.git
  branch = v1.1.x # Change to version you want

Then you can run the following commands to align with that version before building.

git submodule init
git submodule update --remote

Android

Android build requires NDK(LTS), please specify following build systems info.

# Build ThorVG native libraries
cd tool
sh flutter_build.android.sh $NDK $HOST_TAG $API

Check whether these files are generated:

  • android/src/main/arm64-v8a/libthorvg.so
  • android/src/main/armeabi-v7a/libthorvg.so
  • android/src/main/x86_64/libthorvg.so

iOS

# Build ThorVG native libraries
cd tool
sh flutter_build.ios.sh

Check whether this file is generated:

  • ios/Frameworks/libthorvg.dylib

About

ThorVG for Flutter Platform

Topics

Resources

Code of conduct

Stars

14 stars

Watchers

4 watching

Forks

Sponsor this project

Used by

Contributors

Languages