svgaplayer_3 3.0.1 copy "svgaplayer_3: ^3.0.1" to clipboard
svgaplayer_3: ^3.0.1 copied to clipboard

The SVGAPlayer implementation of Flutter using CustomPainter.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:svgaplayer_3/svgaplayer_flutter.dart';
import 'package:svgaplayer_flutter_example/sample.dart';

import 'constants.dart';

void main() => runApp(ExampleApp());

class ExampleApp extends StatelessWidget {
  const ExampleApp({
    super.key,
  });

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData.dark(),
      home: HomeScreen(),
    );
  }
}

class HomeScreen extends StatelessWidget {
  HomeScreen({
    super.key,
  });

  /// Callback for register dynamic items.
  final dynamicSamples = <String, void Function(MovieEntity entity)>{
    "kingset.svga": (entity) => entity.dynamicItem
      ..setText(
        TextPainter(
          text: TextSpan(
            text: "Hello, World!",
            style: TextStyle(
              fontSize: 28,
              color: Colors.white,
              fontWeight: FontWeight.bold,
            ),
          ),
        ),
        "banner",
      )
    // ..setImageWithUrl(
    //     "https://github.com/PonyCui/resources/blob/master/svga_replace_avatar.png?raw=true",
    //     "99")
    // ..setDynamicDrawer((canvas, frameIndex) {
    //   canvas.drawRect(Rect.fromLTWH(0, 0, 88, 88),
    //       Paint()..color = Colors.red); // draw by yourself.
    // }, "banner"),
  };

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('SVGA Flutter Samples'),
      ),
      body: ListView.separated(
        itemCount: samples.length,
        separatorBuilder: (_, __) => Divider(),
        itemBuilder: (context, index) {
          return ListTile(
            title: Text(samples[index].first),
            subtitle: Text(samples[index].last),
            onTap: () => _goToSample(
              context,
              samples[index],
            ),
          );
        },
      ),
    );
  }

  void _goToSample(context, List<String> sample) {
    Navigator.of(context).push(
      MaterialPageRoute(
        builder: (context) {
          return SVGASampleScreen(
            name: sample.first,
            image: sample.last,
            dynamicCallback: dynamicSamples[sample.first],
          );
        },
      ),
    );
  }
}
1
likes
140
pub points
0%
popularity

Publisher

unverified uploader

The SVGAPlayer implementation of Flutter using CustomPainter.

Repository (GitHub)
View/report issues

Documentation

API reference

License

unknown (license)

Dependencies

archive, flutter, http, path_drawing, protobuf

More

Packages that depend on svgaplayer_3