diff --git a/.gitignore b/.gitignore index 41c1683..79f2d39 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ build/ ios/.generated/ packages pubspec.lock +example/ios/Podfile.lock diff --git a/CHANGELOG.md b/CHANGELOG.md index 3df1299..08c2f16 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,35 +1,62 @@ -## [1.0.0] - 8/30/18 +## v2.0.1 - 2020-02-19 + +Bugfixes: +- Fixed wrong build.gradle + +## v2.0.0 - 2020-02-19 + +Features: +- [Add-to-app support](https://github.com/mintware-de/flutter_barcode_reader/pull/168) - @santiihoyos +- Changed overlay to full screen in iOS 13 + +Bugfixes: +- [Fixed rotation on iOS](https://github.com/mintware-de/flutter_barcode_reader/pull/167) - @mintware-de + - [#61 Rotating orientation on iPhones only shows half the screen](https://github.com/mintware-de/flutter_barcode_reader/issues/61) + +Changes: +- [Fix compile warning](https://github.com/mintware-de/flutter_barcode_reader/pull/127) - @lookfirst +- [Upgrade gradle](https://github.com/mintware-de/flutter_barcode_reader/pull/142) - @SuuSoJeat + - `com.android.tools.build:gradle`: 3.3.1 -> 3.5.0 + - `org.jetbrains.kotlin:kotlin-gradle-plugin`: 1.3.20 -> 1.3.50 + - `compileSdkVersion`: 28 -> 29 + - `targetSdkVersion`: 28 -> 29 + - `gradle`: 4.10.2 -> 5.4.1 +- [Package description updated](https://github.com/mintware-de/flutter_barcode_reader/pull/180) - @connectety +- README.md and LICENSE.md updated +- Since the project owner has been changed, the package names are different. Checkout the [UPGRADE.md](./UPGRADE.md) for details. + +## v1.0.0 - 2018-08-30 Breaking Change: Adds support for AndroidX -## [0.0.8] - 8/30/18 +## v0.0.8 - 2018-08-30 -* Fixes [iOS: pressing cancel doesn't stop scanning](https://github.com/apptreesoftware/flutter_barcode_reader/issues/60) thanks to @tgezginis. +* Fixes [iOS: pressing cancel doesn't stop scanning](https://github.com/mintware-de/flutter_barcode_reader/issues/60) thanks to @tgezginis. -## [0.0.7] - 8/30/18 +## v0.0.7 - 2018-08-30 * Fix iOS barcodes not scanning -## [0.0.6] - 8/29/18 +## v0.0.6 - 2018-08-29 * Fix android dependencies * iOS scanner now looks like Android thanks to @dustin-graham -## [0.0.4] - 2/8/18 +## v0.0.4 - 2018-02-8 -* Fix missing gradle dependency (thanks to [toteto](https://github.com/apptreesoftware/flutter_barcode_reader/pull/15)) +* Fix missing gradle dependency (thanks to [toteto](https://github.com/mintware-de/flutter_barcode_reader/pull/15)) * Update gradle dependencies -## [0.0.3] - 2/8/17 +## v0.0.3 - 2017-02-8 * Improved permission handling (thanks to [BenSower](https://github.com/BenSower)) * Added MIT license -## [0.0.2] - 11/7/17 +## v0.0.2 - 2017-11-7 * Rewrite iOS scanner in Objective-C to avoid Swift use_frameworks! conflicts with other plugins (see https://github.com/flutter/flutter/issues/10968) -## [0.0.1] - 10/29/17 +## v0.0.1 - 2017-10-29 * Supports 2D & QR Codes * Control flash while scanning diff --git a/LICENSE b/LICENSE index 736d914..0ba4dc4 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,7 @@ The MIT License -Copyright (c) 2018 AppTree Software http://www.apptreesoftware.com +Copyright (c) 2020 Julian Finkler https://www.mintware.de +Copyright (c) 2018-2019 AppTree Software http://www.apptreesoftware.com Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index a35c5a7..b43730f 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,8 @@ +[![GitHub license](https://img.shields.io/github/license/mintware-de/flutter_barcode_reader.svg)](https://github.com/mintware-de/flutter_barcode_reader/blob/master/LICENSE) +[![GitHub stars](https://img.shields.io/github/stars/mintware-de/flutter_barcode_reader)](https://github.com/mintware-de/flutter_barcode_reader/stargazers) +[![Pub](https://img.shields.io/pub/v/barcode_scan.svg)](https://pub.dartlang.org/packages/barcode_scan) +[![GitHub forks](https://img.shields.io/github/forks/mintware-de/flutter_barcode_reader)](https://github.com/mintware-de/flutter_barcode_reader/network) + # Barcode Scanner A flutter plugin for scanning 2D barcodes and QR codes. @@ -13,7 +18,6 @@ Android: https://github.com/dm77/barcodescanner - [x] Scan QR codes - [x] Control the flash while scanning - [x] Permission handling -- [ ] Support multiple barcode libraries ## Getting Started @@ -24,44 +28,55 @@ For Android, you must do the following before you can use the plugin: `` -* Add the BarcodeScanner activity to your AndroidManifest.xml. Do NOT modify the name. - - `` - - * This plugin is written in Kotlin. Therefore, you need to add Kotlin support to your project. See [installing the Kotlin plugin](https://kotlinlang.org/docs/tutorials/kotlin-android.html#installing-the-kotlin-plugin). Edit your project-level build.gradle file to look like this: - - buildscript { - ext.kotlin_version = '1.3.21' - ... - dependencies { - ... - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - } - } - ... +```groovy +buildscript { + ext.kotlin_version = '1.3.61' + // ... + dependencies { + // ... + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + } +} +// ... +``` Edit your app-level build.gradle file to look like this: - apply plugin: 'kotlin-android' - ... - dependencies { - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" - ... - } +```groovy +apply plugin: 'kotlin-android' +// ... +dependencies { + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + // ... +} +``` Now you can depend on the barcode_scan plugin in your pubspec.yaml file: - dependencies: - ... - barcode_scan: any - +```yaml +dependencies: + # ... + barcode_scan: any +``` Click "Packages get" in Android Studio or run `flutter packages get` in your project folder. ### iOS To use on iOS, you must add the the camera usage description to your Info.plist +```xml + + NSCameraUsageDescription Camera permission is required for barcode scanning. + + +``` + + +## Common problems +### Android "Could not find org.jetbrains.kotlin:kotlin-stdlib-jre..." +Change `org.jetbrains.kotlin:kotlin-stdlib-jre` to `org.jetbrains.kotlin:kotlin-stdlib-jdk` +([StackOverflow](https://stackoverflow.com/a/53358817)) diff --git a/UPGRADE.md b/UPGRADE.md new file mode 100644 index 0000000..acd1546 --- /dev/null +++ b/UPGRADE.md @@ -0,0 +1,25 @@ +# Upgrade from 1.0.0 to 2.0.0 + +The simples way for upgrading is by replacing: +- `com.apptreesoftware.barcodescan` +- `com.yourcompany.barcodescan` +- `com.apptreesoftware.barcode_scan` + +With: `de.mintware.barcode_scan` + +Detailed changes: +Android: +Kotlin Package: `com.apptreesoftware.barcodescan` -> `de.mintware.barcode_scan` +Manifest-Package: `com.yourcompany.barcodescan` -> `de.mintware.barcodescan` +Activity: `com.apptreesoftware.barcodescan.BarcodeScannerActivity` -> `de.mintware.barcode_scan.BarcodeScannerActivity` + +iOS: +Bundle ID: `com.apptreesoftware.barcode.plugin.example` -> `de.mintware.barcode_scan.plugin.example` + +Flutter: +Method channel: `com.apptreesoftware.barcode_scan` -> `de.mintware.barcode_scan` +pubspec.yaml: + - homepage updated + - deprecated author entry removed + - comments removed + - flutter.plugin.androidPackage: `com.apptreesoftware.barcode_scan` -> `de.mintware.barcode_scan` diff --git a/android/gradle/wrapper/gradle-wrapper.properties b/android/gradle/wrapper/gradle-wrapper.properties index f00068b..7225ec2 100644 --- a/android/gradle/wrapper/gradle-wrapper.properties +++ b/android/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Wed Jan 30 20:42:57 BRST 2019 +#Tue Aug 27 10:46:28 ICT 2019 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip diff --git a/android/src/main/AndroidManifest.xml b/android/src/main/AndroidManifest.xml index ff7847a..f84e395 100644 --- a/android/src/main/AndroidManifest.xml +++ b/android/src/main/AndroidManifest.xml @@ -1,9 +1,9 @@ + package="de.mintware.barcodescan"> - + diff --git a/android/src/main/kotlin/de/mintware/barcode_scan/BarcodeScanPlugin.kt b/android/src/main/kotlin/de/mintware/barcode_scan/BarcodeScanPlugin.kt new file mode 100644 index 0000000..59539da --- /dev/null +++ b/android/src/main/kotlin/de/mintware/barcode_scan/BarcodeScanPlugin.kt @@ -0,0 +1,57 @@ +package de.mintware.barcode_scan + +import android.app.Activity +import android.content.Intent +import android.util.Log +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 +import io.flutter.plugin.common.PluginRegistry.Registrar + +class BarcodeScanPlugin(private val registrar: Registrar) : MethodCallHandler, PluginRegistry.ActivityResultListener { + var result: Result? = null + + companion object { + @JvmStatic + fun registerWith(registrar: Registrar) { + val channel = MethodChannel(registrar.messenger(), "de.mintware.barcode_scan") + val plugin = BarcodeScanPlugin(registrar) + channel.setMethodCallHandler(plugin) + registrar.addActivityResultListener(plugin) + } + } + + override fun onMethodCall(call: MethodCall, result: Result) { + if (call.method == "scan") { + this.result = result + showBarcodeView() + } else { + result.notImplemented() + } + } + + private fun showBarcodeView() { + if (registrar.activity() == null) { + Log.e("BarcodeScanPlugin", "plugin can't launch scan activity, because plugin is not attached to any activity.") + return + } + val intent = Intent(registrar.activity(), BarcodeScannerActivity::class.java) + registrar.activity().startActivityForResult(intent, 100) + } + + override fun onActivityResult(code: Int, resultCode: Int, data: Intent?): Boolean { + if (code == 100) { + if (resultCode == Activity.RESULT_OK) { + val barcode = data?.getStringExtra("SCAN_RESULT") + barcode?.let { this.result?.success(barcode) } + } else { + val errorCode = data?.getStringExtra("ERROR_CODE") + this.result?.error(errorCode, null, null) + } + return true + } + return false + } +} diff --git a/android/src/main/kotlin/com/apptreesoftware/barcodescan/BarcodeScannerActivity.kt b/android/src/main/kotlin/de/mintware/barcode_scan/BarcodeScannerActivity.kt similarity index 99% rename from android/src/main/kotlin/com/apptreesoftware/barcodescan/BarcodeScannerActivity.kt rename to android/src/main/kotlin/de/mintware/barcode_scan/BarcodeScannerActivity.kt index e33255a..a0cab80 100644 --- a/android/src/main/kotlin/com/apptreesoftware/barcodescan/BarcodeScannerActivity.kt +++ b/android/src/main/kotlin/de/mintware/barcode_scan/BarcodeScannerActivity.kt @@ -1,4 +1,4 @@ -package com.apptreesoftware.barcodescan +package de.mintware.barcode_scan import android.Manifest import android.app.Activity diff --git a/example/.gitignore b/example/.gitignore index 1624781..83b685b 100644 --- a/example/.gitignore +++ b/example/.gitignore @@ -9,3 +9,7 @@ packages pubspec.lock .flutter-plugins .flutter-plugins-dependencies +ios/Flutter.podspec +ios/Flutter/Flutter.podspec +ios/Flutter/flutter_export_environment.sh +ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist \ No newline at end of file diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index 30d4008..5789251 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -29,12 +29,12 @@ android { defaultConfig { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). - applicationId "com.yourcompany.barcodescanexample" + applicationId "de.mintware.barcode_scan_example" minSdkVersion 16 targetSdkVersion 28 versionCode 1 versionName "1.0" - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } buildTypes { diff --git a/example/android/app/src/main/kotlin/com/apptreesoftware/barcodescanexample/MainActivity.kt b/example/android/app/src/main/kotlin/com/apptreesoftware/barcodescanexample/MainActivity.kt index 7d70e96..e90c15b 100644 --- a/example/android/app/src/main/kotlin/com/apptreesoftware/barcodescanexample/MainActivity.kt +++ b/example/android/app/src/main/kotlin/com/apptreesoftware/barcodescanexample/MainActivity.kt @@ -1,4 +1,4 @@ -package com.apptreesoftware.barcodescanexample +package de.mintware.barcode_scan_example import com.apptreesoftware.barcodescan.BarcodeScanPlugin import io.flutter.embedding.android.FlutterActivity diff --git a/example/ios/.gitignore b/example/ios/.gitignore index 38864ee..b60de6f 100644 --- a/example/ios/.gitignore +++ b/example/ios/.gitignore @@ -38,4 +38,4 @@ Icon? /Flutter/Generated.xcconfig /ServiceDefinitions.json -Pods/ +Pods/ \ No newline at end of file diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock deleted file mode 100644 index e1cac8c..0000000 --- a/example/ios/Podfile.lock +++ /dev/null @@ -1,29 +0,0 @@ -PODS: - - barcode_scan (0.0.1): - - Flutter - - MTBBarcodeScanner - - Flutter (1.0.0) - - MTBBarcodeScanner (5.0.11) - -DEPENDENCIES: - - barcode_scan (from `/Users/matthew/AppTree/plugins/barcode_scan/ios`) - - Flutter (from `/Users/matthew/Library/flutter/bin/cache/artifacts/engine/ios`) - -SPEC REPOS: - https://github.com/cocoapods/specs.git: - - MTBBarcodeScanner - -EXTERNAL SOURCES: - barcode_scan: - :path: "/Users/matthew/AppTree/plugins/barcode_scan/ios" - Flutter: - :path: "/Users/matthew/Library/flutter/bin/cache/artifacts/engine/ios" - -SPEC CHECKSUMS: - barcode_scan: 33f586d02270046fc6559135038b34b5754eaa4f - Flutter: 58dd7d1b27887414a370fcccb9e645c08ffd7a6a - MTBBarcodeScanner: f453b33c4b7dfe545d8c6484ed744d55671788cb - -PODFILE CHECKSUM: 407db753d18e8726329521f96a8fa0bebaef3f42 - -COCOAPODS: 1.6.1 diff --git a/example/ios/Runner.xcodeproj/project.pbxproj b/example/ios/Runner.xcodeproj/project.pbxproj index afa1280..617fad5 100644 --- a/example/ios/Runner.xcodeproj/project.pbxproj +++ b/example/ios/Runner.xcodeproj/project.pbxproj @@ -180,7 +180,6 @@ TargetAttributes = { 97C146ED1CF9000F007C117D = { CreatedOnToolsVersion = 7.3.1; - DevelopmentTeam = RTZBJSE8E8; LastSwiftMigration = 0830; }; }; @@ -274,7 +273,7 @@ ); inputPaths = ( "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh", - "${PODS_ROOT}/../../../../../../Library/flutter/bin/cache/artifacts/engine/ios/Flutter.framework", + "${PODS_ROOT}/../../../../../development/flutter/bin/cache/artifacts/engine/ios/Flutter.framework", ); name = "[CP] Embed Pods Frameworks"; outputPaths = ( @@ -416,7 +415,6 @@ ARCHS = arm64; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; - DEVELOPMENT_TEAM = RTZBJSE8E8; ENABLE_BITCODE = NO; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -428,7 +426,7 @@ "$(inherited)", "$(PROJECT_DIR)/Flutter", ); - PRODUCT_BUNDLE_IDENTIFIER = com.apptreesoftware.barcode.plugin.example; + PRODUCT_BUNDLE_IDENTIFIER = de.mintware.barcode_scan.plugin.example; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; @@ -443,7 +441,6 @@ ARCHS = arm64; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; - DEVELOPMENT_TEAM = RTZBJSE8E8; ENABLE_BITCODE = NO; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -455,7 +452,7 @@ "$(inherited)", "$(PROJECT_DIR)/Flutter", ); - PRODUCT_BUNDLE_IDENTIFIER = com.apptreesoftware.barcode.plugin.example; + PRODUCT_BUNDLE_IDENTIFIER = de.mintware.barcode_scan.plugin.example; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; SWIFT_VERSION = 4.0; diff --git a/example/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings b/example/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings new file mode 100644 index 0000000..6b30c74 --- /dev/null +++ b/example/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings @@ -0,0 +1,10 @@ + + + + + BuildSystemType + Original + PreviewsEnabled + + + diff --git a/ios/Classes/BarcodeScanPlugin.m b/ios/Classes/BarcodeScanPlugin.m index 012593c..ae557c4 100644 --- a/ios/Classes/BarcodeScanPlugin.m +++ b/ios/Classes/BarcodeScanPlugin.m @@ -3,7 +3,7 @@ @implementation BarcodeScanPlugin + (void)registerWithRegistrar:(NSObject*)registrar { - FlutterMethodChannel *channel = [FlutterMethodChannel methodChannelWithName:@"com.apptreesoftware.barcode_scan" + FlutterMethodChannel *channel = [FlutterMethodChannel methodChannelWithName:@"de.mintware.barcode_scan" binaryMessenger:registrar.messenger]; BarcodeScanPlugin *instance = [BarcodeScanPlugin new]; instance.hostViewController = [UIApplication sharedApplication].delegate.window.rootViewController; @@ -22,10 +22,12 @@ - (void)showBarcodeView { BarcodeScannerViewController *scannerViewController = [[BarcodeScannerViewController alloc] init]; UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:scannerViewController]; + if (@available(iOS 13.0, *)) { + [navigationController setModalPresentationStyle:UIModalPresentationFullScreen]; + } scannerViewController.delegate = self; [self.hostViewController presentViewController:navigationController animated:NO completion:nil]; } - - (void)barcodeScannerViewController:(BarcodeScannerViewController *)controller didScanBarcodeWithResult:(NSString *)result { if (self.result) { self.result(result); diff --git a/ios/Classes/BarcodeScannerViewController.m b/ios/Classes/BarcodeScannerViewController.m index 4927030..e515749 100644 --- a/ios/Classes/BarcodeScannerViewController.m +++ b/ios/Classes/BarcodeScannerViewController.m @@ -10,6 +10,35 @@ @implementation BarcodeScannerViewController { } +- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id)coordinator +{ + CGRect bounds = [UIScreen mainScreen].bounds; + CGRect reversedBounds = CGRectMake(bounds.origin.x, bounds.origin.y, bounds.size.height, bounds.size.width); + self.previewView.bounds = reversedBounds; + self.previewView.frame = reversedBounds; + [self.scanRect stopAnimating]; + [self.scanRect removeFromSuperview]; + [self setupScanRect:reversedBounds]; + [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator]; +} + +- (void)setupScanRect:(CGRect)bounds { + self.scanRect = [[ScannerOverlay alloc] initWithFrame:bounds]; + self.scanRect.translatesAutoresizingMaskIntoConstraints = NO; + self.scanRect.backgroundColor = UIColor.clearColor; + [self.view addSubview:_scanRect]; + [self.view addConstraints:[NSLayoutConstraint + constraintsWithVisualFormat:@"V:[scanRect]" + options:NSLayoutFormatAlignAllBottom + metrics:nil + views:@{@"scanRect": _scanRect}]]; + [self.view addConstraints:[NSLayoutConstraint + constraintsWithVisualFormat:@"H:[scanRect]" + options:NSLayoutFormatAlignAllBottom + metrics:nil + views:@{@"scanRect": _scanRect}]]; + [_scanRect startAnimating]; +} - (void)viewDidLoad { [super viewDidLoad]; @@ -26,21 +55,7 @@ options:NSLayoutFormatAlignAllBottom metrics:nil views:@{@"previewView": _previewView}]]; - self.scanRect = [[ScannerOverlay alloc] initWithFrame:self.view.bounds]; - self.scanRect.translatesAutoresizingMaskIntoConstraints = NO; - self.scanRect.backgroundColor = UIColor.clearColor; - [self.view addSubview:_scanRect]; - [self.view addConstraints:[NSLayoutConstraint - constraintsWithVisualFormat:@"V:[scanRect]" - options:NSLayoutFormatAlignAllBottom - metrics:nil - views:@{@"scanRect": _scanRect}]]; - [self.view addConstraints:[NSLayoutConstraint - constraintsWithVisualFormat:@"H:[scanRect]" - options:NSLayoutFormatAlignAllBottom - metrics:nil - views:@{@"scanRect": _scanRect}]]; - [_scanRect startAnimating]; + [self setupScanRect:self.view.bounds]; self.scanner = [[MTBBarcodeScanner alloc] initWithPreviewView:_previewView]; self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancel)]; [self updateFlashButton]; diff --git a/ios/Classes/ScannerOverlay.m b/ios/Classes/ScannerOverlay.m index ab4c121..7c415b9 100644 --- a/ios/Classes/ScannerOverlay.m +++ b/ios/Classes/ScannerOverlay.m @@ -83,19 +83,31 @@ } - (CGRect)scanRect { - CGRect rect = self.frame; - CGFloat heightMultiplier = 3.0/4.0; // 4:3 aspect ratio - CGFloat scanRectWidth = rect.size.width * 0.8f; - CGFloat scanRectHeight = scanRectWidth * heightMultiplier; - CGFloat scanRectOriginX = (rect.size.width / 2) - (scanRectWidth / 2); - CGFloat scanRectOriginY = (rect.size.height / 2) - (scanRectHeight / 2); - return CGRectMake(scanRectOriginX, scanRectOriginY, scanRectWidth, scanRectHeight); + CGRect rect = self.frame; + + CGFloat frameWidth = rect.size.width; + CGFloat frameHeight = rect.size.height; + + BOOL isLandscape = frameWidth > frameHeight; + CGFloat widthOnPortrait = isLandscape ? frameHeight : frameWidth; + CGFloat scanRectWidth = widthOnPortrait * 0.8f; + CGFloat aspectRatio = 3.0/4.0; + CGFloat scanRectHeight = scanRectWidth * aspectRatio; + + if(isLandscape) { + CGFloat navbarHeight = 32; + frameHeight += navbarHeight; + } + + CGFloat scanRectOriginX = (frameWidth - scanRectWidth) / 2; + CGFloat scanRectOriginY = (frameHeight - scanRectHeight) / 2; + return CGRectMake(scanRectOriginX, scanRectOriginY, scanRectWidth, scanRectHeight); } - (CGRect)scanLineRect { CGRect scanRect = [self scanRect]; - CGRect rect = self.frame; - return CGRectMake(scanRect.origin.x, rect.size.height / 2, scanRect.size.width, 1); + CGFloat positionY = scanRect.origin.y + (scanRect.size.height / 2); + return CGRectMake(scanRect.origin.x, positionY, scanRect.size.width, 1); } @end diff --git a/lib/barcode_scan.dart b/lib/barcode_scan.dart index 048be77..8000445 100644 --- a/lib/barcode_scan.dart +++ b/lib/barcode_scan.dart @@ -2,10 +2,22 @@ import 'dart:async'; import 'package:flutter/services.dart'; +/// Barcode scanner plugin +/// Simply call `var barcode = await BarcodeScanner.scan()` to scan a barcode class BarcodeScanner { + /// If the user has not granted the access to the camera this code is thrown. static const CameraAccessDenied = 'PERMISSION_NOT_GRANTED'; + + /// If the user cancel the scan an exception with this code is thrown. static const UserCanceled = 'USER_CANCELED'; + + /// The method channel static const MethodChannel _channel = - const MethodChannel('com.apptreesoftware.barcode_scan'); + const MethodChannel('de.mintware.barcode_scan'); + + /// Starts the camera for scanning the barcode, shows a preview window and + /// returns the barcode if one was scanned. + /// Can throw an exception. + /// See also [CameraAccessDenied] and [UserCanceled] static Future scan() async => await _channel.invokeMethod('scan'); }