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

class LabVidPainter extends CustomPainter {
  LabVidPainter(
      {required this.image,
      required this.frameIndex,
      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;
  int frameIndex;
  List<double> colorFilterMatrix;

  @override
  void paint(Canvas canvas, Size size) async {
    canvas.save();
    canvas.drawImage(
      image,
      Offset.zero,
      Paint()
        ..filterQuality = FilterQuality.high
        ..colorFilter = ColorFilter.matrix(colorFilterMatrix),
    );
    canvas.restore();
  }

  @override
  bool shouldRepaint(covariant LabVidPainter oldDelegate) {
    return oldDelegate.frameIndex != frameIndex ||
        oldDelegate.colorFilterMatrix != colorFilterMatrix;
  }
}
