lottie-flutter
lottie-flutter copied to clipboard
Support paint on canvas using RenderLottie
Motivation
I would like to render Lottie via Flame engine. After investigation, it requires the renderer to paint on Canvas directly. You can refer flame_svg as an example. Since _drawable in RenderLottie is private and Dart does not support internal variables, it cannot be accessed outside. Therefore, the necessary changes are made in the library.
Implementation Notes
Simply decouple paint on PaintintContext from paint on Canvas.
@override
void paint(PaintingContext context, Offset offset) {
paintOnCanvas(context.canvas, offset);
}
void paintOnCanvas(Canvas canvas, Offset offset) {
if (_drawable == null) return;
_drawable!.draw(canvas, offset & size,
fit: _fit, alignment: _alignment.resolve(TextDirection.ltr));
}
I'm ok to accept this if it enables new use-cases.
Also you might be interested to use directly the LottieDrawable class (which has a draw method).
Here is an example: https://github.com/xvrh/lottie-flutter/blob/master/example/lib/examples/custom_draw.dart