Skip to content

Commit 2f84d34

Browse files
authored
Merge pull request #54 from yushulx/dev
Dev
2 parents f4cbb65 + f0eefcf commit 2f84d34

21 files changed

+207
-250
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 3.1.0
2+
* Added a `rotation` parameter to `decodeImageBuffer()` method.
3+
14
## 3.0.5
25
* Added `errorCode` and `errorMsg` properties to `BarcodeResult`.
36
* Removed support for the macOS plugin.

README.md

Lines changed: 27 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,27 @@
11
# flutter_barcode_sdk
22
![pub.dev](https://img.shields.io/pub/v/flutter_barcode_sdk.svg)
33

4-
The **Flutter Barcode SDK** is a wrapper for the [Dynamsoft Barcode Reader SDK](https://www.dynamsoft.com/barcode-reader/overview/). It supports multiple platforms, including **Android**, **iOS**, **Web**, **Windows**, and **Linux**, and can decode various barcode types such as linear barcodes, QR Code, DataMatrix, MaxiCode, PDF417, and more. This SDK encapsulates the low-level decoding functions of the Dynamsoft Barcode Reader, enabling both file and image buffer decoding. It empowers developers to effortlessly build 1D/2D barcode readers and scanners. The project is actively maintained by community contributors.
4+
The **Flutter Barcode SDK** is a wrapper for the [Dynamsoft Barcode Reader SDK](https://www.dynamsoft.com/barcode-reader/overview/). It supports multiple platforms, including **Android**, **iOS**, **Web**, **Windows**, and **Linux**, and can decode a wide range of barcode types such as **linear barcodes**, **QR Code**, **DataMatrix**, **MaxiCode**, **PDF417**, and more. This SDK encapsulates the low-level decoding capabilities of the Dynamsoft Barcode Reader, enabling barcode decoding from both **files and image buffers**. With this package, developers can effortlessly build robust **1D/2D barcode reader** and **scanner** apps. The project is actively maintained with contributions from the community.
55

6-
> **Note:** For live camera scenarios, it is recommended to use the official [Dynamsoft Capture Vision Flutter Edition](https://pub.dev/packages/dynamsoft_capture_vision_flutter), as it offers better performance than combining the [Flutter camera plugin](https://pub.dev/packages/camera) with the Flutter Barcode SDK.
6+
> **Note:** For live camera scenarios, it is recommended to use the official [Dynamsoft Capture Vision Flutter Edition](https://pub.dev/packages/dynamsoft_capture_vision_flutter), which offers better performance than combining the [Flutter camera plugin](https://pub.dev/packages/camera) with the Flutter Barcode SDK.
77
88
## **Table of Contents**
99
1. [Getting a License Key](#getting-a-license-key)
1010
2. [Supported Platforms](#supported-platforms)
1111
3. [Supported Barcode Symbologies](#supported-barcode-symbologies)
1212
4. [Build Configuration](#build-configuration)
13-
5. [API Compatibility](#api-compatibility)
14-
6. [Usage](#usage)
15-
7. [Examples](#try-barcode-decoding-example)
13+
5. [API Reference](#api-reference)
14+
6. [Examples](#try-barcode-decoding-example)
1615

1716
## **Getting a License Key**
1817
[![](https://img.shields.io/badge/Get-30--day%20FREE%20Trial-blue)](https://www.dynamsoft.com/customer/license/trialLicense/?product=dcv&package=cross-platform)
1918

2019
## **Supported Platforms**
21-
- **Android**
22-
- **iOS**
23-
- **Windows**
24-
- **Linux**
25-
- **Web**
20+
- **Android**
21+
- **iOS**
22+
- **Windows**
23+
- **Linux**
24+
- **Web**
2625

2726
## **Supported Barcode Symbologies**
2827
### **Linear Barcodes (1D)**
@@ -71,16 +70,14 @@ minSdkVersion 21
7170
```
7271

7372
### iOS
74-
- Add camera usage descriptions to `ios/Runner/Info.plist`:
73+
Add camera usage descriptions to `ios/Runner/Info.plist`:
7574

76-
```xml
77-
<key>NSCameraUsageDescription</key>
78-
<string>Can I use the camera please?</string>
79-
<key>NSMicrophoneUsageDescription</key>
80-
<string>Can I use the mic please?</string>
81-
```
82-
83-
- Minimum deployment target: iOS 13.0 or later
75+
```xml
76+
<key>NSCameraUsageDescription</key>
77+
<string>Can I use the camera please?</string>
78+
<key>NSMicrophoneUsageDescription</key>
79+
<string>Can I use the mic please?</string>
80+
```
8481

8582
### Desktop
8683

@@ -96,68 +93,17 @@ In `index.html`, include:
9693
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/dcv.bundle.min.js"></script>
9794
```
9895

99-
## **API Compatibility**
100-
| Methods | Android | iOS | Windows | Linux | Web|
101-
| ----------- | ----------- | ----------- | ----------- |----------- |----------- |
102-
| `Future<void> setLicense(String license) async` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |:heavy_check_mark: |
103-
| `Future<List<BarcodeResult>> decodeFile(String filename) async` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |:heavy_check_mark: | :heavy_check_mark: |
104-
| `Future<List<BarcodeResult>> decodeImageBuffer(Uint8List bytes, int width, int height, int stride, int format) async` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |:heavy_check_mark: |
105-
| `Future<int> setBarcodeFormats(int formats) async` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |:heavy_check_mark: | :heavy_check_mark: |
106-
| `Future<String> getParameters() async` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |:heavy_check_mark: |
107-
| `Future<int> setParameters(String params)` async | :heavy_check_mark: |:heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |:heavy_check_mark: | :heavy_check_mark: |
108-
| `Future<void> init()` async | :heavy_check_mark: |:heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |:heavy_check_mark: |
109-
110-
## **Usage**
111-
- Initialize Flutter barcode SDK and set the license key:
112-
113-
```dart
114-
_barcodeReader = FlutterBarcodeSdk();
115-
await _barcodeReader.setLicense('LICENSE-KEY');
116-
await _barcodeReader.init();
117-
```
118-
119-
- Read barcodes from an image file:
120-
121-
```dart
122-
List<BarcodeResult> results = await _barcodeReader.decodeFile(image-path);
123-
```
124-
125-
- Read barcodes from an image buffer:
126-
127-
128-
```dart
129-
import 'dart:ui' as ui;
130-
Uint8List fileBytes = await file.readAsBytes();
131-
ui.Image image = await decodeImageFromList(fileBytes);
132-
133-
ByteData byteData = await image.toByteData(
134-
format: ui.ImageByteFormat.rawRgba);
135-
List<BarcodeResult> results =
136-
await _barcodeReader.decodeImageBuffer(
137-
byteData.buffer.asUint8List(),
138-
image.width,
139-
image.height,
140-
byteData.lengthInBytes ~/ image.height,
141-
ImagePixelFormat.IPF_ARGB_8888.index);
142-
```
143-
144-
- Set barcode formats:
145-
146-
```dart
147-
int ret = await _barcodeReader.setBarcodeFormats(BarcodeFormat.CODE_39 | BarcodeFormat.CODABAR | BarcodeFormat.QR_CODE | BarcodeFormat.DATAMATRIX);
148-
```
149-
150-
- Get current barcode detection parameters:
151-
152-
```dart
153-
String params = await _barcodeReader.getParameters();
154-
```
155-
156-
- Set barcode detection parameters:
157-
158-
```dart
159-
int ret = await _barcodeReader.setParameters(params);
160-
```
96+
## API Reference
97+
| Method | Description | Parameters | Return Type |
98+
| ----------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------- |
99+
| `Future<int> setLicense(String license)` | Sets the Dynamsoft Barcode Reader license key. | `license`: The license key string. | `Future<int>` |
100+
| `Future<int> init()` | Initializes the barcode reader and applies default parameters for the current platform. || `Future<int>` |
101+
| `Future<List<BarcodeResult>> decodeFile(String filename)` | Decodes barcodes from an image file. | `filename`: Path to the image file. | `Future<List<BarcodeResult>>` |
102+
| `Future<List<BarcodeResult>> decodeImageBuffer(Uint8List bytes, int width, int height, int stride, int format, int rotation)` | Decodes barcodes from a raw image buffer (for real-time or camera preview scanning). | `bytes`: Image buffer (raw bytes)<br>`width`: Image width<br>`height`: Image height<br>`stride`: Bytes per row<br>`format`: Pixel format (see `ImagePixelFormat`)<br>`rotation`: 0/90/180/270 | `Future<List<BarcodeResult>>` |
103+
| `Future<int> setBarcodeFormats(int formats)` | Sets the barcode formats to be detected. | `formats`: Bitwise combination of barcode formats (see `BarcodeFormat`). | `Future<int>` |
104+
| `Future<String> getParameters()` | Retrieves the current barcode detection settings as a JSON string. || `Future<String>` |
105+
| `Future<int> setParameters(String params)` | Updates barcode detection parameters with a JSON string. | `params`: JSON string of detection parameters. | `Future<int>` |
106+
161107

162108

163109
## Try Barcode Reader & Scanner Examples

android/src/main/java/com/dynamsoft/flutter_barcode_sdk/BarcodeManager.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public List<Map<String, Object>> decodeFileBytes(byte[] bytes) {
134134
return ret;
135135
}
136136

137-
public List<Map<String, Object>> decodeImageBuffer(byte[] bytes, int width, int height, int stride, int format) {
137+
public List<Map<String, Object>> decodeImageBuffer(byte[] bytes, int width, int height, int stride, int format, int rotation) {
138138
List<Map<String, Object>> ret = new ArrayList<Map<String, Object>>();
139139
try {
140140
ImageData imageData = new ImageData();
@@ -143,6 +143,7 @@ public List<Map<String, Object>> decodeImageBuffer(byte[] bytes, int width, int
143143
imageData.height = height;
144144
imageData.stride = stride;
145145
imageData.format = format;
146+
imageData.orientation = rotation;
146147
CapturedResult results = mRouter.capture(imageData, "");
147148
int errorCode = results.getErrorCode();
148149
String errorMsg = results.getErrorMessage();

android/src/main/java/com/dynamsoft/flutter_barcode_sdk/FlutterBarcodeSdkPlugin.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,12 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
7979
final int height = call.argument("height");
8080
final int stride = call.argument("stride");
8181
final int format = call.argument("format");
82+
final int rotation = call.argument("rotation");
8283
final Result r = result;
8384
mExecutor.execute(new Runnable() {
8485
@Override
8586
public void run() {
86-
final List<Map<String, Object>> results = mBarcodeManager.decodeImageBuffer(bytes, width, height, stride, format);
87+
final List<Map<String, Object>> results = mBarcodeManager.decodeImageBuffer(bytes, width, height, stride, format, rotation);
8788
mHandler.post(new Runnable() {
8889
@Override
8990
public void run() {

example/ios/Podfile.lock

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ PODS:
44
- DynamsoftBarcodeReaderBundle (11.0.3000):
55
- DynamsoftCaptureVisionBundle (= 3.0.3000)
66
- DynamsoftCaptureVisionBundle (3.0.3000)
7-
- file_selector_ios (0.0.1):
8-
- Flutter
97
- Flutter (1.0.0)
108
- flutter_barcode_sdk (3.0.0):
119
- DynamsoftBarcodeReaderBundle (= 11.0.3000)
@@ -18,7 +16,6 @@ PODS:
1816

1917
DEPENDENCIES:
2018
- camera_avfoundation (from `.symlinks/plugins/camera_avfoundation/ios`)
21-
- file_selector_ios (from `.symlinks/plugins/file_selector_ios/ios`)
2219
- Flutter (from `Flutter`)
2320
- flutter_barcode_sdk (from `.symlinks/plugins/flutter_barcode_sdk/ios`)
2421
- image_picker_ios (from `.symlinks/plugins/image_picker_ios/ios`)
@@ -32,8 +29,6 @@ SPEC REPOS:
3229
EXTERNAL SOURCES:
3330
camera_avfoundation:
3431
:path: ".symlinks/plugins/camera_avfoundation/ios"
35-
file_selector_ios:
36-
:path: ".symlinks/plugins/file_selector_ios/ios"
3732
Flutter:
3833
:path: Flutter
3934
flutter_barcode_sdk:
@@ -47,7 +42,6 @@ SPEC CHECKSUMS:
4742
camera_avfoundation: be3be85408cd4126f250386828e9b1dfa40ab436
4843
DynamsoftBarcodeReaderBundle: 578c27daeda029a5a5aeb0fdda63dddb3fc5fc29
4944
DynamsoftCaptureVisionBundle: 1935e3efc70db1b7c6cab19dfe420c3e43dbe1a0
50-
file_selector_ios: f92e583d43608aebc2e4a18daac30b8902845502
5145
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
5246
flutter_barcode_sdk: 82cec9bdb0d4e88b81c4ff1351a82dda6a9f9acb
5347
image_picker_ios: 7fe1ff8e34c1790d6fff70a32484959f563a928a

example/lib/desktop.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,12 @@ class _DesktopState extends State<Desktop> {
137137

138138
isDecoding = true;
139139
_barcodeResultsList = await _barcodeReader.decodeImageBuffer(
140-
rgb,
141-
width,
142-
height,
143-
width * 3,
144-
ImagePixelFormat.IPF_RGB_888.index,
145-
);
140+
rgb,
141+
width,
142+
height,
143+
width * 3,
144+
ImagePixelFormat.IPF_RGB_888.index,
145+
ImageRotation.rotation0.value);
146146

147147
// _barcodeResults = getBarcodeResults(_barcodeResultsList);
148148

example/lib/mobile.dart

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,14 @@ class MobileState extends State<Mobile> with WidgetsBindingObserver {
137137
defaultTargetPlatform == TargetPlatform.iOS);
138138
int format = ImagePixelFormat.IPF_NV21.index;
139139

140+
int rotation = 0;
141+
if (MediaQuery.of(context).size.width <
142+
MediaQuery.of(context).size.height) {
143+
if (Platform.isAndroid) {
144+
rotation = ImageRotation.rotation90.value;
145+
}
146+
}
147+
140148
switch (availableImage.format.group) {
141149
case ImageFormatGroup.yuv420:
142150
format = ImagePixelFormat.IPF_NV21.index;
@@ -160,13 +168,14 @@ class MobileState extends State<Mobile> with WidgetsBindingObserver {
160168
availableImage.width,
161169
availableImage.height,
162170
availableImage.planes[0].bytesPerRow,
163-
format)
171+
format,
172+
rotation)
164173
.then((results) {
165174
if (_isScanRunning) {
166175
_results = results;
167-
if (Platform.isAndroid && results.isNotEmpty) {
168-
_results = rotate90barcode(_results, _previewSize.height.toInt());
169-
}
176+
// if (Platform.isAndroid && results.isNotEmpty) {
177+
// _results = rotate90barcode(_results, _previewSize_previewSize.height.toInt());
178+
// }
170179
setState(() {});
171180
}
172181

@@ -237,8 +246,14 @@ class MobileState extends State<Mobile> with WidgetsBindingObserver {
237246
'images/default.png',
238247
)
239248
: SizedBox(
240-
width: _previewSize.height,
241-
height: _previewSize.width,
249+
width: MediaQuery.of(context).size.width <
250+
MediaQuery.of(context).size.height
251+
? _previewSize.height
252+
: _previewSize.width,
253+
height: MediaQuery.of(context).size.width <
254+
MediaQuery.of(context).size.height
255+
? _previewSize.width
256+
: _previewSize.height,
242257
child: CameraPreview(
243258
_controller!,
244259
)),

example/lib/web.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ class _WebState extends State<Web> {
102102
image.width,
103103
image.height,
104104
byteData.lengthInBytes ~/ image.height,
105-
ImagePixelFormat.IPF_ARGB_8888.index);
105+
ImagePixelFormat.IPF_ARGB_8888.index,
106+
ImageRotation.rotation0.value);
106107
}
107108

108109
updateResults(_barcodeResultsList);

example/macos/Flutter/GeneratedPluginRegistrant.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@ import FlutterMacOS
66
import Foundation
77

88
import file_selector_macos
9-
import flutter_barcode_sdk
109
import flutter_lite_camera
1110
import path_provider_foundation
1211

1312
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
1413
FileSelectorPlugin.register(with: registry.registrar(forPlugin: "FileSelectorPlugin"))
15-
FlutterBarcodeSdkPlugin.register(with: registry.registrar(forPlugin: "FlutterBarcodeSdkPlugin"))
1614
FlutterLiteCameraPlugin.register(with: registry.registrar(forPlugin: "FlutterLiteCameraPlugin"))
1715
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
1816
}

0 commit comments

Comments
 (0)