create static method
Creates a new texture-backed Lottie animation natively.
width / height are the rasterization dimensions in device pixels —
thorvg renders straight into a buffer of this size, so callers should
already have applied the device pixel ratio.
Implementation
static Future<ThorvgController> create({
required Uint8List data,
required int width,
required int height,
bool animate = true,
bool repeat = true,
bool reverse = false,
double speed = 1.0,
}) async {
if (data.isEmpty) {
throw ArgumentError.value(data, 'data', 'must not be empty');
}
if (width <= 0 || height <= 0) {
throw ArgumentError('width and height must be > 0 (got ${width}x$height)');
}
final raw = await _channel.invokeMapMethod<Object?, Object?>('create', {
'data': data,
'width': width,
'height': height,
'animate': animate,
'repeat': repeat,
'reverse': reverse,
'speed': speed,
});
if (raw == null) {
throw StateError('thorvg_plus.create returned null');
}
return ThorvgController._(
textureId: (raw['textureId'] as num).toInt(),
lottieWidth: (raw['lottieWidth'] as num?)?.toInt() ?? width,
lottieHeight: (raw['lottieHeight'] as num?)?.toInt() ?? height,
totalFrame: (raw['totalFrame'] as num?)?.toDouble() ?? 0.0,
duration: (raw['duration'] as num?)?.toDouble() ?? 0.0,
);
}