| @@ -48,8 +48,8 @@ android { | |||
| dependencies { | |||
| implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" | |||
| implementation('com.journeyapps:zxing-android-embedded:4.1.0') { transitive = false } | |||
| implementation 'androidx.appcompat:appcompat:1.3.1' | |||
| implementation 'com.google.zxing:core:3.4.1' | |||
| implementation('com.journeyapps:zxing-android-embedded:4.2.0') { transitive = false } | |||
| implementation 'androidx.appcompat:appcompat:1.3.0' | |||
| implementation 'com.google.zxing:core:3.3.3' | |||
| coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5' | |||
| } | |||
| @@ -85,7 +85,8 @@ class QRView(private val context: Context, messenger: BinaryMessenger, private v | |||
| "getFlashInfo" -> getFlashInfo(result) | |||
| "getSystemFeatures" -> getSystemFeatures(result) | |||
| "changeScanArea" -> changeScanArea( | |||
| call.argument<Double>("cutOutSize")!!, | |||
| call.argument<Double>("scanAreaWidth")!!, | |||
| call.argument<Double>("scanAreaHeight")!!, | |||
| call.argument<Double>("cutOutBottomOffset")!!, | |||
| result, | |||
| ) | |||
| @@ -249,11 +250,12 @@ class QRView(private val context: Context, messenger: BinaryMessenger, private v | |||
| } | |||
| private fun changeScanArea( | |||
| cutOutSize: Double, | |||
| dpScanAreaWidth: Double, | |||
| dpScanAreaHeight: Double, | |||
| cutOutBottomOffset: Double, | |||
| result: MethodChannel.Result | |||
| ) { | |||
| setScanAreaSize(cutOutSize, cutOutSize, cutOutBottomOffset) | |||
| setScanAreaSize(dpScanAreaWidth, dpScanAreaHeight, cutOutBottomOffset) | |||
| result.success(true) | |||
| } | |||
| @@ -56,7 +56,8 @@ public class QRView:NSObject,FlutterPlatformView { | |||
| self?.setDimensions(result, | |||
| width: arguments["width"] ?? 0, | |||
| height: arguments["height"] ?? 0, | |||
| scanArea: arguments["scanArea"] ?? 0, | |||
| scanAreaWidth: arguments["scanAreaWidth"] ?? 0, | |||
| scanAreaHeight: arguments["scanAreaHeight"] ?? 0, | |||
| scanAreaOffset: arguments["scanAreaOffset"] ?? 0) | |||
| case "startScan": | |||
| self?.startScan(call.arguments as! Array<Int>, result) | |||
| @@ -84,7 +85,7 @@ public class QRView:NSObject,FlutterPlatformView { | |||
| return previewView | |||
| } | |||
| func setDimensions(_ result: @escaping FlutterResult, width: Double, height: Double, scanArea: Double, scanAreaOffset: Double) { | |||
| func setDimensions(_ result: @escaping FlutterResult, width: Double, height: Double, scanAreaWidth: Double, scanAreaHeight: Double, scanAreaOffset: Double) { | |||
| // Then set the size of the preview area. | |||
| previewView.frame = CGRect(x: 0, y: 0, width: width, height: height) | |||
| @@ -103,9 +104,9 @@ public class QRView:NSObject,FlutterPlatformView { | |||
| } | |||
| // Set scanArea if provided. | |||
| if (scanArea != 0) { | |||
| if (scanAreaWidth != 0 && scanAreaHeight != 0) { | |||
| scanner?.didStartScanningBlock = { | |||
| self.scanner?.scanRect = CGRect(x: Double(midX) - (scanArea / 2), y: Double(midY) - (scanArea / 2), width: scanArea, height: scanArea) | |||
| self.scanner?.scanRect = CGRect(x: Double(midX) - (scanAreaWidth / 2), y: Double(midY) - (scanAreaHeight / 2), width: scanAreaWidth, height: scanAreaHeight) | |||
| // Set offset if provided. | |||
| if (scanAreaOffset != 0) { | |||
| @@ -334,7 +334,8 @@ class QRViewController { | |||
| await channel.invokeMethod('setDimensions', { | |||
| 'width': renderBox.size.width, | |||
| 'height': renderBox.size.height, | |||
| 'scanArea': overlay?.cutOutSize ?? 0, | |||
| 'scanAreaWidth': overlay?.cutOutWidth ?? 0, | |||
| 'scanAreaHeight': overlay?.cutOutHeight ?? 0, | |||
| 'scanAreaOffset': overlay?.cutOutBottomOffset ?? 0 | |||
| }); | |||
| return true; | |||
| @@ -346,7 +347,8 @@ class QRViewController { | |||
| return false; | |||
| } | |||
| await channel.invokeMethod('changeScanArea', { | |||
| 'cutOutSize': overlay.cutOutSize, | |||
| 'scanAreaWidth': overlay.cutOutWidth, | |||
| 'scanAreaHeight': overlay.cutOutHeight, | |||
| 'cutOutBottomOffset': overlay.cutOutBottomOffset | |||
| }); | |||
| return true; | |||
| @@ -1,4 +1,5 @@ | |||
| import 'dart:ui'; | |||
| import 'dart:math'; | |||
| import 'package:flutter/material.dart'; | |||
| @@ -9,17 +10,30 @@ class QrScannerOverlayShape extends ShapeBorder { | |||
| this.overlayColor = const Color.fromRGBO(0, 0, 0, 80), | |||
| this.borderRadius = 0, | |||
| this.borderLength = 40, | |||
| this.cutOutSize = 250, | |||
| double? cutOutSize, | |||
| double? cutOutWidth, | |||
| double? cutOutHeight, | |||
| this.cutOutBottomOffset = 0, | |||
| }) : assert(borderLength <= cutOutSize / 2 + borderWidth * 2, | |||
| "Border can't be larger than ${cutOutSize / 2 + borderWidth * 2}"); | |||
| }) : cutOutWidth = cutOutWidth ?? cutOutSize ?? 250, | |||
| cutOutHeight = cutOutHeight ?? cutOutSize ?? 250 { | |||
| assert( | |||
| borderLength <= | |||
| min(this.cutOutWidth, this.cutOutHeight) / 2 + borderWidth * 2, | |||
| "Border can't be larger than ${min(this.cutOutWidth, this.cutOutHeight) / 2 + borderWidth * 2}", | |||
| ); | |||
| assert( | |||
| (cutOutSize != null && cutOutWidth == null && cutOutHeight == null) || | |||
| (cutOutSize == null && cutOutWidth != null && cutOutHeight != null), | |||
| 'Use only cutOutWidth and cutOutHeight or only cutOutSize'); | |||
| } | |||
| final Color borderColor; | |||
| final double borderWidth; | |||
| final Color overlayColor; | |||
| final double borderRadius; | |||
| final double borderLength; | |||
| final double cutOutSize; | |||
| final double cutOutWidth; | |||
| final double cutOutHeight; | |||
| final double cutOutBottomOffset; | |||
| @override | |||
| @@ -62,10 +76,14 @@ class QrScannerOverlayShape extends ShapeBorder { | |||
| final borderWidthSize = width / 2; | |||
| final height = rect.height; | |||
| final borderOffset = borderWidth / 2; | |||
| final _borderLength = borderLength > cutOutSize / 2 + borderWidth * 2 | |||
| ? borderWidthSize / 2 | |||
| : borderLength; | |||
| final _cutOutSize = cutOutSize < width ? cutOutSize : width - borderOffset; | |||
| final _borderLength = | |||
| borderLength > min(cutOutHeight, cutOutHeight) / 2 + borderWidth * 2 | |||
| ? borderWidthSize / 2 | |||
| : borderLength; | |||
| final _cutOutWidth = | |||
| cutOutWidth < width ? cutOutWidth : width - borderOffset; | |||
| final _cutOutHeight = | |||
| cutOutHeight < height ? cutOutHeight : height - borderOffset; | |||
| final backgroundPaint = Paint() | |||
| ..color = overlayColor | |||
| @@ -82,14 +100,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 | |||