mobile_scanner_state.dart
2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import 'dart:ui';
import 'package:mobile_scanner/src/enums/camera_facing.dart';
import 'package:mobile_scanner/src/enums/torch_state.dart';
import 'package:mobile_scanner/src/mobile_scanner_exception.dart';
/// This class represents the current state of a [MobileScannerController].
class MobileScannerState {
/// Create a new [MobileScannerState] instance.
const MobileScannerState({
required this.availableCameras,
required this.cameraDirection,
required this.isInitialized,
required this.isRunning,
required this.size,
required this.torchState,
required this.zoomScale,
this.error,
});
/// Create a new [MobileScannerState] instance that is uninitialized.
const MobileScannerState.uninitialized(CameraFacing facing)
: this(
availableCameras: null,
cameraDirection: facing,
isInitialized: false,
isRunning: false,
size: Size.zero,
torchState: TorchState.unavailable,
zoomScale: 1.0,
);
/// The number of available cameras.
///
/// This is null if the number of cameras is unknown.
final int? availableCameras;
/// The facing direction of the camera.
final CameraFacing cameraDirection;
/// The error that occurred while setting up or using the camera.
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;
/// The current state of the flashlight of the camera.
final TorchState torchState;
/// The current zoom scale of the camera.
final double zoomScale;
/// Create a copy of this state with the given parameters.
MobileScannerState copyWith({
int? availableCameras,
CameraFacing? cameraDirection,
MobileScannerException? error,
bool? isInitialized,
bool? isRunning,
Size? size,
TorchState? torchState,
double? zoomScale,
}) {
return MobileScannerState(
availableCameras: availableCameras ?? this.availableCameras,
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,
);
}
}