Navaron Bracke

add zxing corners to web barcode

@@ -130,12 +130,22 @@ class MobileScannerWebPlugin { @@ -130,12 +130,22 @@ class MobileScannerWebPlugin {
130 _barCodeStreamSubscription = 130 _barCodeStreamSubscription =
131 barCodeReader.detectBarcodeContinuously().listen((code) { 131 barCodeReader.detectBarcodeContinuously().listen((code) {
132 if (code != null) { 132 if (code != null) {
  133 + final List<Offset>? corners = code.corners;
  134 +
133 controller.add({ 135 controller.add({
134 'name': 'barcodeWeb', 136 'name': 'barcodeWeb',
135 'data': { 137 'data': {
136 'rawValue': code.rawValue, 138 'rawValue': code.rawValue,
137 'rawBytes': code.rawBytes, 139 'rawBytes': code.rawBytes,
138 'format': code.format.rawValue, 140 'format': code.format.rawValue,
  141 + 'displayValue': code.displayValue,
  142 + 'type': code.type.index,
  143 + if (corners != null && corners.isNotEmpty)
  144 + 'corners': corners
  145 + .map(
  146 + (Offset c) => <Object?, Object?>{'x': c.dx, 'y': c.dy},
  147 + )
  148 + .toList(),
139 }, 149 },
140 }); 150 });
141 } 151 }
@@ -400,6 +400,10 @@ class MobileScannerController { @@ -400,6 +400,10 @@ class MobileScannerController {
400 rawValue: barcode['rawValue'] as String?, 400 rawValue: barcode['rawValue'] as String?,
401 rawBytes: barcode['rawBytes'] as Uint8List?, 401 rawBytes: barcode['rawBytes'] as Uint8List?,
402 format: toFormat(barcode['format'] as int), 402 format: toFormat(barcode['format'] as int),
  403 + corners: toCorners(
  404 + (barcode['corners'] as List<Object?>? ?? [])
  405 + .cast<Map<Object?, Object?>>(),
  406 + ),
403 ), 407 ),
404 ], 408 ],
405 ), 409 ),
1 import 'dart:async'; 1 import 'dart:async';
2 import 'dart:html'; 2 import 'dart:html';
3 import 'dart:typed_data'; 3 import 'dart:typed_data';
  4 +import 'dart:ui';
4 5
5 import 'package:js/js.dart'; 6 import 'package:js/js.dart';
6 import 'package:mobile_scanner/src/enums/camera_facing.dart'; 7 import 'package:mobile_scanner/src/enums/camera_facing.dart';
@@ -19,6 +20,16 @@ class JsZXingBrowserMultiFormatReader { @@ -19,6 +20,16 @@ class JsZXingBrowserMultiFormatReader {
19 20
20 @JS() 21 @JS()
21 @anonymous 22 @anonymous
  23 +abstract class ResultPoint {
  24 + /// The x coordinate of the point.
  25 + external double get x;
  26 +
  27 + /// The y coordinate of the point.
  28 + external double get y;
  29 +}
  30 +
  31 +@JS()
  32 +@anonymous
22 abstract class Result { 33 abstract class Result {
23 /// raw text encoded by the barcode 34 /// raw text encoded by the barcode
24 external String get text; 35 external String get text;
@@ -28,15 +39,24 @@ abstract class Result { @@ -28,15 +39,24 @@ abstract class Result {
28 39
29 /// Representing the format of the barcode that was decoded 40 /// Representing the format of the barcode that was decoded
30 external int? format; 41 external int? format;
  42 +
  43 + /// Returns the result points of the barcode. These points represent the corners of the barcode.
  44 + external List<Object?> get resultPoints;
31 } 45 }
32 46
33 extension ResultExt on Result { 47 extension ResultExt on Result {
34 Barcode toBarcode() { 48 Barcode toBarcode() {
  49 + final corners = resultPoints
  50 + .cast<ResultPoint>()
  51 + .map((ResultPoint rp) => Offset(rp.x, rp.y))
  52 + .toList();
  53 +
35 final rawBytes = this.rawBytes; 54 final rawBytes = this.rawBytes;
36 return Barcode( 55 return Barcode(
37 rawValue: text, 56 rawValue: text,
38 rawBytes: rawBytes != null ? Uint8List.fromList(rawBytes) : null, 57 rawBytes: rawBytes != null ? Uint8List.fromList(rawBytes) : null,
39 format: barcodeFormat, 58 format: barcodeFormat,
  59 + corners: corners,
40 ); 60 );
41 } 61 }
42 62