Sfoglia il codice sorgente

Completed QrScannerOverlayShape logic

flutter-beta
Tihomirov 4 anni fa
parent
commit
4d6a2dbc47
2 ha cambiato i file con 9 aggiunte e 8 eliminazioni
  1. +2
    -2
      lib/src/qr_code_scanner.dart
  2. +7
    -6
      lib/src/qr_scanner_overlay_shape.dart

+ 2
- 2
lib/src/qr_code_scanner.dart Vedi File

@@ -334,7 +334,7 @@ class QRViewController {
await channel.invokeMethod('setDimensions', {
'width': renderBox.size.width,
'height': renderBox.size.height,
'scanArea': overlay?.cutOutSize ?? 0,
'scanArea': overlay?.cutOutWidth ?? 0,//Todo
'scanAreaOffset': overlay?.cutOutBottomOffset ?? 0
});
return true;
@@ -346,7 +346,7 @@ class QRViewController {
return false;
}
await channel.invokeMethod('changeScanArea', {
'cutOutSize': overlay.cutOutSize,
'cutOutSize': overlay.cutOutWidth,//Todo
'cutOutBottomOffset': overlay.cutOutBottomOffset
});
return true;


+ 7
- 6
lib/src/qr_scanner_overlay_shape.dart Vedi File

@@ -76,10 +76,11 @@ class QrScannerOverlayShape extends ShapeBorder {
final borderWidthSize = width / 2;
final height = rect.height;
final borderOffset = borderWidth / 2;
final _borderLength = borderLength > cutOutSize / 2 + borderWidth * 2
final _borderLength = borderLength > min(cutOutHeight, cutOutHeight) / 2 + borderWidth * 2
? borderWidthSize / 2
: borderLength;
final _cutOutSize = cutOutSize < width ? cutOutSize : width - borderOffset;
final _cutOutWidth = cutOutWidth < width ? cutOutWidth : width - borderOffset;
final _cutOutHeight = cutOutHeight < height ? cutOutHeight : height - borderOffset;

final backgroundPaint = Paint()
..color = overlayColor
@@ -96,14 +97,14 @@ class QrScannerOverlayShape extends ShapeBorder {
..blendMode = BlendMode.dstOut;

final cutOutRect = Rect.fromLTWH(
rect.left + width / 2 - _cutOutSize / 2 + borderOffset,
rect.left + width / 2 - _cutOutWidth / 2 + borderOffset,
-cutOutBottomOffset +
rect.top +
height / 2 -
_cutOutSize / 2 +
_cutOutHeight / 2 +
borderOffset,
_cutOutSize - borderOffset * 2,
_cutOutSize - borderOffset * 2,
_cutOutWidth - borderOffset * 2,
_cutOutHeight - borderOffset * 2,
);

canvas


Caricamento…
Annulla
Salva