Showing
1 changed file
with
77 additions
and
0 deletions
lib/src/web/zxing/result.dart
0 → 100644
| 1 | +import 'dart:js_interop'; | ||
| 2 | + | ||
| 3 | +import 'package:mobile_scanner/src/enums/barcode_format.dart'; | ||
| 4 | + | ||
| 5 | +/// The JS static interop class for the Result class in the ZXing library. | ||
| 6 | +/// | ||
| 7 | +/// See also: https://github.com/zxing-js/library/blob/master/src/core/Result.ts | ||
| 8 | +@JS() | ||
| 9 | +@staticInterop | ||
| 10 | +abstract class Result {} | ||
| 11 | + | ||
| 12 | +extension ResultExt on Result { | ||
| 13 | + /// Get the barcode format. | ||
| 14 | + /// | ||
| 15 | + /// See also https://github.com/zxing-js/library/blob/master/src/core/BarcodeFormat.ts | ||
| 16 | + external JSFunction getBarcodeFormat; | ||
| 17 | + | ||
| 18 | + /// Get the raw bytes of the result. | ||
| 19 | + external JSFunction getRawBytes; | ||
| 20 | + | ||
| 21 | + /// Get the points of the result. | ||
| 22 | + external JSFunction getResultPoints; | ||
| 23 | + | ||
| 24 | + /// Get the text of the result. | ||
| 25 | + external JSFunction getText; | ||
| 26 | + | ||
| 27 | + /// Get the timestamp of the result. | ||
| 28 | + external JSFunction getTimestamp; | ||
| 29 | + | ||
| 30 | + /// Get the barcode format of the result. | ||
| 31 | + BarcodeFormat get barcodeFormat { | ||
| 32 | + final JSNumber? format = getBarcodeFormat.callAsFunction() as JSNumber?; | ||
| 33 | + | ||
| 34 | + switch (format?.toDartInt) { | ||
| 35 | + case 0: | ||
| 36 | + return BarcodeFormat.aztec; | ||
| 37 | + case 1: | ||
| 38 | + return BarcodeFormat.codabar; | ||
| 39 | + case 2: | ||
| 40 | + return BarcodeFormat.code39; | ||
| 41 | + case 3: | ||
| 42 | + return BarcodeFormat.code93; | ||
| 43 | + case 4: | ||
| 44 | + return BarcodeFormat.code128; | ||
| 45 | + case 5: | ||
| 46 | + return BarcodeFormat.dataMatrix; | ||
| 47 | + case 6: | ||
| 48 | + return BarcodeFormat.ean8; | ||
| 49 | + case 7: | ||
| 50 | + return BarcodeFormat.ean13; | ||
| 51 | + case 8: | ||
| 52 | + return BarcodeFormat.itf; | ||
| 53 | + case 9: | ||
| 54 | + // Maxicode | ||
| 55 | + return BarcodeFormat.unknown; | ||
| 56 | + case 10: | ||
| 57 | + return BarcodeFormat.pdf417; | ||
| 58 | + case 11: | ||
| 59 | + return BarcodeFormat.qrCode; | ||
| 60 | + case 12: | ||
| 61 | + // RSS 14 | ||
| 62 | + return BarcodeFormat.unknown; | ||
| 63 | + case 13: | ||
| 64 | + // RSS EXPANDED | ||
| 65 | + return BarcodeFormat.unknown; | ||
| 66 | + case 14: | ||
| 67 | + return BarcodeFormat.upcA; | ||
| 68 | + case 15: | ||
| 69 | + return BarcodeFormat.upcE; | ||
| 70 | + case 16: | ||
| 71 | + // UPC/EAN extension | ||
| 72 | + return BarcodeFormat.unknown; | ||
| 73 | + default: | ||
| 74 | + return BarcodeFormat.unknown; | ||
| 75 | + } | ||
| 76 | + } | ||
| 77 | +} |
-
Please register or login to post a comment