From 4455cf83027b6d5b736ce1c0b6e973608f4dc3fe Mon Sep 17 00:00:00 2001 From: Akshay Kalbhor Date: Tue, 16 Nov 2021 22:11:47 +0530 Subject: [PATCH] add invert scan feature for android --- .../kotlin/net/touchcapture/qr/flutterqr/QRView.kt | 9 +++++++++ lib/src/qr_code_scanner.dart | 12 ++++++++++++ 2 files changed, 21 insertions(+) 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 3578f44..bef7b31 100644 --- a/android/src/main/kotlin/net/touchcapture/qr/flutterqr/QRView.kt +++ b/android/src/main/kotlin/net/touchcapture/qr/flutterqr/QRView.kt @@ -90,6 +90,7 @@ class QRView(private val context: Context, messenger: BinaryMessenger, private v call.argument("cutOutBottomOffset")!!, result, ) + "invertScan" -> setInvertScan(call.argument("isInvertScan")!!, result) else -> result.notImplemented() } } @@ -259,6 +260,14 @@ class QRView(private val context: Context, messenger: BinaryMessenger, private v result.success(true) } + private fun setInvertScan(isInvert: Boolean, result: MethodChannel.Result) { + barcodeView!!.pause() + val settings = barcodeView!!.cameraSettings + settings.isScanInverted = isInvert + barcodeView!!.cameraSettings = settings + barcodeView!!.resume(); + } + private fun setScanAreaSize( dpScanAreaWidth: Double, dpScanAreaHeight: Double, diff --git a/lib/src/qr_code_scanner.dart b/lib/src/qr_code_scanner.dart index e675289..8627b8b 100644 --- a/lib/src/qr_code_scanner.dart +++ b/lib/src/qr_code_scanner.dart @@ -357,4 +357,16 @@ class QRViewController { } return false; } + + //Starts/Stops invert scanning. + Future scanInvert(bool isScanInvert) async { + if (defaultTargetPlatform == TargetPlatform.android) { + try { + await _channel + .invokeMethod('invertScan', {"isInvertScan": isScanInvert}); + } on PlatformException catch (e) { + throw CameraException(e.code, e.message); + } + } + } }