start_options.dart
1.65 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
import 'dart:ui';
import 'package:mobile_scanner/src/enums/barcode_format.dart';
import 'package:mobile_scanner/src/enums/camera_facing.dart';
import 'package:mobile_scanner/src/enums/detection_speed.dart';
/// This class defines the different start options for the mobile scanner.
class StartOptions {
const StartOptions({
required this.cameraDirection,
required this.cameraResolution,
required this.detectionSpeed,
required this.detectionTimeoutMs,
required this.formats,
required this.returnImage,
required this.torchEnabled,
});
/// The direction for the camera.
final CameraFacing cameraDirection;
/// The desired camera resolution for the scanner.
final Size? cameraResolution;
/// The detection speed for the scanner.
final DetectionSpeed detectionSpeed;
/// The detection timeout for the scanner, in milliseconds.
final int detectionTimeoutMs;
/// The barcode formats to detect.
final List<BarcodeFormat> formats;
/// Whether the detected barcodes should provide their image data.
final bool returnImage;
/// Whether the torch should be turned on when the scanner starts.
final bool torchEnabled;
Map<String, Object?> toMap() {
return <String, Object?>{
if (cameraResolution != null)
'cameraResolution': <int>[
cameraResolution!.width.toInt(),
cameraResolution!.height.toInt(),
],
'facing': cameraDirection.rawValue,
if (formats.isNotEmpty)
'formats': formats.map((f) => f.rawValue).toList(),
'returnImage': returnImage,
'speed': detectionSpeed.rawValue,
'timeout': detectionTimeoutMs,
'torch': torchEnabled,
};
}
}