result.dart
2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import 'dart:js_interop';
import 'dart:typed_data';
import 'dart:ui';
import 'package:mobile_scanner/src/enums/barcode_format.dart';
import 'package:mobile_scanner/src/enums/barcode_type.dart';
import 'package:mobile_scanner/src/objects/barcode.dart';
import 'package:mobile_scanner/src/web/zxing/result_point.dart';
/// The JS static interop class for the Result class in the ZXing library.
///
/// See also: https://github.com/zxing-js/library/blob/master/src/core/Result.ts
extension type Result(JSObject _) implements JSObject {
@JS('barcodeFormat')
external int? get _barcodeFormat;
/// Get the text of the result.
external String? get text;
@JS('rawBytes')
external JSUint8Array? get _rawBytes;
@JS('resultPoints')
external JSArray<ResultPoint>? get _resultPoints;
/// Get the timestamp of the result.
external int? get timestamp;
/// Get the barcode format of the result.
///
/// See also https://github.com/zxing-js/library/blob/master/src/core/BarcodeFormat.ts
BarcodeFormat get barcodeFormat {
switch (_barcodeFormat) {
case 0:
return BarcodeFormat.aztec;
case 1:
return BarcodeFormat.codabar;
case 2:
return BarcodeFormat.code39;
case 3:
return BarcodeFormat.code93;
case 4:
return BarcodeFormat.code128;
case 5:
return BarcodeFormat.dataMatrix;
case 6:
return BarcodeFormat.ean8;
case 7:
return BarcodeFormat.ean13;
case 8:
return BarcodeFormat.itf;
case 9:
// Maxicode
return BarcodeFormat.unknown;
case 10:
return BarcodeFormat.pdf417;
case 11:
return BarcodeFormat.qrCode;
case 12:
// RSS 14
return BarcodeFormat.unknown;
case 13:
// RSS EXPANDED
return BarcodeFormat.unknown;
case 14:
return BarcodeFormat.upcA;
case 15:
return BarcodeFormat.upcE;
case 16:
// UPC/EAN extension
return BarcodeFormat.unknown;
default:
return BarcodeFormat.unknown;
}
}
/// Get the raw bytes of the result.
Uint8List? get rawBytes => _rawBytes?.toDart;
/// Get the corner points of the result.
List<Offset> get resultPoints {
final JSArray<ResultPoint>? points = _resultPoints;
if (points == null) {
return const [];
}
return points.toDart.map((point) {
return Offset(point.x, point.y);
}).toList();
}
/// Convert this result to a [Barcode].
Barcode get toBarcode {
return Barcode(
corners: resultPoints,
format: barcodeFormat,
displayValue: text,
rawBytes: rawBytes,
rawValue: text,
type: BarcodeType.text,
);
}
}