From 917c985c6b71f2f34ee2ae228ec6cb057a4dbcea Mon Sep 17 00:00:00 2001 From: Julian Steenbakker Date: Mon, 21 Dec 2020 11:59:51 +0100 Subject: [PATCH 1/4] Update README.md --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 973c25c..476deff 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,14 @@ A QR code scanner that works on both iOS and Android by natively embedding the platform view within Flutter. The integration with Flutter is seamless, much better than jumping into a native Activity or a ViewController to perform the scan. +# *Warning* +If you are using Flutter Beta or Dev channel (1.25 or 1.26) you can get the following error: + +`java.lang.AbstractMethodError: abstract method "void io.flutter.plugin.platform.PlatformView.onFlutterViewAttached(android.view.View)"` + +This is a bug in Flutter which is being tracked here: https://github.com/flutter/flutter/issues/72185 + +There is a workaround by adding `android.enableDexingArtifactTransform=false` to your `gradle.properties` file. ## Screenshots From b4ee3d78dc4ae43ed051b978f8483e04e6b8600b Mon Sep 17 00:00:00 2001 From: Julian Steenbakker Date: Mon, 21 Dec 2020 22:16:52 +0100 Subject: [PATCH 2/4] 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 3/4] 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 4/4] 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 { } + ```