fumin65

add pause function to web part

... ... @@ -129,6 +129,11 @@ 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.');
... ...
import 'dart:async';
import 'dart:developer';
import 'dart:html';
import 'dart:js_interop';
import 'dart:ui_web' as ui_web;
... ... @@ -235,6 +237,11 @@ class MobileScannerWeb extends MobileScannerPlatform {
throw PermissionRequestPendingException();
}
// If the previous state is a pause, reset scanner.
if (_barcodesSubscription != null && _barcodesSubscription!.isPaused) {
await stop();
}
await _barcodeReader.maybeLoadLibrary(
alternateScriptUrl: _alternateScriptUrl,
);
... ... @@ -336,6 +343,13 @@ class MobileScannerWeb extends MobileScannerPlatform {
}
}
@override
Future<void> pause() async {
_barcodesSubscription?.pause();
await _barcodeReader.pause();
}
@override
Future<void> stop() async {
if (_barcodesController.isClosed) {
... ...
... ... @@ -192,6 +192,11 @@ final class ZXingBarcodeReader extends BarcodeReader {
}
@override
Future<void> pause() async {
_reader?.videoElement?.pause();
}
@override
Future<void> stop() async {
_onMediaTrackSettingsChanged = null;
_reader?.stopContinuousDecode.callAsFunction(_reader as JSAny?);
... ...