| @@ -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"; | |||
| @@ -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<QRViewExample> { | |||
| 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<QRViewExample> { | |||
| } | |||
| 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<SizeChangedLayoutNotification>( | |||
| 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<QRViewExample> { | |||
| borderRadius: 10, | |||
| borderLength: 30, | |||
| borderWidth: 10, | |||
| cutOutSize: 300, | |||
| cutOutSize: scanArea, | |||
| ), | |||
| ))); | |||
| } | |||
| @@ -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<String, Double> | |||
| 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) | |||
| } | |||
| } | |||
| @@ -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<QRView> { | |||
| 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<QRView> { | |||
| ); | |||
| } | |||
| Widget _getPlatformQrView() { | |||
| Widget _getPlatformQrView(GlobalKey key) { | |||
| Widget _platformQrView; | |||
| switch (defaultTargetPlatform) { | |||
| case TargetPlatform.android: | |||
| @@ -137,7 +138,7 @@ class _QRViewState extends State<QRView> { | |||
| _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<QRView> { | |||
| 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}); | |||
| } | |||
| } | |||
| } | |||