From 77166253ae71a0a8d58972dc21eed88e08e9087a Mon Sep 17 00:00:00 2001 From: otsmr Date: Sun, 25 Jan 2026 12:39:53 +0100 Subject: [PATCH] fix #390 --- .../layers/background.layer.dart | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/src/views/camera/share_image_editor/layers/background.layer.dart b/lib/src/views/camera/share_image_editor/layers/background.layer.dart index ecd3ab7..ab0408f 100755 --- a/lib/src/views/camera/share_image_editor/layers/background.layer.dart +++ b/lib/src/views/camera/share_image_editor/layers/background.layer.dart @@ -33,7 +33,7 @@ class _BackgroundLayerState extends State { width: widget.layerData.image.width.toDouble(), height: widget.layerData.image.height.toDouble(), padding: EdgeInsets.zero, - color: Colors.green, + color: Colors.transparent, child: CustomPaint( painter: UiImagePainter(scImage.image!), ), @@ -47,16 +47,25 @@ class UiImagePainter extends CustomPainter { @override void paint(Canvas canvas, Size size) { + final imageSize = Size(image.width.toDouble(), image.height.toDouble()); + + final sizes = applyBoxFit(BoxFit.contain, imageSize, size); + + final destRect = Alignment.center.inscribe( + sizes.destination, + Rect.fromLTWH(0, 0, size.width, size.height), + ); + canvas.drawImageRect( image, - Rect.fromLTWH(0, 0, image.width.toDouble(), image.height.toDouble()), - Rect.fromLTWH(0, 0, size.width, size.height), + Rect.fromLTWH(0, 0, imageSize.width, imageSize.height), + destRect, Paint(), ); } @override - bool shouldRepaint(covariant CustomPainter oldDelegate) { - return false; + bool shouldRepaint(covariant UiImagePainter oldDelegate) { + return image != oldDelegate.image; } }