From 471c4533e64272379094d409baac4b0a0cde2b93 Mon Sep 17 00:00:00 2001 From: Tihomirov <56314363+OrangeSofter@users.noreply.github.com> Date: Fri, 1 Oct 2021 18:59:15 +0300 Subject: [PATCH 1/9] Field cutOutSize changed to cutOutWidth and cutOutHeight --- lib/src/qr_scanner_overlay_shape.dart | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/src/qr_scanner_overlay_shape.dart b/lib/src/qr_scanner_overlay_shape.dart index 1b11dfb4..653e3b6c 100644 --- a/lib/src/qr_scanner_overlay_shape.dart +++ b/lib/src/qr_scanner_overlay_shape.dart @@ -9,9 +9,9 @@ class QrScannerOverlayShape extends ShapeBorder { this.overlayColor = const Color.fromRGBO(0, 0, 0, 80), this.borderRadius = 0, this.borderLength = 40, - this.cutOutSize = 250, + double cutOutSize = 250, this.cutOutBottomOffset = 0, - }) : assert(borderLength <= cutOutSize / 2 + borderWidth * 2, + }) : cutOutWidth = cutOutSize, cutOutHeight = cutOutSize, assert(borderLength <= cutOutSize / 2 + borderWidth * 2, "Border can't be larger than ${cutOutSize / 2 + borderWidth * 2}"); final Color borderColor; @@ -19,7 +19,8 @@ class QrScannerOverlayShape extends ShapeBorder { final Color overlayColor; final double borderRadius; final double borderLength; - final double cutOutSize; + final double cutOutWidth; + final double cutOutHeight; final double cutOutBottomOffset; @override From d8f5a0eb8260796e5f8c3b97ac0b2abdd8736b2c Mon Sep 17 00:00:00 2001 From: Tihomirov <56314363+OrangeSofter@users.noreply.github.com> Date: Fri, 1 Oct 2021 20:37:07 +0300 Subject: [PATCH 2/9] Fixed QrScannerOverlayShape constructor --- lib/src/qr_scanner_overlay_shape.dart | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/src/qr_scanner_overlay_shape.dart b/lib/src/qr_scanner_overlay_shape.dart index 653e3b6c..a0a4159d 100644 --- a/lib/src/qr_scanner_overlay_shape.dart +++ b/lib/src/qr_scanner_overlay_shape.dart @@ -1,4 +1,5 @@ import 'dart:ui'; +import 'dart:math'; import 'package:flutter/material.dart'; @@ -9,10 +10,20 @@ class QrScannerOverlayShape extends ShapeBorder { this.overlayColor = const Color.fromRGBO(0, 0, 0, 80), this.borderRadius = 0, this.borderLength = 40, - double cutOutSize = 250, + double? cutOutSize, + double? cutOutWidth, + double? cutOutHeight, this.cutOutBottomOffset = 0, - }) : cutOutWidth = cutOutSize, cutOutHeight = cutOutSize, 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; From fe4a11bbb88924bfc67936cdb7adc783d00f1d3f Mon Sep 17 00:00:00 2001 From: Tihomirov Date: Tue, 5 Oct 2021 13:25:11 +0300 Subject: [PATCH 3/9] =?UTF-8?q?=D0=A1ode=20formatting?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/src/qr_scanner_overlay_shape.dart | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/src/qr_scanner_overlay_shape.dart b/lib/src/qr_scanner_overlay_shape.dart index a0a4159d..1d233f1e 100644 --- a/lib/src/qr_scanner_overlay_shape.dart +++ b/lib/src/qr_scanner_overlay_shape.dart @@ -14,15 +14,17 @@ class QrScannerOverlayShape extends ShapeBorder { double? cutOutWidth, double? cutOutHeight, this.cutOutBottomOffset = 0, - }): cutOutWidth = cutOutWidth ?? cutOutSize ?? 250, - cutOutHeight = cutOutHeight ?? cutOutSize ?? 250 { + }) : cutOutWidth = cutOutWidth ?? cutOutSize ?? 250, + cutOutHeight = cutOutHeight ?? cutOutSize ?? 250 { assert( - borderLength <= min(this.cutOutWidth, this.cutOutHeight) / 2 + borderWidth * 2, + 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' - ); + assert( + (cutOutSize != null && cutOutWidth == null && cutOutHeight == null) || + (cutOutSize == null && cutOutWidth != null && cutOutHeight != null), + 'Use only cutOutWidth and cutOutHeight or only cutOutSize'); } final Color borderColor; From 4d6a2dbc47b291f1a670895d8c7f98e8e25b6430 Mon Sep 17 00:00:00 2001 From: Tihomirov Date: Tue, 5 Oct 2021 15:08:06 +0300 Subject: [PATCH 4/9] Completed QrScannerOverlayShape logic --- lib/src/qr_code_scanner.dart | 4 ++-- lib/src/qr_scanner_overlay_shape.dart | 13 +++++++------ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/src/qr_code_scanner.dart b/lib/src/qr_code_scanner.dart index 22876eea..9faf3aff 100644 --- a/lib/src/qr_code_scanner.dart +++ b/lib/src/qr_code_scanner.dart @@ -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; diff --git a/lib/src/qr_scanner_overlay_shape.dart b/lib/src/qr_scanner_overlay_shape.dart index 1d233f1e..b101652a 100644 --- a/lib/src/qr_scanner_overlay_shape.dart +++ b/lib/src/qr_scanner_overlay_shape.dart @@ -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 From febcbdf6aa3db8ec7a35ad6deafb3f4129948df7 Mon Sep 17 00:00:00 2001 From: Tihomirov Date: Tue, 5 Oct 2021 15:20:35 +0300 Subject: [PATCH 5/9] =?UTF-8?q?=D0=A1orrect=20scan=20area=20size=20for=20a?= =?UTF-8?q?ndroid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/kotlin/net/touchcapture/qr/flutterqr/QRView.kt | 8 +++++--- lib/src/qr_code_scanner.dart | 3 ++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/android/src/main/kotlin/net/touchcapture/qr/flutterqr/QRView.kt b/android/src/main/kotlin/net/touchcapture/qr/flutterqr/QRView.kt index 87501582..0369775e 100644 --- a/android/src/main/kotlin/net/touchcapture/qr/flutterqr/QRView.kt +++ b/android/src/main/kotlin/net/touchcapture/qr/flutterqr/QRView.kt @@ -89,7 +89,8 @@ class QRView(private val context: Context, messenger: BinaryMessenger, private v "getFlashInfo" -> getFlashInfo(result) "getSystemFeatures" -> getSystemFeatures(result) "changeScanArea" -> changeScanArea( - call.argument("cutOutSize")!!, + call.argument("scanAreaWidth")!!, + call.argument("scanAreaHeight")!!, call.argument("cutOutBottomOffset")!!, result, ) @@ -253,11 +254,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) } diff --git a/lib/src/qr_code_scanner.dart b/lib/src/qr_code_scanner.dart index 9faf3aff..88b0d421 100644 --- a/lib/src/qr_code_scanner.dart +++ b/lib/src/qr_code_scanner.dart @@ -346,7 +346,8 @@ class QRViewController { return false; } await channel.invokeMethod('changeScanArea', { - 'cutOutSize': overlay.cutOutWidth,//Todo + 'scanAreaWidth': overlay.cutOutWidth, + 'scanAreaHeight': overlay.cutOutHeight, 'cutOutBottomOffset': overlay.cutOutBottomOffset }); return true; From 45b940744b1635b1764d1dc052ae46ef4d0ce371 Mon Sep 17 00:00:00 2001 From: Tihomirov Date: Tue, 5 Oct 2021 15:39:20 +0300 Subject: [PATCH 6/9] Formatting code --- lib/src/qr_code_scanner.dart | 2 +- lib/src/qr_scanner_overlay_shape.dart | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/src/qr_code_scanner.dart b/lib/src/qr_code_scanner.dart index 88b0d421..a194395c 100644 --- a/lib/src/qr_code_scanner.dart +++ b/lib/src/qr_code_scanner.dart @@ -334,7 +334,7 @@ class QRViewController { await channel.invokeMethod('setDimensions', { 'width': renderBox.size.width, 'height': renderBox.size.height, - 'scanArea': overlay?.cutOutWidth ?? 0,//Todo + 'scanArea': overlay?.cutOutWidth ?? 0, //Todo 'scanAreaOffset': overlay?.cutOutBottomOffset ?? 0 }); return true; diff --git a/lib/src/qr_scanner_overlay_shape.dart b/lib/src/qr_scanner_overlay_shape.dart index b101652a..0d41090c 100644 --- a/lib/src/qr_scanner_overlay_shape.dart +++ b/lib/src/qr_scanner_overlay_shape.dart @@ -76,11 +76,14 @@ class QrScannerOverlayShape extends ShapeBorder { final borderWidthSize = width / 2; final height = rect.height; final borderOffset = borderWidth / 2; - 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 _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 From b2ba000daf964b6514097202955b4422995a9c7b Mon Sep 17 00:00:00 2001 From: Tihomirov Date: Tue, 5 Oct 2021 16:39:28 +0300 Subject: [PATCH 7/9] Correct scan area size on ios --- ios/Classes/QRView.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ios/Classes/QRView.swift b/ios/Classes/QRView.swift index 21661eee..ac6931ed 100644 --- a/ios/Classes/QRView.swift +++ b/ios/Classes/QRView.swift @@ -84,7 +84,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 +103,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) { From f6ea193af2c8a3439c78629f16d02c3d18914d76 Mon Sep 17 00:00:00 2001 From: Tihomirov Date: Tue, 5 Oct 2021 17:12:44 +0300 Subject: [PATCH 8/9] Calling the function with passing the parameters of the width and height of the scanning area for IOS --- ios/Classes/QRView.swift | 3 ++- lib/src/qr_code_scanner.dart | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/ios/Classes/QRView.swift b/ios/Classes/QRView.swift index ac6931ed..5300af5c 100644 --- a/ios/Classes/QRView.swift +++ b/ios/Classes/QRView.swift @@ -56,7 +56,8 @@ public class QRView:NSObject,FlutterPlatformView { self?.setDimensions(result, width: arguments["width"] ?? 0, height: arguments["height"] ?? 0, - scanArea: arguments["scanArea"] ?? 0, + scanArea: arguments["scanAreaWidth"] ?? 0, + scanArea: arguments["scanAreaHeight"] ?? 0, scanAreaOffset: arguments["scanAreaOffset"] ?? 0) case "startScan": self?.startScan(call.arguments as! Array, result) diff --git a/lib/src/qr_code_scanner.dart b/lib/src/qr_code_scanner.dart index a194395c..238529c9 100644 --- a/lib/src/qr_code_scanner.dart +++ b/lib/src/qr_code_scanner.dart @@ -334,7 +334,8 @@ class QRViewController { await channel.invokeMethod('setDimensions', { 'width': renderBox.size.width, 'height': renderBox.size.height, - 'scanArea': overlay?.cutOutWidth ?? 0, //Todo + 'scanAreaWidth': overlay?.cutOutWidth ?? 0, + 'scanAreaHeight': overlay?.cutOutHeight ?? 0, 'scanAreaOffset': overlay?.cutOutBottomOffset ?? 0 }); return true; From 81ff47ce3a1a9e9636f30933469f36d41c26687f Mon Sep 17 00:00:00 2001 From: Tihomirov Date: Tue, 5 Oct 2021 17:16:24 +0300 Subject: [PATCH 9/9] Fixed parameters names --- ios/Classes/QRView.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ios/Classes/QRView.swift b/ios/Classes/QRView.swift index 5300af5c..e91caf88 100644 --- a/ios/Classes/QRView.swift +++ b/ios/Classes/QRView.swift @@ -56,8 +56,8 @@ public class QRView:NSObject,FlutterPlatformView { self?.setDimensions(result, width: arguments["width"] ?? 0, height: arguments["height"] ?? 0, - scanArea: arguments["scanAreaWidth"] ?? 0, - scanArea: arguments["scanAreaHeight"] ?? 0, + scanAreaWidth: arguments["scanAreaWidth"] ?? 0, + scanAreaHeight: arguments["scanAreaHeight"] ?? 0, scanAreaOffset: arguments["scanAreaOffset"] ?? 0) case "startScan": self?.startScan(call.arguments as! Array, result)