From 06bb45d4d9758302b7666e59044646ac62bbc15c Mon Sep 17 00:00:00 2001 From: TheJuliuscanute Date: Mon, 17 Jun 2019 18:49:22 +1000 Subject: [PATCH] camera flip addition --- .packages | 8 ++ CHANGELOG.md | 4 + README.md | 1 - .../qr/flutterqr/FlutterQrPlugin.kt | 11 +-- .../net/touchcapture/qr/flutterqr/QRView.kt | 17 ++++ example/README.md | 19 +++- example/ios/Runner.xcodeproj/project.pbxproj | 89 +++++++++---------- .../xcshareddata/xcschemes/Runner.xcscheme | 2 +- example/ios/Runner/Info.plist | 18 ++-- example/lib/main.dart | 19 +++- ios/Classes/QRView.swift | 18 ++-- ios/Classes/SwiftFlutterQrPlugin.swift | 4 +- lib/qr_code_scanner.dart | 4 + pubspec.yaml | 2 +- 14 files changed, 139 insertions(+), 77 deletions(-) create mode 100644 .packages diff --git a/.packages b/.packages new file mode 100644 index 0000000..726dd07 --- /dev/null +++ b/.packages @@ -0,0 +1,8 @@ +# Generated by pub on 2019-06-17 18:43:06.495486. +collection:file:///Users/juliuscanute/Library/CrossPlatform/flutter/.pub-cache/hosted/pub.dartlang.org/collection-1.14.11/lib/ +flutter:file:///Users/juliuscanute/Library/CrossPlatform/flutter/packages/flutter/lib/ +meta:file:///Users/juliuscanute/Library/CrossPlatform/flutter/.pub-cache/hosted/pub.dartlang.org/meta-1.1.6/lib/ +sky_engine:file:///Users/juliuscanute/Library/CrossPlatform/flutter/bin/cache/pkg/sky_engine/lib/ +typed_data:file:///Users/juliuscanute/Library/CrossPlatform/flutter/.pub-cache/hosted/pub.dartlang.org/typed_data-1.1.6/lib/ +vector_math:file:///Users/juliuscanute/Library/CrossPlatform/flutter/.pub-cache/hosted/pub.dartlang.org/vector_math-2.0.8/lib/ +qr_code_scanner:lib/ diff --git a/CHANGELOG.md b/CHANGELOG.md index 15ea243..51b2b71 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.0.6 + +* camera flip added + ## 0.0.5 * preview stretching after change screen orientation fix diff --git a/README.md b/README.md index b57da07..6fa20e0 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,5 @@ This package wires the PlatformView corresponding to iOS and Android inside flut * Special Thanks To: LeonDevLifeLog for his contributions towards improving this package. #TODO'S: -* Add support to flip camera view. * iOS Native embedding is written to match what is supported in the framework as of the date of publication of this package. It needs to be improved as the framework support improves. * Finally, I welcome PR's to make it better :), thanks \ No newline at end of file diff --git a/android/src/main/kotlin/net/touchcapture/qr/flutterqr/FlutterQrPlugin.kt b/android/src/main/kotlin/net/touchcapture/qr/flutterqr/FlutterQrPlugin.kt index b3ca4ad..9336335 100644 --- a/android/src/main/kotlin/net/touchcapture/qr/flutterqr/FlutterQrPlugin.kt +++ b/android/src/main/kotlin/net/touchcapture/qr/flutterqr/FlutterQrPlugin.kt @@ -1,10 +1,6 @@ package net.touchcapture.qr.flutterqr -import android.app.Activity -import android.app.Application -import android.os.Bundle import io.flutter.plugin.common.MethodCall -import io.flutter.plugin.common.MethodChannel import io.flutter.plugin.common.MethodChannel.MethodCallHandler import io.flutter.plugin.common.MethodChannel.Result import io.flutter.plugin.common.PluginRegistry.Registrar @@ -21,10 +17,9 @@ class FlutterQrPlugin : MethodCallHandler { } override fun onMethodCall(call: MethodCall, result: Result) { - if (call.method == "getPlatformVersion") { - result.success("Android ${android.os.Build.VERSION.RELEASE}") - } else { - result.notImplemented() + when { + call.method == "getPlatformVersion" -> result.success("Android ${android.os.Build.VERSION.RELEASE}") + else -> result.notImplemented() } } } 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 a783084..ea54793 100644 --- a/android/src/main/kotlin/net/touchcapture/qr/flutterqr/QRView.kt +++ b/android/src/main/kotlin/net/touchcapture/qr/flutterqr/QRView.kt @@ -10,6 +10,7 @@ import android.os.Build import android.os.Bundle import android.view.View import com.google.zxing.ResultPoint +import android.hardware.Camera.CameraInfo import com.journeyapps.barcodescanner.BarcodeCallback import com.journeyapps.barcodescanner.BarcodeResult import com.journeyapps.barcodescanner.BarcodeView @@ -66,6 +67,19 @@ class QRView(context: Context, private val registrar: PluginRegistry.Registrar, }) } + fun flipCamera() { + barcodeView?.pause() + var settings = barcodeView?.cameraSettings + + if(settings?.requestedCameraId == CameraInfo.CAMERA_FACING_FRONT) + settings?.requestedCameraId = CameraInfo.CAMERA_FACING_BACK + else + settings?.requestedCameraId = CameraInfo.CAMERA_FACING_FRONT + + barcodeView?.cameraSettings = settings + barcodeView?.resume() + } + override fun getView(): View { return initBarCodeView()?.apply { @@ -120,6 +134,9 @@ class QRView(context: Context, private val registrar: PluginRegistry.Registrar, "checkAndRequestPermission" -> { checkAndRequestPermission(result) } + "flipCamera" -> { + flipCamera() + } } } diff --git a/example/README.md b/example/README.md index e7f3350..7eb0a06 100644 --- a/example/README.md +++ b/example/README.md @@ -39,6 +39,7 @@ class QRViewExample extends StatefulWidget { class _QRViewExampleState extends State { final GlobalKey qrKey = GlobalKey(debugLabel: 'QR'); var qrText = ""; + QRViewController controller; @override Widget build(BuildContext context) { return Scaffold( @@ -52,7 +53,22 @@ class _QRViewExampleState extends State { flex: 4, ), Expanded( - child: Text("This is the result of scan: $qrText"), + child: Column(children: + [ + Text("This is the result of scan: $qrText"), + RaisedButton( + onPressed: (){ + if(controller != null){ + controller.flipCamera(); + } + }, + child: Text( + 'Flip', + style: TextStyle(fontSize: 20) + ), + ) + ], + ), flex: 1, ) ], @@ -63,6 +79,7 @@ class _QRViewExampleState extends State { void _onQRViewCreated(QRViewController controller) { final channel = controller.channel; controller.init(qrKey); + this.controller = controller; channel.setMethodCallHandler((MethodCall call) async { switch (call.method) { case "onRecognizeQR": diff --git a/example/ios/Runner.xcodeproj/project.pbxproj b/example/ios/Runner.xcodeproj/project.pbxproj index ea9bd4c..7e82a4c 100644 --- a/example/ios/Runner.xcodeproj/project.pbxproj +++ b/example/ios/Runner.xcodeproj/project.pbxproj @@ -8,13 +8,11 @@ /* Begin PBXBuildFile section */ 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; }; - 2D5378261FAA1A9400D5DBA9 /* flutter_assets in Resources */ = {isa = PBXBuildFile; fileRef = 2D5378251FAA1A9400D5DBA9 /* flutter_assets */; }; 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; }; 3B80C3941E831B6300D905FE /* App.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; }; 3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + 72CA4F8FC83C02C1B0C5292A /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D115C5DD3945F9758AB33CE2 /* Pods_Runner.framework */; }; 74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74858FAE1ED2DC5600515810 /* AppDelegate.swift */; }; - 875CEA4621CCA9620072C5B9 /* MTBBarcodeScanner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 875CEA4521CCA9620072C5B9 /* MTBBarcodeScanner.framework */; }; - 90416EE8981E3A39D474076A /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 18FDEF8746A8853DC11EEA49 /* Pods_Runner.framework */; }; 9705A1C61CF904A100538489 /* Flutter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9740EEBA1CF902C7004384FC /* Flutter.framework */; }; 9705A1C71CF904A300538489 /* Flutter.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 9740EEBA1CF902C7004384FC /* Flutter.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; }; @@ -40,15 +38,11 @@ /* Begin PBXFileReference section */ 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = ""; }; 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = ""; }; - 18FDEF8746A8853DC11EEA49 /* Pods_Runner.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Runner.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - 2D5378251FAA1A9400D5DBA9 /* flutter_assets */ = {isa = PBXFileReference; lastKnownFileType = folder; name = flutter_assets; path = Flutter/flutter_assets; sourceTree = SOURCE_ROOT; }; 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = ""; }; 3B80C3931E831B6300D905FE /* App.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = App.framework; path = Flutter/App.framework; sourceTree = ""; }; 74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Runner-Bridging-Header.h"; sourceTree = ""; }; 74858FAE1ED2DC5600515810 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = ""; }; - 875CEA4221CCA33A0072C5B9 /* MTBBarcodeScanner.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = MTBBarcodeScanner.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - 875CEA4521CCA9620072C5B9 /* MTBBarcodeScanner.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = MTBBarcodeScanner.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = ""; }; 9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = ""; }; 9740EEBA1CF902C7004384FC /* Flutter.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Flutter.framework; path = Flutter/Flutter.framework; sourceTree = ""; }; @@ -57,6 +51,7 @@ 97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 97C147001CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + D115C5DD3945F9758AB33CE2 /* Pods_Runner.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Runner.framework; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -64,29 +59,25 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 875CEA4621CCA9620072C5B9 /* MTBBarcodeScanner.framework in Frameworks */, 9705A1C61CF904A100538489 /* Flutter.framework in Frameworks */, 3B80C3941E831B6300D905FE /* App.framework in Frameworks */, - 90416EE8981E3A39D474076A /* Pods_Runner.framework in Frameworks */, + 72CA4F8FC83C02C1B0C5292A /* Pods_Runner.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ - 59377A0B384FA8EFF7C11C6F /* Frameworks */ = { + 0972BCF1757D16A75C3EC240 /* Pods */ = { isa = PBXGroup; children = ( - 875CEA4521CCA9620072C5B9 /* MTBBarcodeScanner.framework */, - 18FDEF8746A8853DC11EEA49 /* Pods_Runner.framework */, ); - name = Frameworks; + name = Pods; sourceTree = ""; }; 9740EEB11CF90186004384FC /* Flutter */ = { isa = PBXGroup; children = ( - 2D5378251FAA1A9400D5DBA9 /* flutter_assets */, 3B80C3931E831B6300D905FE /* App.framework */, 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */, 9740EEBA1CF902C7004384FC /* Flutter.framework */, @@ -100,12 +91,11 @@ 97C146E51CF9000F007C117D = { isa = PBXGroup; children = ( - 875CEA4221CCA33A0072C5B9 /* MTBBarcodeScanner.framework */, 9740EEB11CF90186004384FC /* Flutter */, 97C146F01CF9000F007C117D /* Runner */, 97C146EF1CF9000F007C117D /* Products */, - E0C0CF8E7F3368743823A4D6 /* Pods */, - 59377A0B384FA8EFF7C11C6F /* Frameworks */, + 0972BCF1757D16A75C3EC240 /* Pods */, + EA94796F93C587B741C39DDE /* Frameworks */, ); sourceTree = ""; }; @@ -140,11 +130,12 @@ name = "Supporting Files"; sourceTree = ""; }; - E0C0CF8E7F3368743823A4D6 /* Pods */ = { + EA94796F93C587B741C39DDE /* Frameworks */ = { isa = PBXGroup; children = ( + D115C5DD3945F9758AB33CE2 /* Pods_Runner.framework */, ); - name = Pods; + name = Frameworks; sourceTree = ""; }; /* End PBXGroup section */ @@ -154,14 +145,14 @@ isa = PBXNativeTarget; buildConfigurationList = 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */; buildPhases = ( - 0F3EF80A2505CFA7161E4046 /* [CP] Check Pods Manifest.lock */, + 3C208BB7148E708611B40C3B /* [CP] Check Pods Manifest.lock */, 9740EEB61CF901F6004384FC /* Run Script */, 97C146EA1CF9000F007C117D /* Sources */, 97C146EB1CF9000F007C117D /* Frameworks */, 97C146EC1CF9000F007C117D /* Resources */, 9705A1C41CF9048500538489 /* Embed Frameworks */, 3B06AD1E1E4923F5004D2608 /* Thin Binary */, - 5694CD6E1A5E2C175A82230C /* [CP] Embed Pods Frameworks */, + 826384570F6676587F6C98F0 /* [CP] Embed Pods Frameworks */, ); buildRules = ( ); @@ -178,19 +169,19 @@ 97C146E61CF9000F007C117D /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 1010; + LastUpgradeCheck = 1020; ORGANIZATIONNAME = "The Chromium Authors"; TargetAttributes = { 97C146ED1CF9000F007C117D = { CreatedOnToolsVersion = 7.3.1; DevelopmentTeam = W5L5PDU89L; - LastSwiftMigration = 1010; + LastSwiftMigration = 1020; }; }; }; buildConfigurationList = 97C146E91CF9000F007C117D /* Build configuration list for PBXProject "Runner" */; compatibilityVersion = "Xcode 3.2"; - developmentRegion = English; + developmentRegion = en; hasScannedForEncodings = 0; knownRegions = ( en, @@ -214,7 +205,6 @@ 97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */, 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */, 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */, - 2D5378261FAA1A9400D5DBA9 /* flutter_assets in Resources */, 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -222,43 +212,43 @@ /* End PBXResourcesBuildPhase section */ /* Begin PBXShellScriptBuildPhase section */ - 0F3EF80A2505CFA7161E4046 /* [CP] Check Pods Manifest.lock */ = { + 3B06AD1E1E4923F5004D2608 /* Thin Binary */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( ); - inputFileListPaths = ( - ); inputPaths = ( - "${PODS_PODFILE_DIR_PATH}/Podfile.lock", - "${PODS_ROOT}/Manifest.lock", - ); - name = "[CP] Check Pods Manifest.lock"; - outputFileListPaths = ( ); + name = "Thin Binary"; outputPaths = ( - "$(DERIVED_FILE_DIR)/Pods-Runner-checkManifestLockResult.txt", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; - showEnvVarsInLog = 0; + shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" thin"; }; - 3B06AD1E1E4923F5004D2608 /* Thin Binary */ = { + 3C208BB7148E708611B40C3B /* [CP] Check Pods Manifest.lock */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( ); + inputFileListPaths = ( + ); inputPaths = ( + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", + ); + name = "[CP] Check Pods Manifest.lock"; + outputFileListPaths = ( ); - name = "Thin Binary"; outputPaths = ( + "$(DERIVED_FILE_DIR)/Pods-Runner-checkManifestLockResult.txt", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" thin"; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; + showEnvVarsInLog = 0; }; - 5694CD6E1A5E2C175A82230C /* [CP] Embed Pods Frameworks */ = { + 826384570F6676587F6C98F0 /* [CP] Embed Pods Frameworks */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( @@ -269,7 +259,7 @@ "${SRCROOT}/Pods/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh", "${PODS_ROOT}/../.symlinks/flutter/ios/Flutter.framework", "${BUILT_PRODUCTS_DIR}/MTBBarcodeScanner/MTBBarcodeScanner.framework", - "${BUILT_PRODUCTS_DIR}/flutter_qr/flutter_qr.framework", + "${BUILT_PRODUCTS_DIR}/qr_code_scanner/qr_code_scanner.framework", ); name = "[CP] Embed Pods Frameworks"; outputFileListPaths = ( @@ -277,7 +267,7 @@ outputPaths = ( "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Flutter.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/MTBBarcodeScanner.framework", - "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/flutter_qr.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/qr_code_scanner.framework", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; @@ -337,6 +327,7 @@ baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; CLANG_ANALYZER_NONNULL = YES; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; @@ -400,9 +391,9 @@ "$(inherited)", "$(PROJECT_DIR)/Flutter", ); - PRODUCT_BUNDLE_IDENTIFIER = net.touchcapture; + PRODUCT_BUNDLE_IDENTIFIER = net.touch.capture; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; VERSIONING_SYSTEM = "apple-generic"; }; name = Profile; @@ -412,6 +403,7 @@ baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; CLANG_ANALYZER_NONNULL = YES; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; @@ -468,6 +460,7 @@ baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; CLANG_ANALYZER_NONNULL = YES; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; @@ -533,11 +526,11 @@ "$(inherited)", "$(PROJECT_DIR)/Flutter", ); - PRODUCT_BUNDLE_IDENTIFIER = net.touchcapture; + PRODUCT_BUNDLE_IDENTIFIER = net.touch.capture; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; VERSIONING_SYSTEM = "apple-generic"; }; name = Debug; @@ -561,10 +554,10 @@ "$(inherited)", "$(PROJECT_DIR)/Flutter", ); - PRODUCT_BUNDLE_IDENTIFIER = net.touchcapture; + PRODUCT_BUNDLE_IDENTIFIER = net.touch.capture; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; VERSIONING_SYSTEM = "apple-generic"; }; name = Release; diff --git a/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme index 3eaa63c..a28140c 100644 --- a/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme +++ b/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -1,6 +1,6 @@ - NSCameraUsageDescription - Can we access your camera in order to scan barcodes? - UIBackgroundModes - - fetch - remote-notification - - io.flutter.embedded_views_preview - CFBundleDevelopmentRegion en CFBundleExecutable @@ -31,6 +22,13 @@ $(FLUTTER_BUILD_NUMBER) LSRequiresIPhoneOS + NSCameraUsageDescription + Can we access your camera in order to scan barcodes? + UIBackgroundModes + + fetch + remote-notification + UILaunchStoryboardName LaunchScreen UIMainStoryboardFile @@ -50,5 +48,7 @@ UIViewControllerBasedStatusBarAppearance + io.flutter.embedded_views_preview + diff --git a/example/lib/main.dart b/example/lib/main.dart index 89d3154..b4fde6a 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -16,6 +16,7 @@ class QRViewExample extends StatefulWidget { class _QRViewExampleState extends State { final GlobalKey qrKey = GlobalKey(debugLabel: 'QR'); var qrText = ""; + QRViewController controller; @override Widget build(BuildContext context) { return Scaffold( @@ -29,7 +30,22 @@ class _QRViewExampleState extends State { flex: 4, ), Expanded( - child: Text("This is the result of scan: $qrText"), + child: Column(children: + [ + Text("This is the result of scan: $qrText"), + RaisedButton( + onPressed: (){ + if(controller != null){ + controller.flipCamera(); + } + }, + child: Text( + 'Flip', + style: TextStyle(fontSize: 20) + ), + ) + ], + ), flex: 1, ) ], @@ -40,6 +56,7 @@ class _QRViewExampleState extends State { void _onQRViewCreated(QRViewController controller) { final channel = controller.channel; controller.init(qrKey); + this.controller = controller; channel.setMethodCallHandler((MethodCall call) async { switch (call.method) { case "onRecognizeQR": diff --git a/ios/Classes/QRView.swift b/ios/Classes/QRView.swift index a99eb3c..121818a 100644 --- a/ios/Classes/QRView.swift +++ b/ios/Classes/QRView.swift @@ -42,12 +42,16 @@ public class QRView:NSObject,FlutterPlatformView { public func view() -> UIView { channel.setMethodCallHandler({ [weak self] (call: FlutterMethodCall, result: FlutterResult) -> Void in - guard call.method == "setDimensions" else { - result(FlutterMethodNotImplemented) - return + switch(call.method){ + case "setDimensions": + var arguments = call.arguments as! Dictionary + self?.setDimensions(width: arguments["width"] ?? 0,height: arguments["height"] ?? 0) + case "flipCamera": + self?.flipCamera() + default: + result(FlutterMethodNotImplemented) + return } - var arguments = call.arguments as! Dictionary - self?.setDimensions(width: arguments["width"] ?? 0,height: arguments["height"] ?? 0) }) return previewView } @@ -57,4 +61,8 @@ public class QRView:NSObject,FlutterPlatformView { scanner = MTBBarcodeScanner(previewView: previewView) MTBBarcodeScanner.requestCameraPermission(success: isCameraAvailable) } + + func flipCamera(){ + scanner?.flipCamera() + } } diff --git a/ios/Classes/SwiftFlutterQrPlugin.swift b/ios/Classes/SwiftFlutterQrPlugin.swift index c132b32..f26aff6 100644 --- a/ios/Classes/SwiftFlutterQrPlugin.swift +++ b/ios/Classes/SwiftFlutterQrPlugin.swift @@ -2,6 +2,7 @@ import Flutter import UIKit public class SwiftFlutterQrPlugin: NSObject, FlutterPlugin { + var factory: QRViewFactory public init(with registrar: FlutterPluginRegistrar) { self.factory = QRViewFactory(withRegistrar: registrar) @@ -13,10 +14,9 @@ public class SwiftFlutterQrPlugin: NSObject, FlutterPlugin { } public func applicationDidEnterBackground(_ application: UIApplication) { - } public func applicationWillTerminate(_ application: UIApplication) { - } + } diff --git a/lib/qr_code_scanner.dart b/lib/qr_code_scanner.dart index 73c1550..48ebbac 100644 --- a/lib/qr_code_scanner.dart +++ b/lib/qr_code_scanner.dart @@ -82,4 +82,8 @@ class QRViewController { {"width": renderBox.size.width, "height": renderBox.size.height}); } } + + void flipCamera(){ + channel.invokeMethod("flipCamera"); + } } diff --git a/pubspec.yaml b/pubspec.yaml index 90a7347..6e7b112 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: qr_code_scanner description: QR code scanner that can be embedded inside flutter. It uses zxing in Android and MTBBarcode scanner in iOS. -version: 0.0.5 +version: 0.0.6 author: Julius Canute homepage: https://github.com/juliuscanute/qr_code_scanner