Julian Steenbakker

bug: fix pause and resume not working on web

... ... @@ -13,6 +13,17 @@ import 'package:web/web.dart';
abstract class BarcodeReader {
const BarcodeReader();
/// Whether the video feed is paused
bool? get paused =>
throw UnimplementedError('paused has not been implemented.');
/// Pause the barcode reader.
void pause() => throw UnimplementedError('pause() has not been implemented.');
/// Pause the barcode reader.
Future<void> resume() =>
throw UnimplementedError('resume() has not been implemented.');
/// Whether the scanner is currently scanning for barcodes.
bool get isScanning {
throw UnimplementedError('isScanning has not been implemented.');
... ... @@ -128,11 +139,6 @@ abstract class BarcodeReader {
throw UnimplementedError('start() has not been implemented.');
}
/// Pause the barcode reader.
Future<void> pause() {
throw UnimplementedError('pause() has not been implemented.');
}
/// Stop the barcode reader and dispose of the video stream.
Future<void> stop() {
throw UnimplementedError('stop() has not been implemented.');
... ...
... ... @@ -263,6 +263,16 @@ class MobileScannerWeb extends MobileScannerPlatform {
@override
Future<MobileScannerViewAttributes> start(StartOptions startOptions) async {
if (_barcodeReader != null) {
if (_barcodeReader!.paused ?? false) {
await _barcodeReader?.resume();
return MobileScannerViewAttributes(
// The torch of a media stream is not available for video tracks.
// See https://developer.mozilla.org/en-US/docs/Web/API/MediaTrackConstraints#instance_properties_of_video_tracks
currentTorchMode: TorchState.unavailable,
size: _barcodeReader?.videoSize ?? Size.zero,
);
}
throw const MobileScannerException(
errorCode: MobileScannerErrorCode.controllerAlreadyInitialized,
errorDetails: MobileScannerErrorDetails(
... ... @@ -365,7 +375,7 @@ class MobileScannerWeb extends MobileScannerPlatform {
@override
Future<void> pause() async {
_barcodesSubscription?.pause();
await _barcodeReader?.pause();
_barcodeReader?.pause();
}
@override
... ...
... ... @@ -169,8 +169,15 @@ final class ZXingBarcodeReader extends BarcodeReader {
}
@override
Future<void> pause() async {
_reader?.videoElement?.pause();
bool? get paused => _reader?.videoElement?.paused;
@override
void pause() => _reader?.videoElement?.pause();
@override
Future<void> resume() async {
final result = _reader?.videoElement?.play();
await result?.toDart;
}
@override
... ...