Skip to content
This repository has been archived by the owner on Oct 10, 2020. It is now read-only.

Rewrite platform communication #185

Merged
merged 11 commits into from
Apr 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.

version:
revision: 27321ebbad34b0a3fafe99fac037102196d655ff
channel: stable

project_type: plugin
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
## Next release

- iOS code migrated to Swift
- Android code migrated to FlutterPlugin
- Platform communication with protobuf
- Retrieve the number of available cameras with `BarcodeScanner.numberOfCameras`

Flexible configuration:
- Set the strings for the flash on/off and the cancel button
- Restrict the detected barcode formats
- Set which camera is used for scanning barcodes

**BREAKING CHANGES**:
- minSdk version on Android is now 18
- `BarcodeScanner.scan()` returns a `ScanResult` object. Check [UPGRADE.md](./UPGRADE.md) for migration details.

## v2.0.1 - 2020-02-19

Bugfixes:
Expand Down
74 changes: 73 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,79 @@ To use on iOS, you must add the the camera usage description to your Info.plist
```


## Usage

```dart

import 'package:barcode_scan/barcode_scan.dart';

void main() async {
var result = await BarcodeScanner.scan();

print(result.type); // The result type (barcode, cancelled, failed)
print(result.rawContent); // The barcode content
print(result.format); // The barcode format (as enum)
print(result.formatNote); // If a unknown format was scanned this field contains a note
}
```


## Advanced usage
You can pass options to the scan method:

```dart

import 'package:barcode_scan/barcode_scan.dart';

void main() async {

var options = ScanOptions(
// set the options
);

var result = await BarcodeScanner.scan(options: options);

// ...
}
```

### Supported options
| Option | Type | Description | Supported by |
|----------------------------|-------------------|-------------------------------------------------------------------------------------------|---------------|
| `strings.cancel` | `String` | The cancel button text on iOS | iOS only |
| `strings.flash_on` | `String` | The flash on button text | iOS + Android |
| `strings.flash_off` | `String` | The flash off button text | iOS + Android |
| `restrictFormat` | `BarcodeFormat[]` | Restrict the formats which are recognized | iOS + Android |
| `useCamera` | `int` | The index of the camera which is used for scanning (See `BarcodeScanner.numberOfCameras`) | iOS + Android |
| `autoEnableFlash` | `bool` | Enable the flash when start scanning | iOS + Android |
| `android.aspectTolerance` | `double` | Enable the flash when start scanning | Android only |
| `android.useAutoFocus` | `bool` | Enable the flash when start scanning | Android only |

## Development setup

### Setup protobuf

Mac:
```bash
$ brew install protobuf
$ brew install swift-protobuf
```
Windows / Linux: https://github.com/protocolbuffers/protobuf#protocol-compiler-installation


Activate the protobuf dart plugin:
`$ pub global activate protoc_plugin`

Install the`Protobuf Support` plugin for IDEA / Android Studio or `vscode-proto3` for VS Code

If you changed the protos.proto you've to execute the ./generate_proto.sh to update the dart / swift sources






## 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))
([StackOverflow](https://stackoverflow.com/a/53358817))
7 changes: 7 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# Upgrade from 2.x to 3.0.0

The `BarcodeScan.scan()` method returns a [`ScanResult`](./lib/model/scan_result.dart).
The barcode is stored in `ScanResult.rawContent`
Check your calls to this method and read the barcode from the `rawContent` property.


# Upgrade from 1.0.0 to 2.0.0

The simples way for upgrading is by replacing:
Expand Down
11 changes: 11 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
include: package:effective_dart/analysis_options.yaml

# For lint rules and documentation, see http://dart-lang.github.io/linter/lints.
# Uncomment to specify additional rules.
# linter:
# rules:
# - camel_case_types

analyzer:
exclude:
- lib/gen/**
45 changes: 35 additions & 10 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,73 @@ group 'de.mintware.barcode_scan'
version '1.0-SNAPSHOT'

buildscript {
ext.kotlin_version = '1.3.61'
ext.protobuf_version = '0.8.8'
repositories {
google()
jcenter()
}

dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.61"
classpath 'com.android.tools.build:gradle:3.5.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "com.google.protobuf:protobuf-gradle-plugin:$protobuf_version"
}
}

rootProject.allprojects {
repositories {
jcenter()
google()
jcenter()
}
}

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'com.google.protobuf'

android {
compileSdkVersion 29

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
main.proto.srcDirs += '../protos'
}
defaultConfig {
minSdkVersion 16
targetSdkVersion 29
versionCode 1
versionName "1.0"
minSdkVersion 18
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
lintOptions {
disable 'InvalidPackage'
}
}


protobuf {
// Configure the protoc executable
protoc {
// Download from repositories
artifact = 'com.google.protobuf:protoc:3.11.4'
}
plugins {
javalite {
// The codegen for lite comes as a separate artifact
artifact = 'com.google.protobuf:protoc-gen-javalite:3.0.0'
}
}
generateProtoTasks {
all().each { task ->
task.plugins {
javalite { }
}
}
}
}

dependencies {
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.50'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'me.dm7.barcodescanner:zxing:1.9.13'
api 'com.google.android.material:material:1.0.0'
implementation 'com.google.protobuf:protobuf-lite:3.0.1'
api 'com.google.android.material:material:1.1.0'
}
5 changes: 3 additions & 2 deletions android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
android.enableJetifier=true
android.useAndroidX=true
org.gradle.jvmargs=-Xmx1536M
android.enableR8=true
android.useAndroidX=true
android.enableJetifier=true
Binary file removed android/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
1 change: 0 additions & 1 deletion android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#Tue Aug 27 10:46:28 ICT 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
Expand Down
160 changes: 0 additions & 160 deletions android/gradlew

This file was deleted.

Loading