From 7d12605a7b2a311a35a36bfdf46b477c954827a0 Mon Sep 17 00:00:00 2001 From: Julian Steenbakker Date: Mon, 21 Dec 2020 16:56:14 +0100 Subject: [PATCH 1/6] Added scanArea for iOS. --- example/ios/Runner.xcodeproj/project.pbxproj | 16 +++++++--------- example/lib/main.dart | 16 +++++++++++++--- ios/Classes/QRView.swift | 18 +++++++++++++++--- lib/src/qr_code_scanner.dart | 20 ++++++++++++-------- 4 files changed, 47 insertions(+), 23 deletions(-) diff --git a/example/ios/Runner.xcodeproj/project.pbxproj b/example/ios/Runner.xcodeproj/project.pbxproj index 1bb97b9..8a96753 100644 --- a/example/ios/Runner.xcodeproj/project.pbxproj +++ b/example/ios/Runner.xcodeproj/project.pbxproj @@ -168,7 +168,7 @@ TargetAttributes = { 97C146ED1CF9000F007C117D = { CreatedOnToolsVersion = 7.3.1; - DevelopmentTeam = 5LSCTACHT8; + DevelopmentTeam = RCH2VG82SH; LastSwiftMigration = 1020; ProvisioningStyle = Automatic; }; @@ -250,13 +250,11 @@ ); inputPaths = ( "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh", - "${PODS_ROOT}/../Flutter/Flutter.framework", "${BUILT_PRODUCTS_DIR}/MTBBarcodeScanner/MTBBarcodeScanner.framework", "${BUILT_PRODUCTS_DIR}/qr_code_scanner/qr_code_scanner.framework", ); name = "[CP] Embed Pods Frameworks"; outputPaths = ( - "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Flutter.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/MTBBarcodeScanner.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/qr_code_scanner.framework", ); @@ -372,7 +370,7 @@ CODE_SIGN_IDENTITY = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; - DEVELOPMENT_TEAM = 5LSCTACHT8; + DEVELOPMENT_TEAM = RCH2VG82SH; ENABLE_BITCODE = NO; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -384,7 +382,7 @@ "$(inherited)", "$(PROJECT_DIR)/Flutter", ); - PRODUCT_BUNDLE_IDENTIFIER = dev.steenbakker.capture; + PRODUCT_BUNDLE_IDENTIFIER = dev.steenbakker.camera; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; SWIFT_VERSION = 4.0; @@ -510,7 +508,7 @@ CODE_SIGN_IDENTITY = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; - DEVELOPMENT_TEAM = 5LSCTACHT8; + DEVELOPMENT_TEAM = RCH2VG82SH; ENABLE_BITCODE = NO; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -522,7 +520,7 @@ "$(inherited)", "$(PROJECT_DIR)/Flutter", ); - PRODUCT_BUNDLE_IDENTIFIER = dev.steenbakker.capture; + PRODUCT_BUNDLE_IDENTIFIER = dev.steenbakker.camera; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; @@ -541,7 +539,7 @@ CODE_SIGN_IDENTITY = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; - DEVELOPMENT_TEAM = 5LSCTACHT8; + DEVELOPMENT_TEAM = RCH2VG82SH; ENABLE_BITCODE = NO; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -553,7 +551,7 @@ "$(inherited)", "$(PROJECT_DIR)/Flutter", ); - PRODUCT_BUNDLE_IDENTIFIER = dev.steenbakker.capture; + PRODUCT_BUNDLE_IDENTIFIER = dev.steenbakker.camera; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; diff --git a/example/lib/main.dart b/example/lib/main.dart index 4d5680c..2cdab32 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -1,3 +1,5 @@ +import 'dart:io'; + import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:qr_code_scanner/qr_code_scanner.dart'; @@ -25,10 +27,16 @@ class _QRViewExampleState extends State { QRViewController controller; final GlobalKey qrKey = GlobalKey(debugLabel: 'QR'); + // In order to get hot reload to work we need to pause the camera if the platform + // is android, or resume the camera if the platform is iOS. @override void reassemble() { super.reassemble(); - controller.pauseCamera(); + if (Platform.isAndroid) { + controller.pauseCamera(); + } else if (Platform.isIOS) { + controller.resumeCamera(); + } } @override @@ -139,11 +147,13 @@ class _QRViewExampleState extends State { } Widget _buildQrView(BuildContext context) { + // For this example we check how width or tall the device is and change the scanArea and overlay accordingly. + double scanArea = (MediaQuery.of(context).size.width < 500 || MediaQuery.of(context).size.height < 400) ? 150 : 300; // To ensure the Scanner view is properly sizes after rotation // we need to listen for Flutter SizeChanged notification and update controller return NotificationListener( onNotification: (notification) { - Future.microtask(() => controller?.updateDimensions(qrKey)); + Future.microtask(() => controller?.updateDimensions(qrKey, scanArea: scanArea)); return false; }, child: SizeChangedLayoutNotifier( @@ -156,7 +166,7 @@ class _QRViewExampleState extends State { borderRadius: 10, borderLength: 30, borderWidth: 10, - cutOutSize: 300, + cutOutSize: scanArea, ), ))); } diff --git a/ios/Classes/QRView.swift b/ios/Classes/QRView.swift index eeb3bfd..8f1097c 100644 --- a/ios/Classes/QRView.swift +++ b/ios/Classes/QRView.swift @@ -13,15 +13,18 @@ public class QRView:NSObject,FlutterPlatformView { var scanner: MTBBarcodeScanner? var registrar: FlutterPluginRegistrar var channel: FlutterMethodChannel + var frame: CGRect public init(withFrame frame: CGRect, withRegistrar registrar: FlutterPluginRegistrar, withId id: Int64){ self.registrar = registrar + self.frame = frame previewView = UIView(frame: frame) channel = FlutterMethodChannel(name: "net.touchcapture.qr.flutterqr/qrview_\(id)", binaryMessenger: registrar.messenger()) } func isCameraAvailable(success: Bool) -> Void { if success { + do { try scanner?.startScanning(resultBlock: { [weak self] codes in if let codes = codes { @@ -74,7 +77,7 @@ public class QRView:NSObject,FlutterPlatformView { switch(call.method){ case "setDimensions": let arguments = call.arguments as! Dictionary - self?.setDimensions(width: arguments["width"] ?? 0,height: arguments["height"] ?? 0) + self?.setDimensions(width: arguments["width"] ?? 0, height: arguments["height"] ?? 0, scanArea: arguments["scanArea"] ?? 0) case "flipCamera": self?.flipCamera() case "toggleFlash": @@ -91,15 +94,24 @@ public class QRView:NSObject,FlutterPlatformView { return previewView } - func setDimensions(width: Double, height: Double) -> Void { + func setDimensions(width: Double, height: Double, scanArea: Double) -> Void { previewView.frame = CGRect(x: 0, y: 0, width: width, height: height) - + let midX = self.view().bounds.midX + let midY = self.view().bounds.midY if let sc: MTBBarcodeScanner = scanner { if let previewLayer = sc.previewLayer { previewLayer.frame = previewView.bounds; } } else { scanner = MTBBarcodeScanner(previewView: previewView) + + if (scanArea != 0) { + scanner?.didStartScanningBlock = { + self.scanner?.scanRect = CGRect(x: Double(midX) - (scanArea / 2), y: Double(midY) - (scanArea / 2), width: scanArea, height: scanArea) + } + } + + MTBBarcodeScanner.requestCameraPermission(success: isCameraAvailable) } } diff --git a/lib/src/qr_code_scanner.dart b/lib/src/qr_code_scanner.dart index 451f240..5b583c1 100644 --- a/lib/src/qr_code_scanner.dart +++ b/lib/src/qr_code_scanner.dart @@ -3,6 +3,7 @@ import 'dart:async'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; +import 'package:qr_code_scanner/qr_code_scanner.dart'; typedef QRViewCreatedCallback = void Function(QRViewController); @@ -110,7 +111,7 @@ class _QRViewState extends State { Widget build(BuildContext context) { return Stack( children: [ - _getPlatformQrView(), + _getPlatformQrView(widget.key), if (widget.overlay != null) Container( padding: widget.overlayMargin, @@ -124,7 +125,7 @@ class _QRViewState extends State { ); } - Widget _getPlatformQrView() { + Widget _getPlatformQrView(GlobalKey key) { Widget _platformQrView; switch (defaultTargetPlatform) { case TargetPlatform.android: @@ -137,7 +138,7 @@ class _QRViewState extends State { _platformQrView = UiKitView( viewType: 'net.touchcapture.qr.flutterqr/qrview', onPlatformViewCreated: _onPlatformViewCreated, - creationParams: _CreationParams.fromWidget(0, 0).toMap(), + creationParams: _CreationParams.fromWidget(MediaQuery.of(context).size.width, 400).toMap(), creationParamsCodec: StandardMessageCodec(), ); break; @@ -152,7 +153,8 @@ class _QRViewState extends State { if (widget.onQRViewCreated == null) { return; } - widget.onQRViewCreated(QRViewController._(id, widget.key)); + + widget.onQRViewCreated(QRViewController._(id, widget.key, (widget.overlay as QrScannerOverlayShape).cutOutSize)); } } @@ -178,9 +180,9 @@ class _CreationParams { } class QRViewController { - QRViewController._(int id, GlobalKey qrKey) + QRViewController._(int id, GlobalKey qrKey, double scanArea) : _channel = MethodChannel('net.touchcapture.qr.flutterqr/qrview_$id') { - updateDimensions(qrKey); + updateDimensions(qrKey, scanArea: scanArea); _channel.setMethodCallHandler( (call) async { switch (call.method) { @@ -231,11 +233,13 @@ class QRViewController { _scanUpdateController.close(); } - void updateDimensions(GlobalKey key) { + void updateDimensions(GlobalKey key, {double scanArea}) { if (defaultTargetPlatform == TargetPlatform.iOS) { final RenderBox renderBox = key.currentContext.findRenderObject(); _channel.invokeMethod('setDimensions', - {'width': renderBox.size.width, 'height': renderBox.size.height}); + {'width': renderBox.size.width, + 'height': renderBox.size.height, + 'scanArea': scanArea?? 0}); } } } From 4a429d61a33d6610058232e9ef3e67dd6d895023 Mon Sep 17 00:00:00 2001 From: Julian Steenbakker Date: Mon, 21 Dec 2020 20:41:08 +0100 Subject: [PATCH 2/6] Reformat with dartfmt --- example/lib/main.dart | 8 ++++++-- lib/src/qr_code_scanner.dart | 16 ++++++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index 2cdab32..5134972 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -148,12 +148,16 @@ class _QRViewExampleState extends State { Widget _buildQrView(BuildContext context) { // For this example we check how width or tall the device is and change the scanArea and overlay accordingly. - double scanArea = (MediaQuery.of(context).size.width < 500 || MediaQuery.of(context).size.height < 400) ? 150 : 300; + double scanArea = (MediaQuery.of(context).size.width < 500 || + MediaQuery.of(context).size.height < 400) + ? 150 + : 300; // To ensure the Scanner view is properly sizes after rotation // we need to listen for Flutter SizeChanged notification and update controller return NotificationListener( onNotification: (notification) { - Future.microtask(() => controller?.updateDimensions(qrKey, scanArea: scanArea)); + Future.microtask( + () => controller?.updateDimensions(qrKey, scanArea: scanArea)); return false; }, child: SizeChangedLayoutNotifier( diff --git a/lib/src/qr_code_scanner.dart b/lib/src/qr_code_scanner.dart index 5b583c1..aa7d20a 100644 --- a/lib/src/qr_code_scanner.dart +++ b/lib/src/qr_code_scanner.dart @@ -138,7 +138,9 @@ class _QRViewState extends State { _platformQrView = UiKitView( viewType: 'net.touchcapture.qr.flutterqr/qrview', onPlatformViewCreated: _onPlatformViewCreated, - creationParams: _CreationParams.fromWidget(MediaQuery.of(context).size.width, 400).toMap(), + creationParams: + _CreationParams.fromWidget(MediaQuery.of(context).size.width, 400) + .toMap(), creationParamsCodec: StandardMessageCodec(), ); break; @@ -154,7 +156,8 @@ class _QRViewState extends State { return; } - widget.onQRViewCreated(QRViewController._(id, widget.key, (widget.overlay as QrScannerOverlayShape).cutOutSize)); + widget.onQRViewCreated(QRViewController._( + id, widget.key, (widget.overlay as QrScannerOverlayShape).cutOutSize)); } } @@ -236,10 +239,11 @@ class QRViewController { void updateDimensions(GlobalKey key, {double scanArea}) { if (defaultTargetPlatform == TargetPlatform.iOS) { final RenderBox renderBox = key.currentContext.findRenderObject(); - _channel.invokeMethod('setDimensions', - {'width': renderBox.size.width, - 'height': renderBox.size.height, - 'scanArea': scanArea?? 0}); + _channel.invokeMethod('setDimensions', { + 'width': renderBox.size.width, + 'height': renderBox.size.height, + 'scanArea': scanArea ?? 0 + }); } } } From 6238a86fa530868ea1ca62688da422c2e66aa451 Mon Sep 17 00:00:00 2001 From: Julian Steenbakker Date: Mon, 21 Dec 2020 20:45:00 +0100 Subject: [PATCH 3/6] Updated barcode check to inline check. Updated README.md. --- example/lib/main.dart | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index 5134972..68efd50 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -148,10 +148,10 @@ class _QRViewExampleState extends State { Widget _buildQrView(BuildContext context) { // For this example we check how width or tall the device is and change the scanArea and overlay accordingly. - double scanArea = (MediaQuery.of(context).size.width < 500 || + var scanArea = (MediaQuery.of(context).size.width < 500 || MediaQuery.of(context).size.height < 400) - ? 150 - : 300; + ? 150.0 + : 300.0; // To ensure the Scanner view is properly sizes after rotation // we need to listen for Flutter SizeChanged notification and update controller return NotificationListener( From b4ee3d78dc4ae43ed051b978f8483e04e6b8600b Mon Sep 17 00:00:00 2001 From: Julian Steenbakker Date: Mon, 21 Dec 2020 22:16:52 +0100 Subject: [PATCH 4/6] Updated example. --- example/lib/main.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index 68efd50..beb8d51 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -148,7 +148,7 @@ class _QRViewExampleState extends State { Widget _buildQrView(BuildContext context) { // For this example we check how width or tall the device is and change the scanArea and overlay accordingly. - var scanArea = (MediaQuery.of(context).size.width < 500 || + var scanArea = (MediaQuery.of(context).size.width < 400 || MediaQuery.of(context).size.height < 400) ? 150.0 : 300.0; From ac236ecb050d51d3f8ddc7f5080e9fc598ca7fc9 Mon Sep 17 00:00:00 2001 From: Julian Steenbakker Date: Mon, 21 Dec 2020 22:31:26 +0100 Subject: [PATCH 5/6] Removed redundant var. --- example/ios/Runner.xcodeproj/project.pbxproj | 16 +++++++++------- ios/Classes/QRView.swift | 4 ---- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/example/ios/Runner.xcodeproj/project.pbxproj b/example/ios/Runner.xcodeproj/project.pbxproj index 8a96753..df30a3b 100644 --- a/example/ios/Runner.xcodeproj/project.pbxproj +++ b/example/ios/Runner.xcodeproj/project.pbxproj @@ -168,7 +168,7 @@ TargetAttributes = { 97C146ED1CF9000F007C117D = { CreatedOnToolsVersion = 7.3.1; - DevelopmentTeam = RCH2VG82SH; + DevelopmentTeam = 5LSCTACHT8; LastSwiftMigration = 1020; ProvisioningStyle = Automatic; }; @@ -250,11 +250,13 @@ ); inputPaths = ( "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh", + "${PODS_ROOT}/../Flutter/Flutter.framework", "${BUILT_PRODUCTS_DIR}/MTBBarcodeScanner/MTBBarcodeScanner.framework", "${BUILT_PRODUCTS_DIR}/qr_code_scanner/qr_code_scanner.framework", ); name = "[CP] Embed Pods Frameworks"; outputPaths = ( + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Flutter.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/MTBBarcodeScanner.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/qr_code_scanner.framework", ); @@ -370,7 +372,7 @@ CODE_SIGN_IDENTITY = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; - DEVELOPMENT_TEAM = RCH2VG82SH; + DEVELOPMENT_TEAM = 5LSCTACHT8; ENABLE_BITCODE = NO; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -382,7 +384,7 @@ "$(inherited)", "$(PROJECT_DIR)/Flutter", ); - PRODUCT_BUNDLE_IDENTIFIER = dev.steenbakker.camera; + PRODUCT_BUNDLE_IDENTIFIER = dev.steenbakker.qr; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; SWIFT_VERSION = 4.0; @@ -508,7 +510,7 @@ CODE_SIGN_IDENTITY = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; - DEVELOPMENT_TEAM = RCH2VG82SH; + DEVELOPMENT_TEAM = 5LSCTACHT8; ENABLE_BITCODE = NO; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -520,7 +522,7 @@ "$(inherited)", "$(PROJECT_DIR)/Flutter", ); - PRODUCT_BUNDLE_IDENTIFIER = dev.steenbakker.camera; + PRODUCT_BUNDLE_IDENTIFIER = dev.steenbakker.qr; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; @@ -539,7 +541,7 @@ CODE_SIGN_IDENTITY = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; - DEVELOPMENT_TEAM = RCH2VG82SH; + DEVELOPMENT_TEAM = 5LSCTACHT8; ENABLE_BITCODE = NO; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -551,7 +553,7 @@ "$(inherited)", "$(PROJECT_DIR)/Flutter", ); - PRODUCT_BUNDLE_IDENTIFIER = dev.steenbakker.camera; + PRODUCT_BUNDLE_IDENTIFIER = dev.steenbakker.qr; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; diff --git a/ios/Classes/QRView.swift b/ios/Classes/QRView.swift index 8f1097c..298f7a9 100644 --- a/ios/Classes/QRView.swift +++ b/ios/Classes/QRView.swift @@ -13,18 +13,15 @@ public class QRView:NSObject,FlutterPlatformView { var scanner: MTBBarcodeScanner? var registrar: FlutterPluginRegistrar var channel: FlutterMethodChannel - var frame: CGRect public init(withFrame frame: CGRect, withRegistrar registrar: FlutterPluginRegistrar, withId id: Int64){ self.registrar = registrar - self.frame = frame previewView = UIView(frame: frame) channel = FlutterMethodChannel(name: "net.touchcapture.qr.flutterqr/qrview_\(id)", binaryMessenger: registrar.messenger()) } func isCameraAvailable(success: Bool) -> Void { if success { - do { try scanner?.startScanning(resultBlock: { [weak self] codes in if let codes = codes { @@ -56,7 +53,6 @@ public class QRView:NSObject,FlutterPlatformView { default: return } - guard let stringValue = code.stringValue else { continue } let result = ["code": stringValue, "type": typeString] self?.channel.invokeMethod("onRecognizeQR", arguments: result) From 9cfc124f9feab305d59123f9eff996c71821e932 Mon Sep 17 00:00:00 2001 From: Julian Steenbakker Date: Mon, 21 Dec 2020 22:39:39 +0100 Subject: [PATCH 6/6] Updated README.md --- README.md | 10 +++++++--- example/README.md | 24 ++++++++++++++++++------ 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 973c25c..3a95069 100644 --- a/README.md +++ b/README.md @@ -56,12 +56,16 @@ class _QRViewExampleState extends State { Barcode result; QRViewController controller; - /// Overriding reassemble and pausing the camera - /// ensures us that hot reload won't give a black screen + // In order to get hot reload to work we need to pause the camera if the platform + // is android, or resume the camera if the platform is iOS. @override void reassemble() { super.reassemble(); - controller.pauseCamera(); + if (Platform.isAndroid) { + controller.pauseCamera(); + } else if (Platform.isIOS) { + controller.resumeCamera(); + } } @override diff --git a/example/README.md b/example/README.md index 866b9a4..20d5579 100644 --- a/example/README.md +++ b/example/README.md @@ -47,12 +47,16 @@ class _QRViewExampleState extends State { QRViewController controller; final GlobalKey qrKey = GlobalKey(debugLabel: 'QR'); - /// Overriding reassemble and pausing the camera - /// ensures us that hot reload won't give a black screen + // In order to get hot reload to work we need to pause the camera if the platform + // is android, or resume the camera if the platform is iOS. @override void reassemble() { super.reassemble(); - controller.pauseCamera(); + if (Platform.isAndroid) { + controller.pauseCamera(); + } else if (Platform.isIOS) { + controller.resumeCamera(); + } } @override @@ -69,7 +73,8 @@ class _QRViewExampleState extends State { mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ if (result != null) - Text('Barcode Type: ${describeEnum(result.format)} Data: ${result.code}') + Text( + 'Barcode Type: ${describeEnum(result.format)} Data: ${result.code}') else Text('Scan a code'), Row( @@ -162,11 +167,17 @@ class _QRViewExampleState extends State { } Widget _buildQrView(BuildContext context) { + // For this example we check how width or tall the device is and change the scanArea and overlay accordingly. + var scanArea = (MediaQuery.of(context).size.width < 400 || + MediaQuery.of(context).size.height < 400) + ? 150.0 + : 300.0; // To ensure the Scanner view is properly sizes after rotation // we need to listen for Flutter SizeChanged notification and update controller return NotificationListener( onNotification: (notification) { - Future.microtask(() => controller?.updateDimensions(qrKey)); + Future.microtask( + () => controller?.updateDimensions(qrKey, scanArea: scanArea)); return false; }, child: SizeChangedLayoutNotifier( @@ -179,7 +190,7 @@ class _QRViewExampleState extends State { borderRadius: 10, borderLength: 30, borderWidth: 10, - cutOutSize: 300, + cutOutSize: scanArea, ), ))); } @@ -201,6 +212,7 @@ class _QRViewExampleState extends State { } + ```