Navaron Bracke

fix missing JS annotations; use a switch expression; format

@@ -10,6 +10,7 @@ import 'package:mobile_scanner/src/web/zxing/result_point.dart'; @@ -10,6 +10,7 @@ import 'package:mobile_scanner/src/web/zxing/result_point.dart';
10 /// The JS static interop class for the Result class in the ZXing library. 10 /// The JS static interop class for the Result class in the ZXing library.
11 /// 11 ///
12 /// See also: https://github.com/zxing-js/library/blob/master/src/core/Result.ts 12 /// See also: https://github.com/zxing-js/library/blob/master/src/core/Result.ts
  13 +@JS()
13 extension type Result(JSObject _) implements JSObject { 14 extension type Result(JSObject _) implements JSObject {
14 @JS('barcodeFormat') 15 @JS('barcodeFormat')
15 external int? get _barcodeFormat; 16 external int? get _barcodeFormat;
@@ -30,48 +31,30 @@ extension type Result(JSObject _) implements JSObject { @@ -30,48 +31,30 @@ extension type Result(JSObject _) implements JSObject {
30 /// 31 ///
31 /// See also https://github.com/zxing-js/library/blob/master/src/core/BarcodeFormat.ts 32 /// See also https://github.com/zxing-js/library/blob/master/src/core/BarcodeFormat.ts
32 BarcodeFormat get barcodeFormat { 33 BarcodeFormat get barcodeFormat {
33 - switch (_barcodeFormat) {  
34 - case 0:  
35 - return BarcodeFormat.aztec;  
36 - case 1:  
37 - return BarcodeFormat.codabar;  
38 - case 2:  
39 - return BarcodeFormat.code39;  
40 - case 3:  
41 - return BarcodeFormat.code93;  
42 - case 4:  
43 - return BarcodeFormat.code128;  
44 - case 5:  
45 - return BarcodeFormat.dataMatrix;  
46 - case 6:  
47 - return BarcodeFormat.ean8;  
48 - case 7:  
49 - return BarcodeFormat.ean13;  
50 - case 8:  
51 - return BarcodeFormat.itf;  
52 - case 9:  
53 - // Maxicode  
54 - return BarcodeFormat.unknown;  
55 - case 10:  
56 - return BarcodeFormat.pdf417;  
57 - case 11:  
58 - return BarcodeFormat.qrCode;  
59 - case 12:  
60 - // RSS 14  
61 - return BarcodeFormat.unknown;  
62 - case 13:  
63 - // RSS EXPANDED  
64 - return BarcodeFormat.unknown;  
65 - case 14:  
66 - return BarcodeFormat.upcA;  
67 - case 15:  
68 - return BarcodeFormat.upcE;  
69 - case 16:  
70 - // UPC/EAN extension  
71 - return BarcodeFormat.unknown;  
72 - default:  
73 - return BarcodeFormat.unknown;  
74 - } 34 + return switch (_barcodeFormat) {
  35 + 0 => BarcodeFormat.aztec,
  36 + 1 => BarcodeFormat.codabar,
  37 + 2 => BarcodeFormat.code39,
  38 + 3 => BarcodeFormat.code93,
  39 + 4 => BarcodeFormat.code128,
  40 + 5 => BarcodeFormat.dataMatrix,
  41 + 6 => BarcodeFormat.ean8,
  42 + 7 => BarcodeFormat.ean13,
  43 + 8 => BarcodeFormat.itf,
  44 + // Maxicode
  45 + 9 => BarcodeFormat.unknown,
  46 + 10 => BarcodeFormat.pdf417,
  47 + 11 => BarcodeFormat.qrCode,
  48 + // RSS 14
  49 + 12 => BarcodeFormat.unknown,
  50 + // RSS EXPANDED
  51 + 13 => BarcodeFormat.unknown,
  52 + 14 => BarcodeFormat.upcA,
  53 + 15 => BarcodeFormat.upcE,
  54 + // UPC/EAN extension
  55 + 16 => BarcodeFormat.unknown,
  56 + _ => BarcodeFormat.unknown
  57 + };
75 } 58 }
76 59
77 /// Get the raw bytes of the result. 60 /// Get the raw bytes of the result.
@@ -3,6 +3,7 @@ import 'dart:js_interop'; @@ -3,6 +3,7 @@ import 'dart:js_interop';
3 /// The JS static interop class for the Result class in the ZXing library. 3 /// The JS static interop class for the Result class in the ZXing library.
4 /// 4 ///
5 /// See also: https://github.com/zxing-js/library/blob/master/src/core/ResultPoint.ts 5 /// See also: https://github.com/zxing-js/library/blob/master/src/core/ResultPoint.ts
  6 +@JS()
6 extension type ResultPoint(JSObject _) implements JSObject { 7 extension type ResultPoint(JSObject _) implements JSObject {
7 /// The x coordinate of the point. 8 /// The x coordinate of the point.
8 external double get x; 9 external double get x;
@@ -165,21 +165,24 @@ final class ZXingBarcodeReader extends BarcodeReader { @@ -165,21 +165,24 @@ final class ZXingBarcodeReader extends BarcodeReader {
165 165
166 extension on BarcodeFormat { 166 extension on BarcodeFormat {
167 /// Get the barcode format from the ZXing library. 167 /// Get the barcode format from the ZXing library.
168 - JSNumber get toJS => switch (this) {  
169 - BarcodeFormat.aztec => 0,  
170 - BarcodeFormat.codabar => 1,  
171 - BarcodeFormat.code39 => 2,  
172 - BarcodeFormat.code93 => 3,  
173 - BarcodeFormat.code128 => 4,  
174 - BarcodeFormat.dataMatrix => 5,  
175 - BarcodeFormat.ean8 => 6,  
176 - BarcodeFormat.ean13 => 7,  
177 - BarcodeFormat.itf => 8,  
178 - BarcodeFormat.pdf417 => 10,  
179 - BarcodeFormat.qrCode => 11,  
180 - BarcodeFormat.upcA => 14,  
181 - BarcodeFormat.upcE => 15,  
182 - BarcodeFormat.unknown || BarcodeFormat.all || _ => -1,  
183 - }  
184 - .toJS; 168 + JSNumber get toJS {
  169 + final int zxingFormat = switch (this) {
  170 + BarcodeFormat.aztec => 0,
  171 + BarcodeFormat.codabar => 1,
  172 + BarcodeFormat.code39 => 2,
  173 + BarcodeFormat.code93 => 3,
  174 + BarcodeFormat.code128 => 4,
  175 + BarcodeFormat.dataMatrix => 5,
  176 + BarcodeFormat.ean8 => 6,
  177 + BarcodeFormat.ean13 => 7,
  178 + BarcodeFormat.itf => 8,
  179 + BarcodeFormat.pdf417 => 10,
  180 + BarcodeFormat.qrCode => 11,
  181 + BarcodeFormat.upcA => 14,
  182 + BarcodeFormat.upcE => 15,
  183 + BarcodeFormat.unknown || BarcodeFormat.all || _ => -1,
  184 + };
  185 +
  186 + return zxingFormat.toJS;
  187 + }
185 } 188 }