Navaron Bracke

add hasTorch & setTorchState to the barcode reader interface instead

@@ -4,19 +4,16 @@ import 'dart:ui'; @@ -4,19 +4,16 @@ import 'dart:ui';
4 4
5 import 'package:js/js.dart'; 5 import 'package:js/js.dart';
6 import 'package:mobile_scanner/src/enums/mobile_scanner_error_code.dart'; 6 import 'package:mobile_scanner/src/enums/mobile_scanner_error_code.dart';
  7 +import 'package:mobile_scanner/src/enums/torch_state.dart';
7 import 'package:mobile_scanner/src/mobile_scanner_exception.dart'; 8 import 'package:mobile_scanner/src/mobile_scanner_exception.dart';
8 import 'package:mobile_scanner/src/objects/barcode_capture.dart'; 9 import 'package:mobile_scanner/src/objects/barcode_capture.dart';
9 import 'package:mobile_scanner/src/objects/start_options.dart'; 10 import 'package:mobile_scanner/src/objects/start_options.dart';
10 -import 'package:mobile_scanner/src/web/flashlight_delegate.dart';  
11 import 'package:web/web.dart'; 11 import 'package:web/web.dart';
12 12
13 /// This class represents the base interface for a barcode reader implementation. 13 /// This class represents the base interface for a barcode reader implementation.
14 abstract class BarcodeReader { 14 abstract class BarcodeReader {
15 const BarcodeReader(); 15 const BarcodeReader();
16 16
17 - /// Get the flashlight delegate for the barcode reader.  
18 - FlashlightDelegate get flashlightDelegate => const FlashlightDelegate();  
19 -  
20 /// Whether the scanner is currently scanning for barcodes. 17 /// Whether the scanner is currently scanning for barcodes.
21 bool get isScanning { 18 bool get isScanning {
22 throw UnimplementedError('isScanning has not been implemented.'); 19 throw UnimplementedError('isScanning has not been implemented.');
@@ -45,6 +42,11 @@ abstract class BarcodeReader { @@ -45,6 +42,11 @@ abstract class BarcodeReader {
45 throw UnimplementedError('detectBarcodes() has not been implemented.'); 42 throw UnimplementedError('detectBarcodes() has not been implemented.');
46 } 43 }
47 44
  45 + /// Check whether the active camera has a flashlight.
  46 + Future<bool> hasTorch() {
  47 + throw UnimplementedError('hasTorch() has not been implemented.');
  48 + }
  49 +
48 /// Load the barcode reader library. 50 /// Load the barcode reader library.
49 /// 51 ///
50 /// Does nothing if the library is already loaded. 52 /// Does nothing if the library is already loaded.
@@ -93,6 +95,11 @@ abstract class BarcodeReader { @@ -93,6 +95,11 @@ abstract class BarcodeReader {
93 await completer.future; 95 await completer.future;
94 } 96 }
95 97
  98 + /// Set the torch state for the active camera to the given [value].
  99 + Future<void> setTorchState(TorchState value) {
  100 + throw UnimplementedError('setTorchState() has not been implemented.');
  101 + }
  102 +
96 /// Start the barcode reader and initialize the video stream. 103 /// Start the barcode reader and initialize the video stream.
97 /// 104 ///
98 /// The [options] are used to configure the barcode reader. 105 /// The [options] are used to configure the barcode reader.
@@ -115,12 +115,10 @@ class MobileScannerWeb extends MobileScannerPlatform { @@ -115,12 +115,10 @@ class MobileScannerWeb extends MobileScannerPlatform {
115 _barcodesController.add(barcode); 115 _barcodesController.add(barcode);
116 }); 116 });
117 117
118 - final bool hasTorch = _barcodeReader.hasTorch; 118 + final bool hasTorch = await _barcodeReader.hasTorch();
119 119
120 if (hasTorch && startOptions.torchEnabled) { 120 if (hasTorch && startOptions.torchEnabled) {
121 - await _barcodeReader.setTorchState(TorchState.on).catchError((_) {  
122 - // If the torch could not be turned on, continue the camera session anyway.  
123 - }); 121 + await _barcodeReader.setTorchState(TorchState.on);
124 } 122 }
125 123
126 return MobileScannerViewAttributes( 124 return MobileScannerViewAttributes(