mirror of
https://github.com/xvrh/lottie-flutter.git
synced 2025-08-06 16:39:36 +08:00

- Run the animation at the exported frame rate - Wrap the animation in a RepaintBoundary - Don't paint during "static" periods
57 lines
1.3 KiB
Dart
57 lines
1.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:lottie/lottie.dart';
|
|
|
|
class FilmStrip extends StatelessWidget {
|
|
final LottieComposition composition;
|
|
final LottieDelegates delegates;
|
|
final Size size;
|
|
|
|
const FilmStrip(this.composition,
|
|
{Key key, @required this.size, this.delegates})
|
|
: super(key: key);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return CustomPaint(
|
|
size: size,
|
|
painter: _CustomerPainter(this),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _CustomerPainter extends CustomPainter {
|
|
static const _columns = 5;
|
|
final FilmStrip parent;
|
|
|
|
_CustomerPainter(this.parent);
|
|
|
|
@override
|
|
void paint(Canvas canvas, Size size) {
|
|
var thumbSize = Size(size.width / _columns, size.width / _columns);
|
|
var drawable = LottieDrawable(parent.composition);
|
|
if (parent.delegates != null) {
|
|
drawable.delegates = parent.delegates;
|
|
}
|
|
|
|
var index = 0;
|
|
for (var progress = 0.0; progress <= 1; progress += 0.05) {
|
|
var x = index % _columns;
|
|
var y = index ~/ _columns;
|
|
|
|
var rect = Offset(x * thumbSize.width, y.toDouble() * thumbSize.height) &
|
|
thumbSize;
|
|
|
|
drawable
|
|
..setProgress(progress, frameRate: FrameRate.max)
|
|
..draw(canvas, rect);
|
|
|
|
++index;
|
|
}
|
|
}
|
|
|
|
@override
|
|
bool shouldRepaint(CustomPainter oldDelegate) {
|
|
return true;
|
|
}
|
|
}
|