mobile_scanner icon indicating copy to clipboard operation
mobile_scanner copied to clipboard

Overlay example does not apply background opacity correctly

Open IanVS opened this issue 1 year ago • 3 comments

I'm using the overlay example as a guide for building a feature in my app, and I noticed that the background opacity is not being applied outside of the scan window correctly:

Android Studio 2024-09-20 10 50 43

I'm a beginner flutter dev, so I don't know what might be causing this.

IanVS avatar Sep 20 '24 14:09 IanVS

This could be a bug in the example. Although, I think that the example just draws the white rectangle, and nothing else.

navaronbracke avatar Sep 23 '24 11:09 navaronbracke

From what I can tell, it does try to apply some opacity.

https://github.com/juliansteenbakker/mobile_scanner/blob/c3271f0cda3df5594a4cebc02696007657785861/example/lib/mobile_scanner_overlay.dart#L147C21-L147C41

    // First, draw the background,
    // with a cutout area that is a bit larger than the scan window.
    // Finally, draw the scan window itself.
    canvas.drawPath(backgroundWithCutout, backgroundPaint);
    canvas.drawRRect(borderRect, borderPaint);

IanVS avatar Sep 23 '24 12:09 IanVS

In ScannerOverlay example class, changing from:

final backgroundPaint = Paint()
  ..color = Colors.black.withOpacity(0.5)
  ..style = PaintingStyle.fill
  ..blendMode = BlendMode.dstOut;

to

final backgroundPaint = Paint()
  ..color = Colors.black.withOpacity(0.5)
  ..style = PaintingStyle.fill
  ..blendMode = BlendMode.srcOver; // <- This line

will add the background opacity.

yottsa avatar Oct 18 '24 10:10 yottsa

@RobertCer I'm not having any luck with that, did you change anything else as well?

Edit: Ah hah, changing from Rect.largest to Rect.fromLTWH(0, 0, size.width, size.height) seems to solve it for me. I'll make a quick PR.

IanVS avatar Oct 31 '24 13:10 IanVS