flipAnimation method

Future<Image> flipAnimation({
  1. required Vector2 size,
  2. required int count,
})

Implementation

Future<Image> flipAnimation({required Vector2 size, required int count}) {
  PictureRecorder recorder = PictureRecorder();
  final paint = Paint();
  Canvas canvas = Canvas(recorder);

  canvas.translate(width / 2, height / 2);
  canvas.scale(-1, 1);
  canvas.translate(-width / 2, -height / 2);
  int indexAux = 0;
  for (int i = count - 1; i >= 0; i--) {
    final dstPosition = Vector2(size.x * i, 0);
    final srcPosition = Vector2(size.x * indexAux, 0);
    canvas.drawImageRect(
      this,
      Rect.fromLTWH(srcPosition.x, srcPosition.y, size.x, size.y),
      Rect.fromLTWH(dstPosition.x, dstPosition.y, size.x, size.y),
      paint,
    );
    indexAux++;
  }

  return recorder.endRecording().toImage(width, height);
}