Navaron Bracke

provide the current torch mode instead of `hasTorch` when the camera starts

... ... @@ -246,7 +246,9 @@ class MethodChannelMobileScanner extends MobileScannerPlatform {
_textureId = textureId;
final int? numberOfCameras = startResult['numberOfCameras'] as int?;
final bool hasTorch = startResult['torchable'] as bool? ?? false;
final TorchState currentTorchState = TorchState.fromRawValue(
startResult['currentTorchState'] as int? ?? -1,
);
final Map<Object?, Object?>? sizeInfo =
startResult['size'] as Map<Object?, Object?>?;
... ... @@ -262,7 +264,7 @@ class MethodChannelMobileScanner extends MobileScannerPlatform {
}
return MobileScannerViewAttributes(
hasTorch: hasTorch,
currentTorchMode: currentTorchState,
numberOfCameras: numberOfCameras,
size: size,
);
... ...
... ... @@ -281,9 +281,9 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> {
isInitialized: true,
isRunning: true,
size: viewAttributes.size,
// If the device has a flashlight, let the platform update the torch state.
// If it does not have one, provide the unavailable state directly.
torchState: viewAttributes.hasTorch ? null : TorchState.unavailable,
// Provide the current torch state.
// Updates are provided by the `torchStateStream`.
torchState: viewAttributes.currentTorchMode,
);
}
} on MobileScannerException catch (error) {
... ...
import 'dart:ui';
import 'package:mobile_scanner/src/enums/torch_state.dart';
/// This class defines the attributes for the mobile scanner view.
class MobileScannerViewAttributes {
const MobileScannerViewAttributes({
required this.hasTorch,
required this.currentTorchMode,
this.numberOfCameras,
required this.size,
});
/// Whether the current active camera has a torch.
final bool hasTorch;
/// The current torch state of the active camera.
final TorchState currentTorchMode;
/// The number of available cameras.
final int? numberOfCameras;
... ...
... ... @@ -346,7 +346,9 @@ class MobileScannerWeb extends MobileScannerPlatform {
}
return MobileScannerViewAttributes(
hasTorch: hasTorch,
// 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,
);
} catch (error, stackTrace) {
... ...