Skip to content

Commit f4cbb65

Browse files
authored
Merge pull request #53 from yushulx/dev
Dev
2 parents 2ec9a62 + 443a118 commit f4cbb65

File tree

17 files changed

+1451
-334
lines changed

17 files changed

+1451
-334
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 3.0.5
2+
* Added `errorCode` and `errorMsg` properties to `BarcodeResult`.
3+
* Removed support for the macOS plugin.
4+
15
## 3.0.4
26
* Updated SDKs for Android and iOS.
37

README.md

Lines changed: 14 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
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**, **Linux** and **macOS**, 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 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.
55

66
> **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.
77
@@ -22,7 +22,6 @@ The **Flutter Barcode SDK** is a wrapper for the [Dynamsoft Barcode Reader SDK](
2222
- **iOS**
2323
- **Windows**
2424
- **Linux**
25-
- **macOS**
2625
- **Web**
2726

2827
## **Supported Barcode Symbologies**
@@ -89,36 +88,6 @@ minSdkVersion 21
8988

9089
Install `CMake` and `platform-specific C++ compiler`.
9190

92-
**macOS**
93-
94-
Install `Xcode`.
95-
96-
To make the demo app work on macOS:
97-
- Disable `com.apple.security.app-sandbox` and enable `com.apple.security.files.user-selected.read-write` in `example/macos/Runner/DebugProfile.entitlements`:
98-
99-
```xml
100-
<?xml version="1.0" encoding="UTF-8"?>
101-
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
102-
<plist version="1.0">
103-
<dict>
104-
<key>com.apple.security.app-sandbox</key>
105-
<false/>
106-
<key>com.apple.security.cs.allow-jit</key>
107-
<true/>
108-
<key>com.apple.security.network.server</key>
109-
<true/>
110-
<key>com.apple.security.files.user-selected.read-write</key>
111-
<true/>
112-
</dict>
113-
</plist>
114-
```
115-
116-
- If `DCV` package is not found, run the command:
117-
118-
```bash
119-
pod repo add master https://github.com/CocoaPods/Specs
120-
```
121-
The command manually adds the CocoaPods `master` spec repository to the local machine to resolve the issue.
12291

12392
### Web
12493
In `index.html`, include:
@@ -128,15 +97,15 @@ In `index.html`, include:
12897
```
12998

13099
## **API Compatibility**
131-
| Methods | Android | iOS | Windows | Linux | macOS | Web|
132-
| ----------- | ----------- | ----------- | ----------- |----------- |----------- |----------- |
133-
| `Future<void> setLicense(String license) async` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |:heavy_check_mark: | :heavy_check_mark: |
134-
| `Future<List<BarcodeResult>> decodeFile(String filename) async` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |:heavy_check_mark: | :heavy_check_mark: |:heavy_check_mark: |
135-
| `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: |:heavy_check_mark: |
136-
| `Future<int> setBarcodeFormats(int formats) async` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |:heavy_check_mark: | :heavy_check_mark: |
137-
| `Future<String> getParameters() async` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |:heavy_check_mark: | :heavy_check_mark: |
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: |
138107
| `Future<int> setParameters(String params)` async | :heavy_check_mark: |:heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |:heavy_check_mark: | :heavy_check_mark: |
139-
| `Future<void> init()` 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: |
140109

141110
## **Usage**
142111
- Initialize Flutter barcode SDK and set the license key:
@@ -191,14 +160,14 @@ In `index.html`, include:
191160
```
192161

193162

194-
## **Try Barcode Decoding Example**
163+
## Try Barcode Reader & Scanner Examples
195164

196165
### Android/iOS
197166
The example demonstrates how to use the Flutter Barcode SDK to read barcodes from an image file and decode the barcode image buffer from the camera stream on Android and iOS.
198167

199168
```
200169
cd example
201-
flutter run -d <device>
170+
flutter run
202171
```
203172

204173
- **Barcode Scanner**
@@ -210,8 +179,8 @@ flutter run -d <device>
210179
![flutter barcode reader](https://www.dynamsoft.com/codepool/img/2025/01/flutter-android-barcode-image-detection.jpg)
211180

212181

213-
### Windows, Linux and macOS
214-
Run the desktop barcode reader and scanner application on Windows, Linux or macOS:
182+
### Windows & Linux
183+
Run the desktop barcode reader and scanner application on Windows or Linux:
215184

216185
```bash
217186
cd example
@@ -220,21 +189,10 @@ flutter run -d windows
220189

221190
# Linux
222191
flutter run -d linux
223-
224-
# macOS
225-
flutter run -d macos
226192
```
227193

228-
- **Barcode Reader**
229-
230-
![flutter desktop barcode reader](https://www.dynamsoft.com/codepool/img/2025/01/flutter-barcode-reader-windows-linux-macos.png)
231-
232-
- **Barcode Scanner**
233-
234-
![flutter desktop barcode scanner](https://www.dynamsoft.com/codepool/img/2025/01/flutter-barcode-scanner-windows-linux-macos.png)
235-
236194

237-
### Web Browser
195+
### Web Barcode Scanner
238196

239197
```bash
240198
cd example

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

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import android.graphics.BitmapFactory;
66
import android.graphics.Point;
77

8+
import com.dynamsoft.core.basic_structures.EnumCapturedResultItemType;
89
import com.dynamsoft.cvr.CapturedResult;
910
import com.dynamsoft.core.basic_structures.CapturedResultItem;
1011
import com.dynamsoft.cvr.CaptureVisionRouter;
@@ -24,10 +25,29 @@ public class BarcodeManager {
2425
private static final String TAG = "DynamsoftBarcodeReader";
2526
private CaptureVisionRouter mRouter;
2627

28+
private void wrapError(List<Map<String, Object>> out, int errorCode, String errorMsg) {
29+
Map<String, Object> data = new HashMap<>();
30+
data.put("format", "");
31+
data.put("text", "");
32+
data.put("x1", 0);
33+
data.put("y1", 0);
34+
data.put("x2", 0);
35+
data.put("y2", 0);
36+
data.put("x3", 0);
37+
data.put("y3", 0);
38+
data.put("x4", 0);
39+
data.put("y4", 0);
40+
data.put("angle", 0);
41+
data.put("barcodeBytes", new byte[0]);
42+
data.put("errorCode", errorCode);
43+
data.put("errorMsg", errorMsg);
44+
out.add(data);
45+
}
2746

2847
private void wrapResults(CapturedResult result, List<Map<String, Object>> out) {
2948
CapturedResultItem[] items = result.getItems();
3049
for (CapturedResultItem item : items) {
50+
if (item.getType() != EnumCapturedResultItemType.CRIT_BARCODE) continue;
3151
Map<String, Object> data = new HashMap<>();
3252
BarcodeResultItem barcodeItem = (BarcodeResultItem)item;
3353
data.put("format", barcodeItem.getFormatString());
@@ -43,6 +63,8 @@ private void wrapResults(CapturedResult result, List<Map<String, Object>> out) {
4363
data.put("y4", points[3].y);
4464
data.put("angle", barcodeItem.getAngle());
4565
data.put("barcodeBytes", barcodeItem.getBytes());
66+
data.put("errorCode", 0);
67+
data.put("errorMsg", "");
4668
out.add(data);
4769
}
4870
}
@@ -75,7 +97,16 @@ public List<Map<String, Object>> decodeFile(String filename) {
7597
List<Map<String, Object>> ret = new ArrayList<Map<String, Object>>();
7698
try {
7799
CapturedResult results = mRouter.capture(filename, "");
78-
wrapResults(results, ret);
100+
int errorCode = results.getErrorCode();
101+
String errorMsg = results.getErrorMessage();
102+
103+
if (errorCode != 0) {
104+
wrapError(ret, errorCode, errorMsg);
105+
}
106+
else {
107+
wrapResults(results, ret);
108+
}
109+
79110
} catch (Exception e) {
80111
e.printStackTrace();
81112
}
@@ -88,7 +119,15 @@ public List<Map<String, Object>> decodeFileBytes(byte[] bytes) {
88119
Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes != null ? bytes.length : 0);
89120
try {
90121
CapturedResult results = mRouter.capture(bitmap, "");
91-
wrapResults(results, ret);
122+
int errorCode = results.getErrorCode();
123+
String errorMsg = results.getErrorMessage();
124+
125+
if (errorCode != 0) {
126+
wrapError(ret, errorCode, errorMsg);
127+
}
128+
else {
129+
wrapResults(results, ret);
130+
}
92131
} catch (Exception e) {
93132
e.printStackTrace();
94133
}
@@ -105,7 +144,15 @@ public List<Map<String, Object>> decodeImageBuffer(byte[] bytes, int width, int
105144
imageData.stride = stride;
106145
imageData.format = format;
107146
CapturedResult results = mRouter.capture(imageData, "");
108-
wrapResults(results, ret);
147+
int errorCode = results.getErrorCode();
148+
String errorMsg = results.getErrorMessage();
149+
150+
if (errorCode != 0) {
151+
wrapError(ret, errorCode, errorMsg);
152+
}
153+
else {
154+
wrapResults(results, ret);
155+
}
109156
} catch (Exception e) {
110157
e.printStackTrace();
111158
}
@@ -115,8 +162,11 @@ public List<Map<String, Object>> decodeImageBuffer(byte[] bytes, int width, int
115162
public int setBarcodeFormats(int formats) {
116163
try {
117164
SimplifiedCaptureVisionSettings settings = mRouter.getSimplifiedSettings("");
118-
settings.barcodeSettings.barcodeFormatIds = formats;
119-
mRouter.updateSettings("", settings);
165+
if (settings.barcodeSettings != null) {
166+
settings.barcodeSettings.barcodeFormatIds = formats;
167+
mRouter.updateSettings("", settings);
168+
}
169+
120170
return 0;
121171
} catch (Exception e) {
122172
e.printStackTrace();

example/lib/mobile.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ class MobileState extends State<Mobile> with WidgetsBindingObserver {
101101
int y2 = result.y2;
102102
int y3 = result.y3;
103103
int y4 = result.y4;
104+
int errorCode = result.errorCode;
105+
String errorMsg = result.errorMsg;
104106

105107
BarcodeResult newResult = BarcodeResult(
106108
result.format,
@@ -114,7 +116,9 @@ class MobileState extends State<Mobile> with WidgetsBindingObserver {
114116
height - y4,
115117
x4,
116118
result.angle,
117-
result.barcodeBytes);
119+
result.barcodeBytes,
120+
errorCode,
121+
errorMsg);
118122

119123
output.add(newResult);
120124
}

example/lib/overlay_painter.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class OverlayPainter extends CustomPainter {
2020
..style = PaintingStyle.stroke;
2121

2222
for (var result in results) {
23+
print(result.toJson());
2324
double minX = result.x1.toDouble();
2425
double minY = result.y1.toDouble();
2526
if (result.x2 < minX) minX = result.x2.toDouble();

0 commit comments

Comments
 (0)