From ef9b51c7d4974272747e256934a9d4f463b015d4 Mon Sep 17 00:00:00 2001
From: Joshua Hoogstraat <34964599+jhoogstraat@users.noreply.github.com>
Date: Sun, 16 May 2021 12:23:38 +0200
Subject: [PATCH] Add documentation and some small fixes
---
CONTRIBUTING.md | 3 +
README.md | 15 +
fast_barcode_scanner/CHANGELOG.md | 10 +-
fast_barcode_scanner/README.md | 107 +++++-
fast_barcode_scanner/android/build.gradle | 123 +++----
.../example/android/app/build.gradle | 2 +-
.../example/lib/detections_counter.dart | 12 +-
fast_barcode_scanner/example/lib/main.dart | 16 +-
.../example/lib/scanner_screen.dart | 14 +-
fast_barcode_scanner/example/pubspec.lock | 72 ----
fast_barcode_scanner/example/pubspec.yaml | 10 -
.../lib/fast_barcode_scanner.dart | 2 +-
.../src/{camera.dart => barcode_camera.dart} | 12 +-
.../lib/src/camera_controller.dart | 73 ++++-
.../lib/src/overlays/blur_overlay.dart | 25 +-
.../lib/src/overlays/material_overlay.dart | 164 +++++-----
.../material_barcode_frame_painter.dart | 78 ++---
.../material_sensing_painter.dart | 81 +++--
fast_barcode_scanner/pubspec.lock | 161 ---------
fast_barcode_scanner/pubspec.yaml | 53 ++-
.../test/fast_barcode_scanner_test.dart | 1 -
.../CHANGELOG.md | 12 +-
.../README.md | 6 +-
...st_barcode_scanner_platform_interface.dart | 13 +-
.../lib/src/types/barcode.dart | 46 ++-
.../lib/src/types/preview_configuration.dart | 26 +-
.../pubspec.lock | 308 ------------------
.../pubspec.yaml | 16 +-
...hod_channel_fast_barcode_scanner_test.dart | 281 ----------------
29 files changed, 525 insertions(+), 1217 deletions(-)
create mode 100644 CONTRIBUTING.md
create mode 100644 README.md
delete mode 100644 fast_barcode_scanner/example/pubspec.lock
rename fast_barcode_scanner/lib/src/{camera.dart => barcode_camera.dart} (89%)
delete mode 100644 fast_barcode_scanner/pubspec.lock
delete mode 100644 fast_barcode_scanner_platform_interface/pubspec.lock
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
new file mode 100644
index 00000000..24222e22
--- /dev/null
+++ b/CONTRIBUTING.md
@@ -0,0 +1,3 @@
+Contributing to fast_barcode_scanner
+
+Contributions are welcome by submitting a PR for to be reviewed.
\ No newline at end of file
diff --git a/README.md b/README.md
new file mode 100644
index 00000000..a623b096
--- /dev/null
+++ b/README.md
@@ -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
\ No newline at end of file
diff --git a/fast_barcode_scanner/CHANGELOG.md b/fast_barcode_scanner/CHANGELOG.md
index 4582905f..dc092b1d 100644
--- a/fast_barcode_scanner/CHANGELOG.md
+++ b/fast_barcode_scanner/CHANGELOG.md
@@ -1,3 +1,11 @@
-## 0.0.1
+## 1.0.2
+
+* Even more documentation.
+
+## 1.0.1
+
+* Updated documentation.
+
+## 1.0.0
* Initial pre-release.
diff --git a/fast_barcode_scanner/README.md b/fast_barcode_scanner/README.md
index fdc37eb1..bea2f46a 100644
--- a/fast_barcode_scanner/README.md
+++ b/fast_barcode_scanner/README.md
@@ -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.
\ No newline at end of file
+# 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
+NSCameraUsageDescription
+This app requires access to your phone’s camera solely for scanning barcodes
+```
+
+### 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) |
diff --git a/fast_barcode_scanner/android/build.gradle b/fast_barcode_scanner/android/build.gradle
index 348b4300..997ea2ce 100644
--- a/fast_barcode_scanner/android/build.gradle
+++ b/fast_barcode_scanner/android/build.gradle
@@ -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"
+}
diff --git a/fast_barcode_scanner/example/android/app/build.gradle b/fast_barcode_scanner/example/android/app/build.gradle
index 8fadebf2..ab5f3866 100644
--- a/fast_barcode_scanner/example/android/app/build.gradle
+++ b/fast_barcode_scanner/example/android/app/build.gradle
@@ -34,7 +34,7 @@ android {
defaultConfig {
applicationId "com.jhoogstraat.fast_barcode_scanner_example"
- minSdkVersion 23
+ minSdkVersion 21
targetSdkVersion 30
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
diff --git a/fast_barcode_scanner/example/lib/detections_counter.dart b/fast_barcode_scanner/example/lib/detections_counter.dart
index f64f7f18..10b74277 100644
--- a/fast_barcode_scanner/example/lib/detections_counter.dart
+++ b/fast_barcode_scanner/example/lib/detections_counter.dart
@@ -1,5 +1,5 @@
import 'dart:async';
-import 'package:fast_barcode_scanner/fast_barcode_scanner.dart';
+import 'package:fast_barcode_scanner_example/scanner_screen.dart';
import 'package:flutter/material.dart';
class DetectionsCounter extends StatefulWidget {
@@ -11,11 +11,11 @@ class _DetectionsCounterState extends State {
@override
void initState() {
super.initState();
- // _streamToken = CameraController.instance.state.codeStream.listen((event) {
- // final count = detectionCount.update(event.value, (value) => value + 1,
- // ifAbsent: () => 1);
- // detectionInfo.value = "${count}x\n${event.value}";
- // });
+ _streamToken = codeStream.stream.listen((event) {
+ final count = detectionCount.update(event.value, (value) => value + 1,
+ ifAbsent: () => 1);
+ detectionInfo.value = "${count}x\n${event.value}";
+ });
}
late StreamSubscription _streamToken;
diff --git a/fast_barcode_scanner/example/lib/main.dart b/fast_barcode_scanner/example/lib/main.dart
index 7828a00a..3ae78596 100644
--- a/fast_barcode_scanner/example/lib/main.dart
+++ b/fast_barcode_scanner/example/lib/main.dart
@@ -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 {
- @override
- Widget build(BuildContext context) {
- return MaterialApp(home: ScannerScreen());
- }
+ runApp(MaterialApp(home: ScannerScreen()));
}
diff --git a/fast_barcode_scanner/example/lib/scanner_screen.dart b/fast_barcode_scanner/example/lib/scanner_screen.dart
index b028d505..e33b5c10 100644
--- a/fast_barcode_scanner/example/lib/scanner_screen.dart
+++ b/fast_barcode_scanner/example/lib/scanner_screen.dart
@@ -1,7 +1,11 @@
+import 'dart:async';
+
import 'package:fast_barcode_scanner/fast_barcode_scanner.dart';
import 'package:flutter/material.dart';
import 'detections_counter.dart';
+final codeStream = StreamController.broadcast();
+
class ScannerScreen extends StatefulWidget {
@override
_ScannerScreenState createState() => _ScannerScreenState();
@@ -35,9 +39,8 @@ class _ScannerScreenState extends State {
),
),
IconButton(
- onPressed: () => Navigator.pushReplacement(
- context, MaterialPageRoute(builder: (ctx) => ScannerScreen())),
- icon: Icon(Icons.navigate_next),
+ onPressed: () => print("switch camera in the future"),
+ icon: Icon(Icons.switch_camera),
)
],
),
@@ -51,12 +54,15 @@ class _ScannerScreenState extends State {
resolution: Resolution.hd720,
framerate: Framerate.fps30,
mode: DetectionMode.pauseVideo,
- position: CameraPosition.front,
+ position: CameraPosition.back,
+ onScan: (code) => codeStream.add(code),
children: [
MaterialPreviewOverlay(animateDetection: false),
BlurPreviewOverlay(),
Positioned(
bottom: 50,
+ left: 0,
+ right: 0,
child: Column(
children: [
ElevatedButton(
diff --git a/fast_barcode_scanner/example/pubspec.lock b/fast_barcode_scanner/example/pubspec.lock
deleted file mode 100644
index a00f6642..00000000
--- a/fast_barcode_scanner/example/pubspec.lock
+++ /dev/null
@@ -1,72 +0,0 @@
-# Generated by pub
-# See https://dart.dev/tools/pub/glossary#lockfile
-packages:
- characters:
- dependency: transitive
- description:
- name: characters
- url: "https://pub.dartlang.org"
- source: hosted
- version: "1.1.0"
- collection:
- dependency: transitive
- description:
- name: collection
- url: "https://pub.dartlang.org"
- source: hosted
- version: "1.15.0"
- fast_barcode_scanner:
- dependency: "direct main"
- description:
- path: ".."
- relative: true
- source: path
- version: "0.0.1"
- fast_barcode_scanner_platform_interface:
- dependency: transitive
- description:
- path: "../../fast_barcode_scanner_platform_interface"
- relative: true
- source: path
- version: "0.0.1"
- flutter:
- dependency: "direct main"
- description: flutter
- source: sdk
- version: "0.0.0"
- meta:
- dependency: transitive
- description:
- name: meta
- url: "https://pub.dartlang.org"
- source: hosted
- version: "1.3.0"
- plugin_platform_interface:
- dependency: transitive
- description:
- name: plugin_platform_interface
- url: "https://pub.dartlang.org"
- source: hosted
- version: "2.0.0"
- sky_engine:
- dependency: transitive
- description: flutter
- source: sdk
- version: "0.0.99"
- typed_data:
- dependency: transitive
- description:
- name: typed_data
- url: "https://pub.dartlang.org"
- source: hosted
- version: "1.3.0"
- vector_math:
- dependency: transitive
- description:
- name: vector_math
- url: "https://pub.dartlang.org"
- source: hosted
- version: "2.1.0"
-sdks:
- dart: ">=2.12.0 <3.0.0"
- flutter: ">=2.0.0"
diff --git a/fast_barcode_scanner/example/pubspec.yaml b/fast_barcode_scanner/example/pubspec.yaml
index 94b9b90f..c36f2a65 100644
--- a/fast_barcode_scanner/example/pubspec.yaml
+++ b/fast_barcode_scanner/example/pubspec.yaml
@@ -1,8 +1,5 @@
name: fast_barcode_scanner_example
description: Demonstrates how to use the fast_barcode_scanner plugin.
-
-# The following line prevents the package from being accidentally published to
-# pub.dev using `pub publish`. This is preferred for private packages.
publish_to: 'none'
environment:
@@ -13,14 +10,7 @@ dependencies:
sdk: flutter
fast_barcode_scanner:
- # When depending on this package from a real application you should use:
- # fast_barcode_scanner: ^x.y.z
- # See https://dart.dev/tools/pub/dependencies#version-constraints
- # The example app is bundled with the plugin so we use a path dependency on
- # the parent directory to use the current plugin's version.
path: ../
- # fast_barcode_scanner_beeper:
- # path: ../../fast_barcode_scanner_beeper
flutter:
uses-material-design: true
\ No newline at end of file
diff --git a/fast_barcode_scanner/lib/fast_barcode_scanner.dart b/fast_barcode_scanner/lib/fast_barcode_scanner.dart
index 89cf72c3..45435f4f 100644
--- a/fast_barcode_scanner/lib/fast_barcode_scanner.dart
+++ b/fast_barcode_scanner/lib/fast_barcode_scanner.dart
@@ -1,4 +1,4 @@
-export 'package:fast_barcode_scanner/src/camera.dart';
+export 'package:fast_barcode_scanner/src/barcode_camera.dart';
export 'package:fast_barcode_scanner/src/camera_controller.dart';
export 'package:fast_barcode_scanner/src/overlays/blur_overlay.dart';
export 'package:fast_barcode_scanner/src/overlays/material_overlay.dart';
diff --git a/fast_barcode_scanner/lib/src/camera.dart b/fast_barcode_scanner/lib/src/barcode_camera.dart
similarity index 89%
rename from fast_barcode_scanner/lib/src/camera.dart
rename to fast_barcode_scanner/lib/src/barcode_camera.dart
index 7c4acd49..309f1f2d 100644
--- a/fast_barcode_scanner/lib/src/camera.dart
+++ b/fast_barcode_scanner/lib/src/barcode_camera.dart
@@ -16,7 +16,7 @@ final ErrorCallback _defaultOnError = (BuildContext context, Object? error) {
/// The main class connecting the platform code to the UI.
///
/// This class is used in the widget tree and connects to the camera
-/// as soon as the build method gets called.
+/// as soon as didChangeDependencies gets called.
class BarcodeCamera extends StatefulWidget {
BarcodeCamera(
{Key? key,
@@ -59,19 +59,19 @@ class BarcodeCameraState extends State {
@override
Widget build(BuildContext context) {
- final camera = CameraController.instance.state;
+ final cameraState = CameraController.instance.state;
return ColoredBox(
color: Colors.black,
child: AnimatedOpacity(
opacity: _opacity,
duration: const Duration(milliseconds: 260),
- child: camera.hasError
- ? widget.onError(context, camera.error!)
+ child: cameraState.hasError
+ ? widget.onError(context, cameraState.error!)
: Stack(
fit: StackFit.expand,
children: [
- if (camera.isInitialized)
- _buildPreview(camera.previewConfig!),
+ if (cameraState.isInitialized)
+ _buildPreview(cameraState.previewConfig!),
...widget.children
],
),
diff --git a/fast_barcode_scanner/lib/src/camera_controller.dart b/fast_barcode_scanner/lib/src/camera_controller.dart
index 8c125038..82507a47 100644
--- a/fast_barcode_scanner/lib/src/camera_controller.dart
+++ b/fast_barcode_scanner/lib/src/camera_controller.dart
@@ -8,22 +8,54 @@ class CameraConfiguration {
const CameraConfiguration(this.types, this.resolution, this.framerate,
this.detectionMode, this.position);
+ /// The types the scanner should look out for.
+ ///
+ /// If a barcode type is not in this list, it will not be detected.
final List types;
+
+ /// The target resolution of the camera feed.
+ ///
+ /// This is experimental, but functional. Should not be set higher
+ /// than necessary.
final Resolution resolution;
+
+ /// The target framerate of the camera feed.
+ ///
+ /// This is experimental, but functional on iOS. Should not be set higher
+ /// than necessary.
final Framerate framerate;
+
+ ///
final DetectionMode detectionMode;
final CameraPosition position;
}
enum CameraEvent { uninitialized, init, paused, resumed, codeFound, error }
+class CameraState {
+ PreviewConfiguration? _previewConfig;
+ bool _togglingTorch = false;
+ Object? _error;
+
+ Object? get error => _error;
+ PreviewConfiguration? get previewConfig => _previewConfig;
+
+ final eventNotifier = ValueNotifier(CameraEvent.uninitialized);
+
+ bool get isInitialized => _previewConfig != null;
+ bool get hasError => error != null;
+}
+
class CameraController {
CameraController._() : this.state = CameraState();
static final _instance = CameraController._();
static CameraController get instance => _instance;
- // Data
+ /// The cumulated state of the barcode scanner.
+ ///
+ /// Contains information about the configuration, torch,
+ /// errors and events.
final CameraState state;
FastBarcodeScannerPlatform get _platform =>
@@ -33,8 +65,9 @@ class CameraController {
/// Informs the platform to initialize the camera.
///
- /// The camera is initialized only once per session.
- /// All susequent calls to this method will be dropped.
+ /// The camera is disposed and reinitialized when calling this
+ /// method repeatedly.
+ /// Events and errors are received via the current state's eventNotifier.
Future initialize(
List types,
Resolution resolution,
@@ -57,44 +90,63 @@ class CameraController {
state.eventNotifier.value = CameraEvent.resumed;
} catch (error, stack) {
+ state._error = error;
+ state.eventNotifier.value = CameraEvent.error;
print(error);
debugPrintStack(stackTrace: stack);
- state.eventNotifier.value = CameraEvent.error;
return;
}
}
+ /// Disposed the platform camera and resets the whole system.
+ ///
+ ///
Future dispose() async {
try {
await _platform.dispose();
state._previewConfig = null;
state.eventNotifier.value = CameraEvent.uninitialized;
} catch (error, stack) {
+ state._error = error;
+ state.eventNotifier.value = CameraEvent.error;
print(error);
debugPrintStack(stackTrace: stack);
}
}
+ /// Pauses the scanner and preview on the platform level.
+ ///
+ ///
Future pauseDetector() async {
try {
await _platform.pause();
state.eventNotifier.value = CameraEvent.paused;
} catch (error, stack) {
+ state._error = error;
+ state.eventNotifier.value = CameraEvent.error;
print(error);
debugPrintStack(stackTrace: stack);
}
}
+ /// Resumes the scanner and preview on the platform level.
+ ///
+ ///
Future resumeDetector() async {
try {
await _platform.resume();
state.eventNotifier.value = CameraEvent.resumed;
} catch (error, stack) {
+ state._error = error;
+ state.eventNotifier.value = CameraEvent.error;
print(error);
debugPrintStack(stackTrace: stack);
}
}
+ /// Toggles the torch, if available.
+ ///
+ ///
Future toggleTorch() async {
if (!state._togglingTorch) {
state._togglingTorch = true;
@@ -102,6 +154,8 @@ class CameraController {
try {
await _platform.toggleTorch();
} catch (error, stack) {
+ state._error = error;
+ state.eventNotifier.value = CameraEvent.error;
print(error);
debugPrintStack(stackTrace: stack);
}
@@ -110,14 +164,3 @@ class CameraController {
}
}
}
-
-class CameraState {
- PreviewConfiguration? _previewConfig;
- bool _togglingTorch = false;
- Object? error;
-
- final eventNotifier = ValueNotifier(CameraEvent.uninitialized);
- bool get isInitialized => _previewConfig != null;
- bool get hasError => error != null;
- PreviewConfiguration? get previewConfig => _previewConfig;
-}
diff --git a/fast_barcode_scanner/lib/src/overlays/blur_overlay.dart b/fast_barcode_scanner/lib/src/overlays/blur_overlay.dart
index 6ea3a69f..24b6cab0 100644
--- a/fast_barcode_scanner/lib/src/overlays/blur_overlay.dart
+++ b/fast_barcode_scanner/lib/src/overlays/blur_overlay.dart
@@ -18,17 +18,18 @@ class BlurPreviewOverlay extends StatelessWidget {
@override
Widget build(BuildContext context) {
return ValueListenableBuilder(
- valueListenable: CameraController.instance.state.eventNotifier,
- builder: (context, event, child) {
- return TweenAnimationBuilder(
- tween: Tween(begin: 0.0, end: shouldBlur(event) ? blurAmount : 0.0),
- duration: duration,
- curve: Curves.easeOut,
- child: Container(color: Colors.black.withOpacity(0.0)),
- builder: (_, value, child) => BackdropFilter(
- filter: ImageFilter.blur(sigmaX: value, sigmaY: value),
- child: child),
- );
- });
+ valueListenable: CameraController.instance.state.eventNotifier,
+ builder: (context, event, child) {
+ return TweenAnimationBuilder(
+ tween: Tween(begin: 0.0, end: shouldBlur(event) ? blurAmount : 0.0),
+ duration: duration,
+ curve: Curves.easeOut,
+ child: Container(color: Colors.black.withOpacity(0.0)),
+ builder: (_, value, child) => BackdropFilter(
+ filter: ImageFilter.blur(sigmaX: value, sigmaY: value),
+ child: child),
+ );
+ },
+ );
}
}
diff --git a/fast_barcode_scanner/lib/src/overlays/material_overlay.dart b/fast_barcode_scanner/lib/src/overlays/material_overlay.dart
index 00ab587b..145069dc 100644
--- a/fast_barcode_scanner/lib/src/overlays/material_overlay.dart
+++ b/fast_barcode_scanner/lib/src/overlays/material_overlay.dart
@@ -1,86 +1,78 @@
-import 'package:flutter/material.dart';
-
-import 'material_scanner_painter/material_barcode_frame_painter.dart';
-import 'material_scanner_painter/material_sensing_painter.dart';
-
-class MaterialPreviewOverlay extends StatefulWidget {
- const MaterialPreviewOverlay(
- {Key? key, this.animateDetection = true, this.aspectRatio = 16 / 9})
- : super(key: key);
-
- final bool animateDetection;
- final double aspectRatio;
-
- @override
- MaterialPreviewOverlayState createState() => MaterialPreviewOverlayState();
-}
-
-class MaterialPreviewOverlayState extends State
- with SingleTickerProviderStateMixin {
- late AnimationController _controller;
- late Animation _opacitySequence;
- late Animation _inflateSequence;
-
- @override
- void initState() {
- super.initState();
-
- if (widget.animateDetection) {
- _controller = AnimationController(
- duration: Duration(milliseconds: 1100), vsync: this);
-
- final fadeIn = 20.0;
- final wait = 2.0;
- final expand = 25.0;
-
- _opacitySequence = TweenSequence([
- TweenSequenceItem(tween: Tween(begin: 0.0, end: 1.0), weight: fadeIn),
- TweenSequenceItem(tween: ConstantTween(1.0), weight: wait),
- TweenSequenceItem(
- tween: Tween(begin: 1.0, end: 0.0)
- .chain(CurveTween(curve: Curves.easeOutCubic)),
- weight: expand),
- // TweenSequenceItem(tween: ConstantTween(0.0), weight: idle),
- ]).animate(_controller);
-
- _inflateSequence = TweenSequence([
- TweenSequenceItem(tween: ConstantTween(0.0), weight: fadeIn + wait),
- TweenSequenceItem(
- tween: Tween(begin: 0.0, end: 1.0)
- .chain(CurveTween(curve: Curves.easeOutCubic)),
- weight: expand),
- // TweenSequenceItem(tween: ConstantTween(0.0), weight: idle),
- ]).animate(_controller);
- }
- }
-
- // @override
- // void didDetectBarcode() async {
- // if (widget.animateDetection) {
- // await _controller.forward();
- // _controller.reset();
- // }
- // }
-
- @override
- Widget build(BuildContext context) {
- return RepaintBoundary(
- child: SizedBox.expand(
- child: widget.animateDetection
- ? _buildAnimation(context)
- : CustomPaint(
- painter: MaterialBarcodeFramePainter(widget.aspectRatio))),
- );
- }
-
- Widget _buildAnimation(BuildContext context) {
- return AnimatedBuilder(
- animation: _controller,
- builder: (context, child) => CustomPaint(
- painter: MaterialBarcodeFramePainter(widget.aspectRatio),
- foregroundPainter: MaterialBarcodeSensingPainter(
- inflate: _inflateSequence.value, opacity: _opacitySequence.value),
- ),
- );
- }
-}
+import 'package:flutter/material.dart';
+
+import 'material_scanner_painter/material_barcode_frame_painter.dart';
+import 'material_scanner_painter/material_sensing_painter.dart';
+
+class MaterialPreviewOverlay extends StatefulWidget {
+ const MaterialPreviewOverlay(
+ {Key? key, this.animateDetection = true, this.aspectRatio = 16 / 9})
+ : super(key: key);
+
+ final bool animateDetection;
+ final double aspectRatio;
+
+ @override
+ MaterialPreviewOverlayState createState() => MaterialPreviewOverlayState();
+}
+
+class MaterialPreviewOverlayState extends State
+ with SingleTickerProviderStateMixin {
+ late AnimationController _controller;
+ late Animation _opacitySequence;
+ late Animation _inflateSequence;
+
+ @override
+ void initState() {
+ super.initState();
+
+ if (widget.animateDetection) {
+ _controller = AnimationController(
+ duration: Duration(milliseconds: 1100), vsync: this);
+
+ final fadeIn = 20.0;
+ final wait = 2.0;
+ final expand = 25.0;
+
+ _opacitySequence = TweenSequence([
+ TweenSequenceItem(tween: Tween(begin: 0.0, end: 1.0), weight: fadeIn),
+ TweenSequenceItem(tween: ConstantTween(1.0), weight: wait),
+ TweenSequenceItem(
+ tween: Tween(begin: 1.0, end: 0.0)
+ .chain(CurveTween(curve: Curves.easeOutCubic)),
+ weight: expand),
+ // TweenSequenceItem(tween: ConstantTween(0.0), weight: idle),
+ ]).animate(_controller);
+
+ _inflateSequence = TweenSequence([
+ TweenSequenceItem(tween: ConstantTween(0.0), weight: fadeIn + wait),
+ TweenSequenceItem(
+ tween: Tween(begin: 0.0, end: 1.0)
+ .chain(CurveTween(curve: Curves.easeOutCubic)),
+ weight: expand),
+ // TweenSequenceItem(tween: ConstantTween(0.0), weight: idle),
+ ]).animate(_controller);
+ }
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ return RepaintBoundary(
+ child: SizedBox.expand(
+ child: widget.animateDetection
+ ? _buildAnimation(context)
+ : CustomPaint(
+ painter: MaterialBarcodeFramePainter(widget.aspectRatio))),
+ );
+ }
+
+ Widget _buildAnimation(BuildContext context) {
+ return AnimatedBuilder(
+ animation: _controller,
+ builder: (context, child) => CustomPaint(
+ painter: MaterialBarcodeFramePainter(widget.aspectRatio),
+ foregroundPainter: MaterialBarcodeSensingPainter(
+ inflate: _inflateSequence.value, opacity: _opacitySequence.value),
+ ),
+ );
+ }
+}
diff --git a/fast_barcode_scanner/lib/src/overlays/material_scanner_painter/material_barcode_frame_painter.dart b/fast_barcode_scanner/lib/src/overlays/material_scanner_painter/material_barcode_frame_painter.dart
index d053c09f..24a02bf0 100644
--- a/fast_barcode_scanner/lib/src/overlays/material_scanner_painter/material_barcode_frame_painter.dart
+++ b/fast_barcode_scanner/lib/src/overlays/material_scanner_painter/material_barcode_frame_painter.dart
@@ -1,39 +1,39 @@
-import 'package:flutter/material.dart';
-
-class MaterialBarcodeFramePainter extends CustomPainter {
- const MaterialBarcodeFramePainter(this.aspectRatio);
-
- final double aspectRatio;
-
- static final borderPaint = Paint()
- ..style = PaintingStyle.stroke
- ..strokeWidth = 5 // strokeWidth is painted 50/50 outwards and inwards.
- ..color = Colors.black.withAlpha(160);
-
- static final backgroundPaint = Paint()..color = Colors.black38;
-
- @override
- void paint(Canvas canvas, Size size) {
- final screenRect = Rect.fromLTWH(0, 0, size.width, size.height);
-
- final cutOutWidth = screenRect.width - 45;
- final cutOutHeight = 1 / aspectRatio * cutOutWidth;
- final cutOut = RRect.fromRectXY(
- Rect.fromCenter(
- center: screenRect.center,
- width: cutOutWidth,
- height: cutOutHeight),
- 12,
- 12);
-
- final cutOutPath = Path.combine(PathOperation.difference,
- Path()..addRect(screenRect), Path()..addRRect(cutOut));
-
- canvas
- ..drawPath(cutOutPath, backgroundPaint)
- ..drawRRect(cutOut.deflate(borderPaint.strokeWidth / 2), borderPaint);
- }
-
- @override
- bool shouldRepaint(MaterialBarcodeFramePainter oldDelegate) => false;
-}
+import 'package:flutter/material.dart';
+
+class MaterialBarcodeFramePainter extends CustomPainter {
+ const MaterialBarcodeFramePainter(this.aspectRatio);
+
+ final double aspectRatio;
+
+ static final borderPaint = Paint()
+ ..style = PaintingStyle.stroke
+ ..strokeWidth = 5 // strokeWidth is painted 50/50 outwards and inwards.
+ ..color = Colors.black.withAlpha(160);
+
+ static final backgroundPaint = Paint()..color = Colors.black38;
+
+ @override
+ void paint(Canvas canvas, Size size) {
+ final screenRect = Rect.fromLTWH(0, 0, size.width, size.height);
+
+ final cutOutWidth = screenRect.width - 45;
+ final cutOutHeight = 1 / aspectRatio * cutOutWidth;
+ final cutOut = RRect.fromRectXY(
+ Rect.fromCenter(
+ center: screenRect.center,
+ width: cutOutWidth,
+ height: cutOutHeight),
+ 12,
+ 12);
+
+ final cutOutPath = Path.combine(PathOperation.difference,
+ Path()..addRect(screenRect), Path()..addRRect(cutOut));
+
+ canvas
+ ..drawPath(cutOutPath, backgroundPaint)
+ ..drawRRect(cutOut.deflate(borderPaint.strokeWidth / 2), borderPaint);
+ }
+
+ @override
+ bool shouldRepaint(MaterialBarcodeFramePainter oldDelegate) => false;
+}
diff --git a/fast_barcode_scanner/lib/src/overlays/material_scanner_painter/material_sensing_painter.dart b/fast_barcode_scanner/lib/src/overlays/material_scanner_painter/material_sensing_painter.dart
index e7e5af33..9d525918 100644
--- a/fast_barcode_scanner/lib/src/overlays/material_scanner_painter/material_sensing_painter.dart
+++ b/fast_barcode_scanner/lib/src/overlays/material_scanner_painter/material_sensing_painter.dart
@@ -1,41 +1,40 @@
-import 'package:flutter/material.dart';
-
-class MaterialBarcodeSensingPainter extends CustomPainter {
- MaterialBarcodeSensingPainter(
- {required this.inflate, required this.opacity});
-
- final double inflate;
- final double opacity;
-
- final sensingPaint = Paint()
- ..style = PaintingStyle.stroke
- ..strokeWidth = 5; // strokeWidth is painted 50/50 outwards and inwards.
-
- @override
- void paint(Canvas canvas, Size size) {
- final rect = Rect.fromLTWH(0, 0, size.width, size.height);
-
- final cutOut = RRect.fromRectXY(
- Rect.fromCenter(
- center: rect.center, width: rect.width - 45, height: 165),
- 12,
- 12);
-
- sensingPaint.color = Colors.white.withAlpha((255 * opacity).toInt());
- sensingPaint.strokeWidth = 5 - 4 * inflate;
-
- canvas.drawRRect(
- _inflate(cutOut.deflate(sensingPaint.strokeWidth / 2)), sensingPaint);
- }
-
- /// Inflates a rect, but keeps the border radius.
- RRect _inflate(RRect rect) {
- return RRect.fromRectAndRadius(
- rect.outerRect.inflate(inflate * 20), rect.blRadius);
- }
-
- @override
- bool shouldRepaint(MaterialBarcodeSensingPainter oldDelegate) {
- return oldDelegate.opacity != opacity || oldDelegate.inflate != inflate;
- }
-}
+import 'package:flutter/material.dart';
+
+class MaterialBarcodeSensingPainter extends CustomPainter {
+ MaterialBarcodeSensingPainter({required this.inflate, required this.opacity});
+
+ final double inflate;
+ final double opacity;
+
+ final sensingPaint = Paint()
+ ..style = PaintingStyle.stroke
+ ..strokeWidth = 5; // strokeWidth is painted 50/50 outwards and inwards.
+
+ @override
+ void paint(Canvas canvas, Size size) {
+ final rect = Rect.fromLTWH(0, 0, size.width, size.height);
+
+ final cutOut = RRect.fromRectXY(
+ Rect.fromCenter(
+ center: rect.center, width: rect.width - 45, height: 165),
+ 12,
+ 12);
+
+ sensingPaint.color = Colors.white.withAlpha((255 * opacity).toInt());
+ sensingPaint.strokeWidth = 5 - 4 * inflate;
+
+ canvas.drawRRect(
+ _inflate(cutOut.deflate(sensingPaint.strokeWidth / 2)), sensingPaint);
+ }
+
+ /// Inflates a rect, but keeps the border radius.
+ RRect _inflate(RRect rect) {
+ return RRect.fromRectAndRadius(
+ rect.outerRect.inflate(inflate * 20), rect.blRadius);
+ }
+
+ @override
+ bool shouldRepaint(MaterialBarcodeSensingPainter oldDelegate) {
+ return oldDelegate.opacity != opacity || oldDelegate.inflate != inflate;
+ }
+}
diff --git a/fast_barcode_scanner/pubspec.lock b/fast_barcode_scanner/pubspec.lock
deleted file mode 100644
index a33e2bd6..00000000
--- a/fast_barcode_scanner/pubspec.lock
+++ /dev/null
@@ -1,161 +0,0 @@
-# Generated by pub
-# See https://dart.dev/tools/pub/glossary#lockfile
-packages:
- async:
- dependency: transitive
- description:
- name: async
- url: "https://pub.dartlang.org"
- source: hosted
- version: "2.5.0"
- boolean_selector:
- dependency: transitive
- description:
- name: boolean_selector
- url: "https://pub.dartlang.org"
- source: hosted
- version: "2.1.0"
- characters:
- dependency: transitive
- description:
- name: characters
- url: "https://pub.dartlang.org"
- source: hosted
- version: "1.1.0"
- charcode:
- dependency: transitive
- description:
- name: charcode
- url: "https://pub.dartlang.org"
- source: hosted
- version: "1.2.0"
- clock:
- dependency: transitive
- description:
- name: clock
- url: "https://pub.dartlang.org"
- source: hosted
- version: "1.1.0"
- collection:
- dependency: transitive
- description:
- name: collection
- url: "https://pub.dartlang.org"
- source: hosted
- version: "1.15.0"
- fake_async:
- dependency: transitive
- description:
- name: fake_async
- url: "https://pub.dartlang.org"
- source: hosted
- version: "1.2.0"
- fast_barcode_scanner_platform_interface:
- dependency: "direct main"
- description:
- path: "../fast_barcode_scanner_platform_interface"
- relative: true
- source: path
- version: "0.0.1"
- flutter:
- dependency: "direct main"
- description: flutter
- source: sdk
- version: "0.0.0"
- flutter_test:
- dependency: "direct dev"
- description: flutter
- source: sdk
- version: "0.0.0"
- matcher:
- dependency: transitive
- description:
- name: matcher
- url: "https://pub.dartlang.org"
- source: hosted
- version: "0.12.10"
- meta:
- dependency: transitive
- description:
- name: meta
- url: "https://pub.dartlang.org"
- source: hosted
- version: "1.3.0"
- path:
- dependency: transitive
- description:
- name: path
- url: "https://pub.dartlang.org"
- source: hosted
- version: "1.8.0"
- plugin_platform_interface:
- dependency: transitive
- description:
- name: plugin_platform_interface
- url: "https://pub.dartlang.org"
- source: hosted
- version: "2.0.0"
- sky_engine:
- dependency: transitive
- description: flutter
- source: sdk
- version: "0.0.99"
- source_span:
- dependency: transitive
- description:
- name: source_span
- url: "https://pub.dartlang.org"
- source: hosted
- version: "1.8.0"
- stack_trace:
- dependency: transitive
- description:
- name: stack_trace
- url: "https://pub.dartlang.org"
- source: hosted
- version: "1.10.0"
- stream_channel:
- dependency: transitive
- description:
- name: stream_channel
- url: "https://pub.dartlang.org"
- source: hosted
- version: "2.1.0"
- string_scanner:
- dependency: transitive
- description:
- name: string_scanner
- url: "https://pub.dartlang.org"
- source: hosted
- version: "1.1.0"
- term_glyph:
- dependency: transitive
- description:
- name: term_glyph
- url: "https://pub.dartlang.org"
- source: hosted
- version: "1.2.0"
- test_api:
- dependency: transitive
- description:
- name: test_api
- url: "https://pub.dartlang.org"
- source: hosted
- version: "0.2.19"
- typed_data:
- dependency: transitive
- description:
- name: typed_data
- url: "https://pub.dartlang.org"
- source: hosted
- version: "1.3.0"
- vector_math:
- dependency: transitive
- description:
- name: vector_math
- url: "https://pub.dartlang.org"
- source: hosted
- version: "2.1.0"
-sdks:
- dart: ">=2.12.0 <3.0.0"
- flutter: ">=2.0.0"
diff --git a/fast_barcode_scanner/pubspec.yaml b/fast_barcode_scanner/pubspec.yaml
index 3d37a29b..f6cfe0c5 100644
--- a/fast_barcode_scanner/pubspec.yaml
+++ b/fast_barcode_scanner/pubspec.yaml
@@ -1,28 +1,27 @@
-name: fast_barcode_scanner
-description: A fast barcode scanner using ML Kit on Android and AVFoundation on iOS.
-version: 0.0.1
-author: Joshua Hoogstraat
-homepage: https://github.com/jhoogstraat/fast_barcode_scanner
-
-environment:
- sdk: '>=2.12.0 <3.0.0'
- flutter: ">=2.0.0 < 3.0.0"
-
-dependencies:
- flutter:
- sdk: flutter
- fast_barcode_scanner_platform_interface:
- path: ../fast_barcode_scanner_platform_interface
-
-dev_dependencies:
- flutter_test:
- sdk: flutter
-
-flutter:
- plugin:
- platforms:
- android:
- package: com.jhoogstraat.fast_barcode_scanner
- pluginClass: FastBarcodeScannerPlugin
- ios:
+name: fast_barcode_scanner
+description: A fast barcode scanner using MLKit on Android and AVFoundation on iOS.
+version: 1.0.2
+homepage: https://github.com/jhoogstraat/fast_barcode_scanner
+repository: https://github.com/jhoogstraat/fast_barcode_scanner
+
+environment:
+ sdk: '>=2.12.0 <3.0.0'
+ flutter: ">=2.0.0"
+
+dependencies:
+ flutter:
+ sdk: flutter
+ fast_barcode_scanner_platform_interface: ^1.0.2
+
+dev_dependencies:
+ flutter_test:
+ sdk: flutter
+
+flutter:
+ plugin:
+ platforms:
+ android:
+ package: com.jhoogstraat.fast_barcode_scanner
+ pluginClass: FastBarcodeScannerPlugin
+ ios:
pluginClass: FastBarcodeScannerPlugin
\ No newline at end of file
diff --git a/fast_barcode_scanner/test/fast_barcode_scanner_test.dart b/fast_barcode_scanner/test/fast_barcode_scanner_test.dart
index 7a5bfeea..bce9dcff 100644
--- a/fast_barcode_scanner/test/fast_barcode_scanner_test.dart
+++ b/fast_barcode_scanner/test/fast_barcode_scanner_test.dart
@@ -1,6 +1,5 @@
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
-import 'package:fast_barcode_scanner/fast_barcode_scanner.dart';
void main() {
const MethodChannel channel = MethodChannel('fast_barcode_scanner');
diff --git a/fast_barcode_scanner_platform_interface/CHANGELOG.md b/fast_barcode_scanner_platform_interface/CHANGELOG.md
index 4582905f..d9468bae 100644
--- a/fast_barcode_scanner_platform_interface/CHANGELOG.md
+++ b/fast_barcode_scanner_platform_interface/CHANGELOG.md
@@ -1,3 +1,11 @@
-## 0.0.1
+## 1.0.2
-* Initial pre-release.
+* Even more documentation.
+
+## 1.0.1
+
+* Updated documentation.
+
+## 1.0.0
+
+* Initial release.
diff --git a/fast_barcode_scanner_platform_interface/README.md b/fast_barcode_scanner_platform_interface/README.md
index 49343793..a96a1376 100644
--- a/fast_barcode_scanner_platform_interface/README.md
+++ b/fast_barcode_scanner_platform_interface/README.md
@@ -1,7 +1,5 @@
# fast_barcode_scanner_platform_interface
-A fast barcode scanner using ML Kit (and CameraX) on Android and AVFoundation on iOS.
+A fast barcode scanner using MLKit (and CameraX) on Android and AVFoundation on iOS.
-Android implementation is still missing.
-
-Documentation coming soon.
\ No newline at end of file
+This package contains the contract for the fast_barcode_scanner plugin.
\ No newline at end of file
diff --git a/fast_barcode_scanner_platform_interface/lib/src/fast_barcode_scanner_platform_interface.dart b/fast_barcode_scanner_platform_interface/lib/src/fast_barcode_scanner_platform_interface.dart
index 37810ac2..fc55b11e 100644
--- a/fast_barcode_scanner_platform_interface/lib/src/fast_barcode_scanner_platform_interface.dart
+++ b/fast_barcode_scanner_platform_interface/lib/src/fast_barcode_scanner_platform_interface.dart
@@ -25,15 +25,15 @@ abstract class FastBarcodeScannerPlatform extends PlatformInterface {
/// Defaults to [MethodChannelFastBarcodeScanner].
static FastBarcodeScannerPlatform get instance => _instance;
- /// Platform-specific plugins should set this with their own platform-specific
+ /// Platform specific plugins should set this with their own platform-specific
/// class that extends [FastBarcodeScannerPlatform] when they register themselves.
static set instance(FastBarcodeScannerPlatform instance) {
PlatformInterface.verifyToken(instance, _token);
_instance = instance;
}
- /// Returns a [PreviewConfiguration] containing the parameters with wich the camera is set up.
- ///
+ /// Returns a [PreviewConfiguration] containing the parameters with
+ /// which the camera is set up.
///
Future init(
List types,
@@ -44,22 +44,27 @@ abstract class FastBarcodeScannerPlatform extends PlatformInterface {
throw UnimplementedError('init() has not been implemented');
}
+ /// Pauses the camera on the platform.
Future pause() {
throw UnimplementedError('pause() has not been implemented');
}
+ /// Resumes the camera from the paused state on the platform.
Future resume() {
throw UnimplementedError('resume() has not been implemented');
}
+ /// Stops and clears the camera ressources.
Future dispose() {
- throw UnimplementedError('stop() has not been implemented');
+ throw UnimplementedError('dispose() has not been implemented');
}
+ /// Toggles the torch, if available.
Future toggleTorch() {
throw UnimplementedError('toggleTorch() has not been implemented');
}
+ /// Set the method to be called when a barcode is detected
void setOnDetectHandler(void Function(Barcode) handler) {
throw UnimplementedError('setOnReadHandler() has not been implemented');
}
diff --git a/fast_barcode_scanner_platform_interface/lib/src/types/barcode.dart b/fast_barcode_scanner_platform_interface/lib/src/types/barcode.dart
index ab117c77..6fdfb48b 100644
--- a/fast_barcode_scanner_platform_interface/lib/src/types/barcode.dart
+++ b/fast_barcode_scanner_platform_interface/lib/src/types/barcode.dart
@@ -1,24 +1,22 @@
-import 'package:flutter/foundation.dart';
-
-import '../../fast_barcode_scanner_platform_interface.dart';
-
-/// Describes a Barcode with type and value.
-/// [Barcode] are equatable.
-class Barcode {
- /// Creates a [Barcode] from a Flutter Message Protocol
- Barcode(List data)
- : this.type =
- BarcodeType.values.firstWhere((e) => describeEnum(e) == data[0]),
- this.value = data[1];
-
- /// The type if the Barcode.
- ///
- /// Can be one of [BarcodeType] in [String] form.
- final BarcodeType type;
-
- /// The actual value of the barcode.
- final String value;
-
- bool operator ==(o) => o is Barcode && o.type == type && o.value == value;
- int get hashCode => super.hashCode ^ type.hashCode ^ value.hashCode;
-}
+import 'package:flutter/foundation.dart';
+
+import '../../fast_barcode_scanner_platform_interface.dart';
+
+/// Describes a Barcode with type and value.
+/// [Barcode] are equatable.
+class Barcode {
+ /// Creates a [Barcode] from a Flutter Message Protocol
+ Barcode(List data)
+ : this.type =
+ BarcodeType.values.firstWhere((e) => describeEnum(e) == data[0]),
+ this.value = data[1];
+
+ /// The type of the barcode.
+ final BarcodeType type;
+
+ /// The actual value of the barcode.
+ final String value;
+
+ bool operator ==(o) => o is Barcode && o.type == type && o.value == value;
+ int get hashCode => super.hashCode ^ type.hashCode ^ value.hashCode;
+}
diff --git a/fast_barcode_scanner_platform_interface/lib/src/types/preview_configuration.dart b/fast_barcode_scanner_platform_interface/lib/src/types/preview_configuration.dart
index b6654d5b..ff64042d 100644
--- a/fast_barcode_scanner_platform_interface/lib/src/types/preview_configuration.dart
+++ b/fast_barcode_scanner_platform_interface/lib/src/types/preview_configuration.dart
@@ -1,25 +1,29 @@
-/// Supported resolutions. Not all devices support all [Resolution]s!
+/// Supported resolutions. Not all devices support all resolutions!
enum Resolution { sd480, hd720, hd1080, hd4k }
-/// Supported Framerates. Not all devices support all [Framerate]s.
+/// Supported Framerates. Not all devices support all framerates!
enum Framerate { fps30, fps60, fps120, fps240 }
-/// Supported Detection modes.
-///
-/// - pauseDetection: Pauses the detection of further barcodes when a barcode is detected.
-/// - pauseVideo: Pauses the camera feed on detection.
-/// - continuous: Does nothing on detection. May need to throttle detections using this.
-enum DetectionMode { pauseDetection, pauseVideo, continuous }
+enum DetectionMode {
+ /// Pauses the detection of further barcodes when a barcode is detected.
+ pauseDetection,
+
+ /// Pauses the camera feed on detection.
+ pauseVideo,
+
+ /// Does nothing on detection. May need to throttle detections using continuous.
+ continuous
+}
/// The position of the camera.
enum CameraPosition { front, back }
-/// A OS-provided configuration by which the camera feed can be laid out in the UI.
+/// The configuration by which the camera feed can be laid out in the UI.
class PreviewConfiguration {
- /// The width of the camera feed in points or dp.
+ /// The width of the camera feed in points.
final int width;
- /// The height of the camera feed in points or db.
+ /// The height of the camera feed in points.
final int height;
/// The orientation of the camera feed.
diff --git a/fast_barcode_scanner_platform_interface/pubspec.lock b/fast_barcode_scanner_platform_interface/pubspec.lock
deleted file mode 100644
index 5b2addc5..00000000
--- a/fast_barcode_scanner_platform_interface/pubspec.lock
+++ /dev/null
@@ -1,308 +0,0 @@
-# Generated by pub
-# See https://dart.dev/tools/pub/glossary#lockfile
-packages:
- _fe_analyzer_shared:
- dependency: transitive
- description:
- name: _fe_analyzer_shared
- url: "https://pub.dartlang.org"
- source: hosted
- version: "17.0.0"
- analyzer:
- dependency: transitive
- description:
- name: analyzer
- url: "https://pub.dartlang.org"
- source: hosted
- version: "1.1.0"
- args:
- dependency: transitive
- description:
- name: args
- url: "https://pub.dartlang.org"
- source: hosted
- version: "2.0.0"
- async:
- dependency: transitive
- description:
- name: async
- url: "https://pub.dartlang.org"
- source: hosted
- version: "2.5.0"
- boolean_selector:
- dependency: transitive
- description:
- name: boolean_selector
- url: "https://pub.dartlang.org"
- source: hosted
- version: "2.1.0"
- build:
- dependency: transitive
- description:
- name: build
- url: "https://pub.dartlang.org"
- source: hosted
- version: "1.6.3"
- built_collection:
- dependency: transitive
- description:
- name: built_collection
- url: "https://pub.dartlang.org"
- source: hosted
- version: "5.0.0"
- built_value:
- dependency: transitive
- description:
- name: built_value
- url: "https://pub.dartlang.org"
- source: hosted
- version: "8.0.0"
- characters:
- dependency: transitive
- description:
- name: characters
- url: "https://pub.dartlang.org"
- source: hosted
- version: "1.1.0"
- charcode:
- dependency: transitive
- description:
- name: charcode
- url: "https://pub.dartlang.org"
- source: hosted
- version: "1.2.0"
- cli_util:
- dependency: transitive
- description:
- name: cli_util
- url: "https://pub.dartlang.org"
- source: hosted
- version: "0.3.0"
- clock:
- dependency: transitive
- description:
- name: clock
- url: "https://pub.dartlang.org"
- source: hosted
- version: "1.1.0"
- code_builder:
- dependency: transitive
- description:
- name: code_builder
- url: "https://pub.dartlang.org"
- source: hosted
- version: "3.6.0"
- collection:
- dependency: transitive
- description:
- name: collection
- url: "https://pub.dartlang.org"
- source: hosted
- version: "1.15.0"
- convert:
- dependency: transitive
- description:
- name: convert
- url: "https://pub.dartlang.org"
- source: hosted
- version: "3.0.0"
- crypto:
- dependency: transitive
- description:
- name: crypto
- url: "https://pub.dartlang.org"
- source: hosted
- version: "3.0.0"
- dart_style:
- dependency: transitive
- description:
- name: dart_style
- url: "https://pub.dartlang.org"
- source: hosted
- version: "1.3.14"
- fake_async:
- dependency: transitive
- description:
- name: fake_async
- url: "https://pub.dartlang.org"
- source: hosted
- version: "1.2.0"
- file:
- dependency: transitive
- description:
- name: file
- url: "https://pub.dartlang.org"
- source: hosted
- version: "6.1.0"
- fixnum:
- dependency: transitive
- description:
- name: fixnum
- url: "https://pub.dartlang.org"
- source: hosted
- version: "1.0.0"
- flutter:
- dependency: "direct main"
- description: flutter
- source: sdk
- version: "0.0.0"
- flutter_test:
- dependency: "direct dev"
- description: flutter
- source: sdk
- version: "0.0.0"
- glob:
- dependency: transitive
- description:
- name: glob
- url: "https://pub.dartlang.org"
- source: hosted
- version: "2.0.0"
- logging:
- dependency: transitive
- description:
- name: logging
- url: "https://pub.dartlang.org"
- source: hosted
- version: "1.0.0"
- matcher:
- dependency: transitive
- description:
- name: matcher
- url: "https://pub.dartlang.org"
- source: hosted
- version: "0.12.10"
- meta:
- dependency: transitive
- description:
- name: meta
- url: "https://pub.dartlang.org"
- source: hosted
- version: "1.3.0"
- mockito:
- dependency: "direct dev"
- description:
- name: mockito
- url: "https://pub.dartlang.org"
- source: hosted
- version: "5.0.0"
- package_config:
- dependency: transitive
- description:
- name: package_config
- url: "https://pub.dartlang.org"
- source: hosted
- version: "2.0.0"
- path:
- dependency: transitive
- description:
- name: path
- url: "https://pub.dartlang.org"
- source: hosted
- version: "1.8.0"
- pedantic:
- dependency: "direct dev"
- description:
- name: pedantic
- url: "https://pub.dartlang.org"
- source: hosted
- version: "1.11.0"
- plugin_platform_interface:
- dependency: "direct main"
- description:
- name: plugin_platform_interface
- url: "https://pub.dartlang.org"
- source: hosted
- version: "2.0.0"
- pub_semver:
- dependency: transitive
- description:
- name: pub_semver
- url: "https://pub.dartlang.org"
- source: hosted
- version: "2.0.0"
- sky_engine:
- dependency: transitive
- description: flutter
- source: sdk
- version: "0.0.99"
- source_gen:
- dependency: transitive
- description:
- name: source_gen
- url: "https://pub.dartlang.org"
- source: hosted
- version: "0.9.10+3"
- source_span:
- dependency: transitive
- description:
- name: source_span
- url: "https://pub.dartlang.org"
- source: hosted
- version: "1.8.0"
- stack_trace:
- dependency: transitive
- description:
- name: stack_trace
- url: "https://pub.dartlang.org"
- source: hosted
- version: "1.10.0"
- stream_channel:
- dependency: transitive
- description:
- name: stream_channel
- url: "https://pub.dartlang.org"
- source: hosted
- version: "2.1.0"
- string_scanner:
- dependency: transitive
- description:
- name: string_scanner
- url: "https://pub.dartlang.org"
- source: hosted
- version: "1.1.0"
- term_glyph:
- dependency: transitive
- description:
- name: term_glyph
- url: "https://pub.dartlang.org"
- source: hosted
- version: "1.2.0"
- test_api:
- dependency: transitive
- description:
- name: test_api
- url: "https://pub.dartlang.org"
- source: hosted
- version: "0.2.19"
- typed_data:
- dependency: transitive
- description:
- name: typed_data
- url: "https://pub.dartlang.org"
- source: hosted
- version: "1.3.0"
- vector_math:
- dependency: transitive
- description:
- name: vector_math
- url: "https://pub.dartlang.org"
- source: hosted
- version: "2.1.0"
- watcher:
- dependency: transitive
- description:
- name: watcher
- url: "https://pub.dartlang.org"
- source: hosted
- version: "1.0.0"
- yaml:
- dependency: transitive
- description:
- name: yaml
- url: "https://pub.dartlang.org"
- source: hosted
- version: "3.1.0"
-sdks:
- dart: ">=2.12.0 <3.0.0"
- flutter: ">=2.0.0"
diff --git a/fast_barcode_scanner_platform_interface/pubspec.yaml b/fast_barcode_scanner_platform_interface/pubspec.yaml
index cd1535a4..e1650591 100644
--- a/fast_barcode_scanner_platform_interface/pubspec.yaml
+++ b/fast_barcode_scanner_platform_interface/pubspec.yaml
@@ -1,22 +1,14 @@
name: fast_barcode_scanner_platform_interface
description: A common platform interface for the fast_barcode_scanner plugin.
homepage: https://github.com/jhoogstraat/fast_barcode_scanner/tree/master/fast_barcode_scanner_platform_interface
-author: Joshua Hoogstraat
-# NOTE: We strongly prefer non-breaking changes, even at the expense of a
-# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
-version: 0.0.1
+repository: https://github.com/jhoogstraat/fast_barcode_scanner
+version: 1.0.2
environment:
sdk: '>=2.12.0 <3.0.0'
- flutter: ">=2.0.0 < 3.0.0"
+ flutter: ">=2.0.0"
dependencies:
flutter:
sdk: flutter
- plugin_platform_interface: ^2.0.0
-
-dev_dependencies:
- flutter_test:
- sdk: flutter
- mockito: ^5.0.0
- pedantic: ^1.11.0
\ No newline at end of file
+ plugin_platform_interface: ^2.0.0
\ No newline at end of file
diff --git a/fast_barcode_scanner_platform_interface/test/method_channel_fast_barcode_scanner_test.dart b/fast_barcode_scanner_platform_interface/test/method_channel_fast_barcode_scanner_test.dart
index e8e06a61..8b137891 100644
--- a/fast_barcode_scanner_platform_interface/test/method_channel_fast_barcode_scanner_test.dart
+++ b/fast_barcode_scanner_platform_interface/test/method_channel_fast_barcode_scanner_test.dart
@@ -1,282 +1 @@
-import 'package:mockito/mockito.dart';
-import 'package:flutter/services.dart';
-import 'package:flutter_test/flutter_test.dart';
-import 'package:plugin_platform_interface/plugin_platform_interface.dart';
-// class UrlLauncherPlatformMock extends Mock
-// with MockPlatformInterfaceMixin
-// implements UrlLauncherPlatform {}
-
-// class ImplementsUrlLauncherPlatform extends Mock
-// implements UrlLauncherPlatform {}
-
-// class ExtendsUrlLauncherPlatform extends UrlLauncherPlatform {}
-
-void main() {
- TestWidgetsFlutterBinding.ensureInitialized();
-
- // group('$FastBarcodeScannerPlatform', () {
- // test('$MethodChannelUrlLauncher() is the default instance', () {
- // expect(UrlLauncherPlatform.instance,
- // isInstanceOf());
- // });
-
- // test('Cannot be implemented with `implements`', () {
- // expect(() {
- // UrlLauncherPlatform.instance = ImplementsUrlLauncherPlatform();
- // }, throwsA(isInstanceOf()));
- // });
-
- // test('Can be mocked with `implements`', () {
- // final UrlLauncherPlatformMock mock = UrlLauncherPlatformMock();
- // UrlLauncherPlatform.instance = mock;
- // });
-
- // test('Can be extended', () {
- // UrlLauncherPlatform.instance = ExtendsUrlLauncherPlatform();
- // });
- // });
-
- // group('$MethodChannelUrlLauncher', () {
- // const MethodChannel channel =
- // MethodChannel('plugins.flutter.io/url_launcher');
- // final List log = [];
- // channel.setMockMethodCallHandler((MethodCall methodCall) async {
- // log.add(methodCall);
- // });
-
- // final MethodChannelUrlLauncher launcher = MethodChannelUrlLauncher();
-
- // tearDown(() {
- // log.clear();
- // });
-
- // test('canLaunch', () async {
- // await launcher.canLaunch('http://example.com/');
- // expect(
- // log,
- // [
- // isMethodCall('canLaunch', arguments: {
- // 'url': 'http://example.com/',
- // })
- // ],
- // );
- // });
-
- // test('launch', () async {
- // await launcher.launch(
- // 'http://example.com/',
- // useSafariVC: true,
- // useWebView: false,
- // enableJavaScript: false,
- // enableDomStorage: false,
- // universalLinksOnly: false,
- // headers: const {},
- // );
- // expect(
- // log,
- // [
- // isMethodCall('launch', arguments: {
- // 'url': 'http://example.com/',
- // 'useSafariVC': true,
- // 'useWebView': false,
- // 'enableJavaScript': false,
- // 'enableDomStorage': false,
- // 'universalLinksOnly': false,
- // 'headers': {},
- // })
- // ],
- // );
- // });
-
- // test('launch with headers', () async {
- // await launcher.launch(
- // 'http://example.com/',
- // useSafariVC: true,
- // useWebView: false,
- // enableJavaScript: false,
- // enableDomStorage: false,
- // universalLinksOnly: false,
- // headers: const {'key': 'value'},
- // );
- // expect(
- // log,
- // [
- // isMethodCall('launch', arguments: {
- // 'url': 'http://example.com/',
- // 'useSafariVC': true,
- // 'useWebView': false,
- // 'enableJavaScript': false,
- // 'enableDomStorage': false,
- // 'universalLinksOnly': false,
- // 'headers': {'key': 'value'},
- // })
- // ],
- // );
- // });
-
- // test('launch force SafariVC', () async {
- // await launcher.launch(
- // 'http://example.com/',
- // useSafariVC: true,
- // useWebView: false,
- // enableJavaScript: false,
- // enableDomStorage: false,
- // universalLinksOnly: false,
- // headers: const {},
- // );
- // expect(
- // log,
- // [
- // isMethodCall('launch', arguments: {
- // 'url': 'http://example.com/',
- // 'useSafariVC': true,
- // 'useWebView': false,
- // 'enableJavaScript': false,
- // 'enableDomStorage': false,
- // 'universalLinksOnly': false,
- // 'headers': {},
- // })
- // ],
- // );
- // });
-
- // test('launch universal links only', () async {
- // await launcher.launch(
- // 'http://example.com/',
- // useSafariVC: false,
- // useWebView: false,
- // enableJavaScript: false,
- // enableDomStorage: false,
- // universalLinksOnly: true,
- // headers: const {},
- // );
- // expect(
- // log,
- // [
- // isMethodCall('launch', arguments: {
- // 'url': 'http://example.com/',
- // 'useSafariVC': false,
- // 'useWebView': false,
- // 'enableJavaScript': false,
- // 'enableDomStorage': false,
- // 'universalLinksOnly': true,
- // 'headers': {},
- // })
- // ],
- // );
- // });
-
- // test('launch force WebView', () async {
- // await launcher.launch(
- // 'http://example.com/',
- // useSafariVC: true,
- // useWebView: true,
- // enableJavaScript: false,
- // enableDomStorage: false,
- // universalLinksOnly: false,
- // headers: const {},
- // );
- // expect(
- // log,
- // [
- // isMethodCall('launch', arguments: {
- // 'url': 'http://example.com/',
- // 'useSafariVC': true,
- // 'useWebView': true,
- // 'enableJavaScript': false,
- // 'enableDomStorage': false,
- // 'universalLinksOnly': false,
- // 'headers': {},
- // })
- // ],
- // );
- // });
-
- // test('launch force WebView enable javascript', () async {
- // await launcher.launch(
- // 'http://example.com/',
- // useSafariVC: true,
- // useWebView: true,
- // enableJavaScript: true,
- // enableDomStorage: false,
- // universalLinksOnly: false,
- // headers: const {},
- // );
- // expect(
- // log,
- // [
- // isMethodCall('launch', arguments: {
- // 'url': 'http://example.com/',
- // 'useSafariVC': true,
- // 'useWebView': true,
- // 'enableJavaScript': true,
- // 'enableDomStorage': false,
- // 'universalLinksOnly': false,
- // 'headers': {},
- // })
- // ],
- // );
- // });
-
- // test('launch force WebView enable DOM storage', () async {
- // await launcher.launch(
- // 'http://example.com/',
- // useSafariVC: true,
- // useWebView: true,
- // enableJavaScript: false,
- // enableDomStorage: true,
- // universalLinksOnly: false,
- // headers: const {},
- // );
- // expect(
- // log,
- // [
- // isMethodCall('launch', arguments: {
- // 'url': 'http://example.com/',
- // 'useSafariVC': true,
- // 'useWebView': true,
- // 'enableJavaScript': false,
- // 'enableDomStorage': true,
- // 'universalLinksOnly': false,
- // 'headers': {},
- // })
- // ],
- // );
- // });
-
- // test('launch force SafariVC to false', () async {
- // await launcher.launch(
- // 'http://example.com/',
- // useSafariVC: false,
- // useWebView: false,
- // enableJavaScript: false,
- // enableDomStorage: false,
- // universalLinksOnly: false,
- // headers: const {},
- // );
- // expect(
- // log,
- // [
- // isMethodCall('launch', arguments: {
- // 'url': 'http://example.com/',
- // 'useSafariVC': false,
- // 'useWebView': false,
- // 'enableJavaScript': false,
- // 'enableDomStorage': false,
- // 'universalLinksOnly': false,
- // 'headers': {},
- // })
- // ],
- // );
- // });
-
- // test('closeWebView default behavior', () async {
- // await launcher.closeWebView();
- // expect(
- // log,
- // [isMethodCall('closeWebView', arguments: null)],
- // );
- // });
- // });
-}