import 'package:flutter/material.dart';
import 'dart:ui' as ui;

class VidPainter extends CustomPainter {
  VidPainter(
      {required this.image,
      this.colorFilterMatrix = const <double>[
        1, 0, 0, 0, 0, // red
        0, 1, 0, 0, 0, // green
        0, 0, 1, 0, 0, // blue
        0, 0, 0, 1, 0, // alpha
      ]});
  ui.Image image;
  List<double> colorFilterMatrix;

  @override
  void paint(Canvas canvas, Size size) async {
    final double scale = size.width / image.width;
    final double offsetY = (size.height - image.height * scale) / 2;

    canvas.save();
    // canvas.scale(scale);
    // canvas.drawImage(image, Offset(0, offsetY), paint);
    canvas.drawImageRect(
        image,
        Rect.fromLTWH(0, 0, image.width.toDouble(), image.height.toDouble()),
        Rect.fromLTWH(0, offsetY, size.width, image.height * scale),
        Paint()..colorFilter = ColorFilter.matrix(colorFilterMatrix));

    canvas.restore();
    // image.dispose();
  }

  @override
  bool shouldRepaint(covariant CustomPainter oldDelegate) {
    return true;
  }
}
