Skip to content

Commit 3fe9c10

Browse files
committed
1.4.3
1 parent f72dafa commit 3fe9c10

File tree

7 files changed

+57
-25
lines changed

7 files changed

+57
-25
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
## 1.4.3
2+
- add ios decode bar code
13
## 1.4.2
24
- fix
35
## 1.4.1

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# scan
22

3-
[![scan](https://img.shields.io/badge/pub-1.4.2-orange)](https://pub.dev/packages/scan)
3+
[![scan](https://img.shields.io/badge/pub-1.4.3-orange)](https://pub.dev/packages/scan)
44

5-
scan qrcode in widget tree.
5+
scan qrcode & barcode in widget tree.
66

7-
decode qrcode image from path.
7+
decode qrcode & barcode image from path.
88

99
> if you want to generate qrcode image, you should use [qr_flutter](https://pub.dev/packages/qr_flutter)
1010

example/ios/Podfile.lock

+6-12
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
PODS:
22
- Flutter (1.0.0)
3-
- image_picker (0.0.1):
4-
- Flutter
53
- images_picker (0.0.1):
64
- Flutter
7-
- ZLPhotoBrowser (= 4.1.3)
5+
- ZLPhotoBrowser (= 4.1.5)
86
- scan (0.0.1):
97
- Flutter
10-
- ZLPhotoBrowser (4.1.3):
11-
- ZLPhotoBrowser/Core (= 4.1.3)
12-
- ZLPhotoBrowser/Core (4.1.3)
8+
- ZLPhotoBrowser (4.1.5):
9+
- ZLPhotoBrowser/Core (= 4.1.5)
10+
- ZLPhotoBrowser/Core (4.1.5)
1311

1412
DEPENDENCIES:
1513
- Flutter (from `Flutter`)
16-
- image_picker (from `.symlinks/plugins/image_picker/ios`)
1714
- images_picker (from `.symlinks/plugins/images_picker/ios`)
1815
- scan (from `.symlinks/plugins/scan/ios`)
1916

@@ -24,19 +21,16 @@ SPEC REPOS:
2421
EXTERNAL SOURCES:
2522
Flutter:
2623
:path: Flutter
27-
image_picker:
28-
:path: ".symlinks/plugins/image_picker/ios"
2924
images_picker:
3025
:path: ".symlinks/plugins/images_picker/ios"
3126
scan:
3227
:path: ".symlinks/plugins/scan/ios"
3328

3429
SPEC CHECKSUMS:
3530
Flutter: 434fef37c0980e73bb6479ef766c45957d4b510c
36-
image_picker: 50e7c7ff960e5f58faa4d1f4af84a771c671bc4a
37-
images_picker: eb05ebd660218fba40842f7d26bc75d946c682e5
31+
images_picker: 634f7663456c00364e7d1a16116c2cc2562ff50f
3832
scan: aea35bb4aa59ccc8839c576a18cd57c7d492cc86
39-
ZLPhotoBrowser: 559062abac47b41ef140cff6ea2370e73623b05f
33+
ZLPhotoBrowser: 809878607ea92e9411c580797ce1be23896b8d7f
4034

4135
PODFILE CHECKSUM: aafe91acc616949ddb318b77800a7f51bffa2a4c
4236

example/lib/main.dart

+6-2
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,12 @@ class _MyAppState extends State<MyApp> {
7777
onPressed: () async {
7878
List<Media>? res = await ImagesPicker.pick();
7979
if (res != null) {
80-
String? qrcode = await Scan.parse(res[0].path!);
81-
print(qrcode);
80+
String? str = await Scan.parse(res[0].path!);
81+
if (str != null) {
82+
setState(() {
83+
qrcode = str;
84+
});
85+
}
8286
}
8387
},
8488
),

example/pubspec.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ packages:
9494
path: ".."
9595
relative: true
9696
source: path
97-
version: "1.4.1"
97+
version: "1.4.3"
9898
sky_engine:
9999
dependency: transitive
100100
description: flutter

ios/Classes/SwiftScanPlugin.swift

+36-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Flutter
22
import UIKit
3+
import Vision
34

45
public class SwiftScanPlugin: NSObject, FlutterPlugin {
56
public static func register(with registrar: FlutterPluginRegistrar) {
@@ -16,11 +17,10 @@ public class SwiftScanPlugin: NSObject, FlutterPlugin {
1617
} else if call.method=="parse" {
1718
let path = call.arguments as! String;
1819
if let features = self.detectQRCode(UIImage.init(contentsOfFile: path)), !features.isEmpty {
19-
for case let row as CIQRCodeFeature in features{
20-
result(row.messageString);
21-
}
20+
let data = features.first as! CIQRCodeFeature
21+
result(data.messageString);
2222
} else {
23-
result(nil);
23+
self.detectBarCode(UIImage.init(contentsOfFile: path), result: result)
2424
}
2525
}
2626
}
@@ -41,4 +41,36 @@ public class SwiftScanPlugin: NSObject, FlutterPlugin {
4141
}
4242
return nil
4343
}
44+
45+
private func detectBarCode(_ image: UIImage?, result: @escaping FlutterResult) {
46+
if let image = image, let ciImage = CIImage.init(image: image), #available(iOS 11.0, *) {
47+
var requestHandler: VNImageRequestHandler;
48+
if ciImage.properties.keys.contains((kCGImagePropertyOrientation as String)) {
49+
requestHandler = VNImageRequestHandler(ciImage: ciImage, orientation: CGImagePropertyOrientation(rawValue: ciImage.properties[(kCGImagePropertyOrientation as String)] as! UInt32) ?? .up, options: [:])
50+
} else {
51+
requestHandler = VNImageRequestHandler(ciImage: ciImage, orientation: .up, options: [:])
52+
}
53+
let request = VNDetectBarcodesRequest { (request,error) in
54+
var res: String? = nil;
55+
if let observations = request.results as? [VNBarcodeObservation], !observations.isEmpty {
56+
let data: VNBarcodeObservation = observations.first!;
57+
res = data.payloadStringValue;
58+
}
59+
DispatchQueue.main.async {
60+
result(res);
61+
}
62+
}
63+
DispatchQueue.global(qos: .background).async {
64+
do{
65+
try requestHandler.perform([request])
66+
} catch {
67+
DispatchQueue.main.async {
68+
result(nil);
69+
}
70+
}
71+
}
72+
} else {
73+
result(nil);
74+
}
75+
}
4476
}

pubspec.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: scan
2-
description: scan qrcode in widget tree with custom options.Accurately decode qrcode image from path.
3-
version: 1.4.2
4-
homepage: https://github.com/chavesgu/FlutterScan
2+
description: scan qrcode & barcode in widget tree with custom options.Accurately decode qrcode & barcode image from path.
3+
version: 1.4.3
4+
homepage: https://github.com/flutter-package/flutter_scan
55

66
environment:
77
sdk: ">=2.12.0 <3.0.0"

0 commit comments

Comments
 (0)