Navaron Bracke

add an isRunning flag to the scanner state

... ... @@ -230,12 +230,14 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> {
value = value.copyWith(
cameraDirection: effectiveDirection,
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,
);
} on MobileScannerException catch (error) {
// The initialization finished with an error.
if (!_isDisposed) {
value = value.copyWith(
cameraDirection: facing,
... ... @@ -258,7 +260,10 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> {
// After the camera stopped, set the torch state to off,
// as the torch state callback is never called when the camera is stopped.
value = value.copyWith(torchState: TorchState.off);
value = value.copyWith(
isRunning: false,
torchState: TorchState.off,
);
}
/// Switch between the front and back camera.
... ...
... ... @@ -10,6 +10,7 @@ class MobileScannerState {
const MobileScannerState({
required this.cameraDirection,
required this.isInitialized,
required this.isRunning,
required this.size,
required this.torchState,
required this.zoomScale,
... ... @@ -21,6 +22,7 @@ class MobileScannerState {
: this(
cameraDirection: facing,
isInitialized: false,
isRunning: false,
size: Size.zero,
torchState: TorchState.unavailable,
zoomScale: 1.0,
... ... @@ -33,8 +35,15 @@ class MobileScannerState {
final MobileScannerException? error;
/// Whether the mobile scanner has initialized successfully.
///
/// This is `true` if the camera is ready to be used.
final bool isInitialized;
/// Whether the mobile scanner is currently running.
///
/// This is `true` if the camera is active.
final bool isRunning;
/// The size of the camera output.
final Size size;
... ... @@ -49,6 +58,7 @@ class MobileScannerState {
CameraFacing? cameraDirection,
MobileScannerException? error,
bool? isInitialized,
bool? isRunning,
Size? size,
TorchState? torchState,
double? zoomScale,
... ... @@ -57,6 +67,7 @@ class MobileScannerState {
cameraDirection: cameraDirection ?? this.cameraDirection,
error: error,
isInitialized: isInitialized ?? this.isInitialized,
isRunning: isRunning ?? this.isRunning,
size: size ?? this.size,
torchState: torchState ?? this.torchState,
zoomScale: zoomScale ?? this.zoomScale,
... ...