Navaron Bracke

add extra getters for Result

1 import 'dart:js_interop'; 1 import 'dart:js_interop';
  2 +import 'dart:typed_data';
  3 +import 'dart:ui';
2 4
3 import 'package:mobile_scanner/src/enums/barcode_format.dart'; 5 import 'package:mobile_scanner/src/enums/barcode_format.dart';
  6 +import 'package:mobile_scanner/src/web/zxing/result_point.dart';
4 7
5 /// The JS static interop class for the Result class in the ZXing library. 8 /// The JS static interop class for the Result class in the ZXing library.
6 /// 9 ///
@@ -74,4 +77,35 @@ extension ResultExt on Result { @@ -74,4 +77,35 @@ extension ResultExt on Result {
74 return BarcodeFormat.unknown; 77 return BarcodeFormat.unknown;
75 } 78 }
76 } 79 }
  80 +
  81 + List<Offset> get resultPoints {
  82 + final JSArray? resultPoints = getResultPoints.callAsFunction() as JSArray?;
  83 +
  84 + if (resultPoints == null) {
  85 + return [];
  86 + }
  87 +
  88 + return resultPoints.toDart.cast<ResultPoint>().map((point) {
  89 + return Offset(point.x, point.y);
  90 + }).toList();
  91 + }
  92 +
  93 + /// Get the raw bytes of the result.
  94 + Uint8List? get rawBytes {
  95 + final JSUint8Array? rawBytes = getRawBytes.callAsFunction() as JSUint8Array?;
  96 +
  97 + return rawBytes?.toDart;
  98 + }
  99 +
  100 + /// Get the text of the result.
  101 + String? get text {
  102 + return getText.callAsFunction() as String?;
  103 + }
  104 +
  105 + /// Get the timestamp of the result.
  106 + int? get timestamp {
  107 + final JSNumber? timestamp = getTimestamp.callAsFunction() as JSNumber?;
  108 +
  109 + return timestamp?.toDartInt;
  110 + }
77 } 111 }