-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add documentation and some small fixes
- Loading branch information
1 parent
455a72a
commit ef9b51c
Showing
29 changed files
with
525 additions
and
1,217 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Contributing to fast_barcode_scanner | ||
|
||
Contributions are welcome by submitting a PR for to be reviewed. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
Flutter Barcode Scanner plugin | ||
|
||
This repository consists hosts the following packages | ||
|
||
fast_barcode_scanner: code for the cross-platform facing plugin used to display a camera view within Flutter applications | ||
fast_barcode_scanner_platform_interface: the code for the common platform interface | ||
These can be found in the corresponding directories within the same name. Most developers are likely here as they are looking to use the fast_barcode_scanner plugin. There is a readme file within each directory with more information. | ||
|
||
Issues | ||
|
||
If you run into bugs, please raise them on the GitHub repository. Please do not email them to me as GitHub is the appropriate place for them and allows for members of the community to answer questions, particularly if I miss the email. It would also be much appreciated if they could be limited to actual bugs or feature requests. If you're looking at how you could use the plugin to do a particular kind of notification, check the example app provides detailed code samples for each supported feature. Also try to check the README first in case you have missed something e.g. platform-specific setup. | ||
|
||
Contributions | ||
|
||
The guidelines around submitting pull requests can be found here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,11 @@ | ||
## 0.0.1 | ||
## 1.0.2 | ||
|
||
* Even more documentation. | ||
|
||
## 1.0.1 | ||
|
||
* Updated documentation. | ||
|
||
## 1.0.0 | ||
|
||
* Initial pre-release. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,95 @@ | ||
# fast_barcode_scanner | ||
|
||
A fast barcode scanner using ML Kit (and CameraX) on Android and AVFoundation on iOS. | ||
|
||
Android implementation is still missing. | ||
|
||
Documentation coming soon. | ||
|
||
## Installation | ||
|
||
### iOS | ||
Add a description under the NSCameraUsageDescription key to your Info.plist. | ||
# fast_barcode_scanner | ||
|
||
[![pub package](https://img.shields.io/pub/v/fast_barcode_scanner)](https://pub.dev/packages/fast_barcode_scanner) | ||
|
||
A fast barcode scanner using **MLKit** (and **CameraX**) on Android and **AVFoundation** on iOS. This package leaves the UI up to the user, but rather gives an access to a camera preview. | ||
|
||
*Note*: This plugin is still under development, and some APIs might not be available yet. If you have any issues, ideas or recommendendations, don't hesitate to create an issue or pull request on github. I am using this plugin in production myself and will actively develop and maintain it going forward. | ||
|
||
**This plugin required iOS 10.0 and Android sdk version 21 or higher.** | ||
|
||
## Installation | ||
Add the following line to your **pubspec.yaml**: | ||
```yaml | ||
fast_barcode_scanner: ^1.0.2 | ||
``` | ||
### iOS | ||
Add the `NSCameraUsageDescription` key to your `ios/Runner/Info.plist`, like so: | ||
```xml | ||
<key>NSCameraUsageDescription</key> | ||
<string>This app requires access to your phone’s camera solely for scanning barcodes</string> | ||
``` | ||
|
||
### Android | ||
Change the minimum Android sdk version to 21 (or higher) in your `android/app/build.gradle` file. | ||
``` | ||
minSdkVersion 21 | ||
``` | ||
## Usage | ||
The barcode scanner consists of two main classes `CameraController` and `BarcodeCamera`. | ||
A full example looks like this: | ||
```dart | ||
import 'package:fast_barcode_scanner/fast_barcode_scanner.dart'; | ||
class MyScannerScreen extends StatelessWidget { | ||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: AppBar(title: Text('Barcode Scanner')), | ||
body: BarcodeCamera( | ||
types: const [ | ||
BarcodeType.ean8, | ||
BarcodeType.ean13, | ||
BarcodeType.code128 | ||
], | ||
resolution: Resolution.hd720, | ||
framerate: Framerate.fps30, | ||
mode: DetectionMode.pauseVideo, | ||
onScan: (code) => print(code), | ||
children: [ | ||
MaterialPreviewOverlay(animateDetection: false), | ||
BlurPreviewOverlay(), | ||
Positioned( | ||
child: ElevatedButton( | ||
onPressed: () => | ||
CameraController.instance.resumeDetector(), | ||
child: Text('Resume'), | ||
), | ||
) | ||
], | ||
) | ||
) | ||
} | ||
} | ||
``` | ||
As you can see, there are two overlays in the childrens list. These two are included in the package. `MaterialPreviewOverlay` mimics the official [material barcode scanning example](https://material.io/design/machine-learning/barcode-scanning.html#usage). `BlurPreviewOverlay` blurs the screen when a barcode is detected and unblurs it on resuming. These are normal widget, which are shown above the camera preview. Look at their source code to find out, how to react to events from the barcode scanner. | ||
|
||
### CameraController | ||
The `CameraController`-singleton manages the camera. It handles all the low level stuff like communicating with native code. It is implemented as a singleton to guarantee that there is always one and the same controller managing the camera. You can access the controller via the `CameraController.instance` attribute. These are the accessible methods: | ||
|
||
|method |Description | | ||
|----------------|-------------------------------------------------| | ||
|`initialize` | Initialized the scanner with the provided config| | ||
|`pauseDetector` | Actively pauses the scanner | | ||
|`resumeDetector`| Resumes the scanner from the paused state | | ||
|`toggleTorch` | toggles the torch on and off | | ||
|`dispose` | Stops and resets the camera on platform level | | ||
|
||
You do not have to call `initialize` yourself, if you use the `BarcodeCamera` widget. | ||
If you want to use your own widget however, have a look at `CameraController.instance.state`, which contains a `PreviewConfiguration` after initialization. This class contains all necessary information to build a preview widget yourself. | ||
|
||
### BarcodeCamera | ||
The `BarcodeCamera` is a widget showing a preview of the camera feed. It calls the `CameraController` in the background for initialization and configuration of the barcode camera. | ||
|
||
An overview of all possible configurations (either passed to `BarcodeCamera` or `CameraController.initialize`): | ||
|
||
|Attribute |Description | | ||
|-------------|---------------------------------------------------------| | ||
|`types` | See code types to scan (see `BarcodeType`) | | ||
|`mode` | Whether to pause the camera on detection | | ||
|`resolution` | The resolution of the camera feed | | ||
|`framerate` | The framerate of the camera feed | | ||
|`position` | Choose betreen back and front camera | | ||
|`onScan` | The callback when a barcode is scanned | | ||
|`children` | Child widgets to display on top (`BarcodeCamera` only) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,62 @@ | ||
group 'com.jhoogstraat.fast_barcode_scanner' | ||
version '1.0-SNAPSHOT' | ||
|
||
buildscript { | ||
ext.kotlin_version = '1.5.0' | ||
repositories { | ||
google() | ||
jcenter() | ||
} | ||
|
||
dependencies { | ||
classpath 'com.android.tools.build:gradle:4.1.0' | ||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" | ||
} | ||
} | ||
|
||
rootProject.allprojects { | ||
repositories { | ||
google() | ||
jcenter() | ||
} | ||
} | ||
|
||
apply plugin: 'com.android.library' | ||
apply plugin: 'kotlin-android' | ||
|
||
android { | ||
compileSdkVersion 30 | ||
|
||
sourceSets { | ||
main.java.srcDirs += 'src/main/kotlin' | ||
} | ||
|
||
defaultConfig { | ||
minSdkVersion 23 | ||
} | ||
|
||
lintOptions { | ||
disable 'InvalidPackage' | ||
} | ||
|
||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_1_8 | ||
targetCompatibility JavaVersion.VERSION_1_8 | ||
} | ||
|
||
// For Kotlin projects | ||
kotlinOptions { | ||
jvmTarget = "1.8" | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" | ||
|
||
def camerax_version = "1.1.0-alpha04" | ||
implementation "androidx.camera:camera-camera2:$camerax_version" | ||
implementation "androidx.camera:camera-lifecycle:$camerax_version" | ||
|
||
implementation 'com.google.mlkit:barcode-scanning:16.1.1' | ||
} | ||
group 'com.jhoogstraat.fast_barcode_scanner' | ||
version '1.0-SNAPSHOT' | ||
|
||
buildscript { | ||
ext.kotlin_version = '1.5.0' | ||
repositories { | ||
google() | ||
jcenter() | ||
} | ||
|
||
dependencies { | ||
classpath 'com.android.tools.build:gradle:4.1.0' | ||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" | ||
} | ||
} | ||
|
||
rootProject.allprojects { | ||
repositories { | ||
google() | ||
jcenter() | ||
} | ||
} | ||
|
||
apply plugin: 'com.android.library' | ||
apply plugin: 'kotlin-android' | ||
|
||
android { | ||
compileSdkVersion 30 | ||
|
||
sourceSets { | ||
main.java.srcDirs += 'src/main/kotlin' | ||
} | ||
|
||
defaultConfig { | ||
minSdkVersion 21 | ||
} | ||
|
||
lintOptions { | ||
disable 'InvalidPackage' | ||
} | ||
|
||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_1_8 | ||
targetCompatibility JavaVersion.VERSION_1_8 | ||
} | ||
|
||
// For Kotlin projects | ||
kotlinOptions { | ||
jvmTarget = "1.8" | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" | ||
|
||
def camerax_version = "1.1.0-alpha04" | ||
def mlkit_version = "16.1.1" | ||
implementation "androidx.camera:camera-camera2:$camerax_version" | ||
implementation "androidx.camera:camera-lifecycle:$camerax_version" | ||
|
||
implementation "com.google.mlkit:barcode-scanning:$mlkit_version" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,7 @@ | ||
import 'package:fast_barcode_scanner/fast_barcode_scanner.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
import 'scanner_screen.dart'; | ||
|
||
void main() { | ||
WidgetsFlutterBinding.ensureInitialized(); | ||
runApp(MyApp()); | ||
} | ||
|
||
class MyApp extends StatefulWidget { | ||
@override | ||
_MyAppState createState() => _MyAppState(); | ||
} | ||
|
||
class _MyAppState extends State<MyApp> { | ||
@override | ||
Widget build(BuildContext context) { | ||
return MaterialApp(home: ScannerScreen()); | ||
} | ||
runApp(MaterialApp(home: ScannerScreen())); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.