Navaron Bracke

add zxing corners to web barcode

... ... @@ -130,12 +130,22 @@ class MobileScannerWebPlugin {
_barCodeStreamSubscription =
barCodeReader.detectBarcodeContinuously().listen((code) {
if (code != null) {
final List<Offset>? corners = code.corners;
controller.add({
'name': 'barcodeWeb',
'data': {
'rawValue': code.rawValue,
'rawBytes': code.rawBytes,
'format': code.format.rawValue,
'displayValue': code.displayValue,
'type': code.type.index,
if (corners != null && corners.isNotEmpty)
'corners': corners
.map(
(Offset c) => <Object?, Object?>{'x': c.dx, 'y': c.dy},
)
.toList(),
},
});
}
... ...
... ... @@ -400,6 +400,10 @@ class MobileScannerController {
rawValue: barcode['rawValue'] as String?,
rawBytes: barcode['rawBytes'] as Uint8List?,
format: toFormat(barcode['format'] as int),
corners: toCorners(
(barcode['corners'] as List<Object?>? ?? [])
.cast<Map<Object?, Object?>>(),
),
),
],
),
... ...
import 'dart:async';
import 'dart:html';
import 'dart:typed_data';
import 'dart:ui';
import 'package:js/js.dart';
import 'package:mobile_scanner/src/enums/camera_facing.dart';
... ... @@ -19,6 +20,16 @@ class JsZXingBrowserMultiFormatReader {
@JS()
@anonymous
abstract class ResultPoint {
/// The x coordinate of the point.
external double get x;
/// The y coordinate of the point.
external double get y;
}
@JS()
@anonymous
abstract class Result {
/// raw text encoded by the barcode
external String get text;
... ... @@ -28,15 +39,24 @@ abstract class Result {
/// Representing the format of the barcode that was decoded
external int? format;
/// Returns the result points of the barcode. These points represent the corners of the barcode.
external List<Object?> get resultPoints;
}
extension ResultExt on Result {
Barcode toBarcode() {
final corners = resultPoints
.cast<ResultPoint>()
.map((ResultPoint rp) => Offset(rp.x, rp.y))
.toList();
final rawBytes = this.rawBytes;
return Barcode(
rawValue: text,
rawBytes: rawBytes != null ? Uint8List.fromList(rawBytes) : null,
format: barcodeFormat,
corners: corners,
);
}
... ...