Navaron Bracke

create a new start options class

  1 +import 'dart:ui';
  2 +
  3 +import 'package:mobile_scanner/src/enums/barcode_format.dart';
  4 +import 'package:mobile_scanner/src/enums/camera_facing.dart';
  5 +import 'package:mobile_scanner/src/enums/detection_speed.dart';
  6 +
  7 +/// This class defines the different start options for the mobile scanner.
  8 +class StartOptions {
  9 + const StartOptions({
  10 + required this.cameraDirection,
  11 + required this.cameraResolution,
  12 + required this.detectionSpeed,
  13 + required this.detectionTimeoutMs,
  14 + required this.formats,
  15 + required this.returnImage,
  16 + required this.torchEnabled,
  17 + });
  18 +
  19 + /// The direction for the camera.
  20 + final CameraFacing cameraDirection;
  21 +
  22 + /// The desired camera resolution for the scanner.
  23 + final Size? cameraResolution;
  24 +
  25 + /// The detection speed for the scanner.
  26 + final DetectionSpeed detectionSpeed;
  27 +
  28 + /// The detection timeout for the scanner, in milliseconds.
  29 + final int detectionTimeoutMs;
  30 +
  31 + /// The barcode formats to detect.
  32 + final List<BarcodeFormat> formats;
  33 +
  34 + /// Whether the detected barcodes should provide their image data.
  35 + final bool returnImage;
  36 +
  37 + /// Whether the torch should be turned on when the scanner starts.
  38 + final bool torchEnabled;
  39 +
  40 + Map<String, Object?> toMap() {
  41 + return <String, Object?>{
  42 + if (cameraResolution != null)
  43 + 'cameraResolution': <int>[
  44 + cameraResolution!.width.toInt(),
  45 + cameraResolution!.height.toInt(),
  46 + ],
  47 + 'facing': cameraDirection.rawValue,
  48 + if (formats.isNotEmpty)
  49 + 'formats': formats.map((f) => f.rawValue).toList(),
  50 + 'returnImage': returnImage,
  51 + 'speed': detectionSpeed.rawValue,
  52 + 'timeout': detectionTimeoutMs,
  53 + 'torch': torchEnabled,
  54 + };
  55 + }
  56 +}