Showing
4 changed files
with
26 additions
and
5 deletions
| @@ -97,7 +97,13 @@ class MobileScannerWebPlugin { | @@ -97,7 +97,13 @@ class MobileScannerWebPlugin { | ||
| 97 | 97 | ||
| 98 | _barCodeStreamSubscription = _barCodeReader.detectBarcodeContinuously().listen((code) { | 98 | _barCodeStreamSubscription = _barCodeReader.detectBarcodeContinuously().listen((code) { |
| 99 | if (code != null) { | 99 | if (code != null) { |
| 100 | - controller.add({'name': 'barcodeWeb', 'data': code}); | 100 | + controller.add({ |
| 101 | + 'name': 'barcodeWeb', | ||
| 102 | + 'data': { | ||
| 103 | + 'rawValue': code.rawValue, | ||
| 104 | + 'rawBytes': code.rawBytes, | ||
| 105 | + }, | ||
| 106 | + }); | ||
| 101 | } | 107 | } |
| 102 | }); | 108 | }); |
| 103 | 109 |
| 1 | import 'dart:async'; | 1 | import 'dart:async'; |
| 2 | import 'dart:io'; | 2 | import 'dart:io'; |
| 3 | +import 'dart:typed_data'; | ||
| 3 | 4 | ||
| 4 | import 'package:flutter/cupertino.dart'; | 5 | import 'package:flutter/cupertino.dart'; |
| 5 | import 'package:flutter/foundation.dart'; | 6 | import 'package:flutter/foundation.dart'; |
| @@ -296,11 +297,13 @@ class MobileScannerController { | @@ -296,11 +297,13 @@ class MobileScannerController { | ||
| 296 | ); | 297 | ); |
| 297 | break; | 298 | break; |
| 298 | case 'barcodeWeb': | 299 | case 'barcodeWeb': |
| 300 | + final barcode = data as Map?; | ||
| 299 | _barcodesController.add( | 301 | _barcodesController.add( |
| 300 | BarcodeCapture( | 302 | BarcodeCapture( |
| 301 | barcodes: [ | 303 | barcodes: [ |
| 302 | Barcode( | 304 | Barcode( |
| 303 | - rawValue: data as String?, | 305 | + rawValue: barcode?['rawValue'] as String?, |
| 306 | + rawBytes: barcode?['rawBytes'] as Uint8List?, | ||
| 304 | ) | 307 | ) |
| 305 | ], | 308 | ], |
| 306 | ), | 309 | ), |
| @@ -2,6 +2,7 @@ import 'dart:html'; | @@ -2,6 +2,7 @@ import 'dart:html'; | ||
| 2 | 2 | ||
| 3 | import 'package:flutter/material.dart'; | 3 | import 'package:flutter/material.dart'; |
| 4 | import 'package:mobile_scanner/src/enums/camera_facing.dart'; | 4 | import 'package:mobile_scanner/src/enums/camera_facing.dart'; |
| 5 | +import 'package:mobile_scanner/src/objects/barcode.dart'; | ||
| 5 | import 'package:mobile_scanner/src/web/media.dart'; | 6 | import 'package:mobile_scanner/src/web/media.dart'; |
| 6 | 7 | ||
| 7 | abstract class WebBarcodeReaderBase { | 8 | abstract class WebBarcodeReaderBase { |
| @@ -25,7 +26,7 @@ abstract class WebBarcodeReaderBase { | @@ -25,7 +26,7 @@ abstract class WebBarcodeReaderBase { | ||
| 25 | }); | 26 | }); |
| 26 | 27 | ||
| 27 | /// Starts scanning QR codes or barcodes | 28 | /// Starts scanning QR codes or barcodes |
| 28 | - Stream<String?> detectBarcodeContinuously(); | 29 | + Stream<Barcode?> detectBarcodeContinuously(); |
| 29 | 30 | ||
| 30 | /// Stops streaming video | 31 | /// Stops streaming video |
| 31 | Future<void> stop(); | 32 | Future<void> stop(); |
| @@ -7,6 +7,7 @@ import 'dart:typed_data'; | @@ -7,6 +7,7 @@ import 'dart:typed_data'; | ||
| 7 | 7 | ||
| 8 | import 'package:js/js.dart'; | 8 | import 'package:js/js.dart'; |
| 9 | import 'package:mobile_scanner/src/enums/camera_facing.dart'; | 9 | import 'package:mobile_scanner/src/enums/camera_facing.dart'; |
| 10 | +import 'package:mobile_scanner/src/objects/barcode.dart'; | ||
| 10 | import 'package:mobile_scanner/src/web/base.dart'; | 11 | import 'package:mobile_scanner/src/web/base.dart'; |
| 11 | 12 | ||
| 12 | @JS('jsQR') | 13 | @JS('jsQR') |
| @@ -58,10 +59,20 @@ class JsQrCodeReader extends WebBarcodeReaderBase | @@ -58,10 +59,20 @@ class JsQrCodeReader extends WebBarcodeReaderBase | ||
| 58 | } | 59 | } |
| 59 | 60 | ||
| 60 | @override | 61 | @override |
| 61 | - Stream<String?> detectBarcodeContinuously() async* { | 62 | + Stream<Barcode?> detectBarcodeContinuously() async* { |
| 62 | yield* Stream.periodic(frameInterval, (_) { | 63 | yield* Stream.periodic(frameInterval, (_) { |
| 63 | return _captureFrame(video); | 64 | return _captureFrame(video); |
| 64 | - }).asyncMap((e) => e).map((event) => event?.data); | 65 | + }).asyncMap((event) async { |
| 66 | + final code = await event; | ||
| 67 | + if (code == null) { | ||
| 68 | + return null; | ||
| 69 | + } | ||
| 70 | + return Barcode( | ||
| 71 | + rawValue: code.data, | ||
| 72 | + rawBytes: Uint8List.fromList(code.binaryData), | ||
| 73 | + format: BarcodeFormat.qrCode, | ||
| 74 | + ); | ||
| 75 | + }); | ||
| 65 | } | 76 | } |
| 66 | 77 | ||
| 67 | /// Captures a frame and analyzes it for QR codes | 78 | /// Captures a frame and analyzes it for QR codes |
-
Please register or login to post a comment