mirror of
https://github.com/simplezhli/flutter_barcode_reader.git
synced 2025-01-03 16:05:30 +08:00
Merge remote-tracking branch 'upstream/master' into dev
# Conflicts: # android/build.gradle # android/src/main/kotlin/com/apptreesoftware/barcodescan/BarcodeScanPlugin.kt # example/.gitignore # example/android/app/src/main/AndroidManifest.xml # example/android/gradle.properties # pubspec.yaml
This commit is contained in:
commit
d36a12a9c6
1
.gitignore
vendored
1
.gitignore
vendored
@ -8,3 +8,4 @@ build/
|
||||
ios/.generated/
|
||||
packages
|
||||
pubspec.lock
|
||||
example/ios/Podfile.lock
|
||||
|
47
CHANGELOG.md
47
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
|
||||
|
3
LICENSE
3
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
|
||||
|
67
README.md
67
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:
|
||||
|
||||
`<uses-permission android:name="android.permission.CAMERA" />`
|
||||
|
||||
* Add the BarcodeScanner activity to your AndroidManifest.xml. Do NOT modify the name.
|
||||
|
||||
`<activity android:name="com.apptreesoftware.barcodescan.BarcodeScannerActivity"/>`
|
||||
|
||||
|
||||
* 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
|
||||
<dict>
|
||||
<!-- ... -->
|
||||
<key>NSCameraUsageDescription</key>
|
||||
<string>Camera permission is required for barcode scanning.</string>
|
||||
<!-- ... -->
|
||||
</dict>
|
||||
```
|
||||
|
||||
|
||||
## 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))
|
||||
|
25
UPGRADE.md
Normal file
25
UPGRADE.md
Normal file
@ -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`
|
@ -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
|
||||
|
@ -1,9 +1,9 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.yourcompany.barcodescan">
|
||||
package="de.mintware.barcodescan">
|
||||
|
||||
<uses-permission android:name="android.permission.CAMERA" />
|
||||
|
||||
<application>
|
||||
<activity android:name="com.apptreesoftware.barcodescan.BarcodeScannerActivity" />
|
||||
<activity android:name="de.mintware.barcode_scan.BarcodeScannerActivity" />
|
||||
</application>
|
||||
</manifest>
|
||||
|
@ -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
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package com.apptreesoftware.barcodescan
|
||||
package de.mintware.barcode_scan
|
||||
|
||||
import android.Manifest
|
||||
import android.app.Activity
|
4
example/.gitignore
vendored
4
example/.gitignore
vendored
@ -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
|
@ -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 {
|
||||
|
@ -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
|
||||
|
@ -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
|
@ -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;
|
||||
|
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>BuildSystemType</key>
|
||||
<string>Original</string>
|
||||
<key>PreviewsEnabled</key>
|
||||
<false/>
|
||||
</dict>
|
||||
</plist>
|
@ -3,7 +3,7 @@
|
||||
|
||||
@implementation BarcodeScanPlugin
|
||||
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)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);
|
||||
|
@ -10,6 +10,35 @@
|
||||
@implementation BarcodeScannerViewController {
|
||||
}
|
||||
|
||||
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)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];
|
||||
|
@ -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
|
||||
|
@ -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<String> scan() async => await _channel.invokeMethod('scan');
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user