Julian Steenbakker

feat: add hasTorch function

@@ -19,6 +19,7 @@ Improvements: @@ -19,6 +19,7 @@ Improvements:
19 Features: 19 Features:
20 * Added a new `placeholderBuilder` function to the `MobileScanner` widget to customize the preview placeholder. 20 * Added a new `placeholderBuilder` function to the `MobileScanner` widget to customize the preview placeholder.
21 * Added `autoStart` parameter to MobileScannerController(). If set to false, controller won't start automatically. 21 * Added `autoStart` parameter to MobileScannerController(). If set to false, controller won't start automatically.
  22 +* Added `hasTorch` function on MobileScannerController(). After starting the controller, you can check if the device has a torch.
22 23
23 Fixed: 24 Fixed:
24 * Fixed a memory leak where the `MobileScanner` widget would never close its subscription to the barcode events. 25 * Fixed a memory leak where the `MobileScanner` widget would never close its subscription to the barcode events.
@@ -101,6 +101,19 @@ class MobileScannerController { @@ -101,6 +101,19 @@ class MobileScannerController {
101 101
102 bool? _hasTorch; 102 bool? _hasTorch;
103 103
  104 + /// Returns whether the device has a torch.
  105 + ///
  106 + /// Throws an error if the controller is not initialized.
  107 + bool get hasTorch {
  108 + if (_hasTorch == null) {
  109 + throw const MobileScannerException(
  110 + errorCode: MobileScannerErrorCode.controllerUninitialized,
  111 + );
  112 + }
  113 +
  114 + return _hasTorch!;
  115 + }
  116 +
104 /// Set the starting arguments for the camera 117 /// Set the starting arguments for the camera
105 Map<String, dynamic> _argumentsToMap({CameraFacing? cameraFacingOverride}) { 118 Map<String, dynamic> _argumentsToMap({CameraFacing? cameraFacingOverride}) {
106 final Map<String, dynamic> arguments = {}; 119 final Map<String, dynamic> arguments = {};