import 'package:flutter/material.dart'; import 'dart:ui' as ui; class VidPainter extends CustomPainter { VidPainter( {required this.image, required this.frameIndex, this.colorFilterMatrix = const [ 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 colorFilterMatrix; @override void paint(Canvas canvas, Size size) async { canvas.save(); final double scaleX = size.width / image.width; final double scaleY = size.height / image.height; final double scale = scaleX < scaleY ? scaleX : scaleY; final double offsetX = (size.width - image.width * scale) / 2; final double offsetY = (size.height - image.height * scale) / 2; canvas.drawImageRect( image, Rect.fromLTWH(0, 0, image.width.toDouble(), image.height.toDouble()), Rect.fromLTWH( offsetX, offsetY, image.width * scale, image.height * scale), Paint() ..colorFilter = ColorFilter.matrix(colorFilterMatrix) ..filterQuality = FilterQuality.high); canvas.restore(); } @override bool shouldRepaint(covariant VidPainter oldDelegate) { return oldDelegate.frameIndex != frameIndex || oldDelegate.colorFilterMatrix != colorFilterMatrix; } }