Navaron Bracke

add hasTorch & setTorchState to the barcode reader interface instead

... ... @@ -4,19 +4,16 @@ import 'dart:ui';
import 'package:js/js.dart';
import 'package:mobile_scanner/src/enums/mobile_scanner_error_code.dart';
import 'package:mobile_scanner/src/enums/torch_state.dart';
import 'package:mobile_scanner/src/mobile_scanner_exception.dart';
import 'package:mobile_scanner/src/objects/barcode_capture.dart';
import 'package:mobile_scanner/src/objects/start_options.dart';
import 'package:mobile_scanner/src/web/flashlight_delegate.dart';
import 'package:web/web.dart';
/// This class represents the base interface for a barcode reader implementation.
abstract class BarcodeReader {
const BarcodeReader();
/// Get the flashlight delegate for the barcode reader.
FlashlightDelegate get flashlightDelegate => const FlashlightDelegate();
/// Whether the scanner is currently scanning for barcodes.
bool get isScanning {
throw UnimplementedError('isScanning has not been implemented.');
... ... @@ -45,6 +42,11 @@ abstract class BarcodeReader {
throw UnimplementedError('detectBarcodes() has not been implemented.');
}
/// Check whether the active camera has a flashlight.
Future<bool> hasTorch() {
throw UnimplementedError('hasTorch() has not been implemented.');
}
/// Load the barcode reader library.
///
/// Does nothing if the library is already loaded.
... ... @@ -93,6 +95,11 @@ abstract class BarcodeReader {
await completer.future;
}
/// Set the torch state for the active camera to the given [value].
Future<void> setTorchState(TorchState value) {
throw UnimplementedError('setTorchState() has not been implemented.');
}
/// Start the barcode reader and initialize the video stream.
///
/// The [options] are used to configure the barcode reader.
... ...
... ... @@ -115,12 +115,10 @@ class MobileScannerWeb extends MobileScannerPlatform {
_barcodesController.add(barcode);
});
final bool hasTorch = _barcodeReader.hasTorch;
final bool hasTorch = await _barcodeReader.hasTorch();
if (hasTorch && startOptions.torchEnabled) {
await _barcodeReader.setTorchState(TorchState.on).catchError((_) {
// If the torch could not be turned on, continue the camera session anyway.
});
await _barcodeReader.setTorchState(TorchState.on);
}
return MobileScannerViewAttributes(
... ...