Navaron Bracke

implement mobile scanner state as a model class

@@ -21,6 +21,7 @@ export 'src/objects/contact_info.dart'; @@ -21,6 +21,7 @@ export 'src/objects/contact_info.dart';
21 export 'src/objects/driver_license.dart'; 21 export 'src/objects/driver_license.dart';
22 export 'src/objects/email.dart'; 22 export 'src/objects/email.dart';
23 export 'src/objects/geo_point.dart'; 23 export 'src/objects/geo_point.dart';
  24 +export 'src/objects/mobile_scanner_state.dart';
24 export 'src/objects/person_name.dart'; 25 export 'src/objects/person_name.dart';
25 export 'src/objects/phone.dart'; 26 export 'src/objects/phone.dart';
26 export 'src/objects/sms.dart'; 27 export 'src/objects/sms.dart';
  1 +import 'dart:ui';
  2 +
  3 +import 'package:mobile_scanner/src/enums/camera_facing.dart';
  4 +import 'package:mobile_scanner/src/enums/torch_state.dart';
  5 +import 'package:mobile_scanner/src/mobile_scanner_exception.dart';
  6 +
  7 +/// This class represents the current state of a [MobileScannerController].
  8 +class MobileScannerState {
  9 + /// Create a new [MobileScannerState] instance.
  10 + const MobileScannerState({
  11 + required this.cameraDirection,
  12 + required this.isInitialized,
  13 + required this.size,
  14 + required this.torchState,
  15 + required this.zoomScale,
  16 + this.error,
  17 + });
  18 +
  19 + /// Create a new [MobileScannerState] instance that is uninitialized.
  20 + const MobileScannerState.uninitialized(CameraFacing facing)
  21 + : this(
  22 + cameraDirection: facing,
  23 + isInitialized: false,
  24 + size: Size.zero,
  25 + torchState: TorchState.unavailable,
  26 + zoomScale: 1.0,
  27 + );
  28 +
  29 + /// The facing direction of the camera.
  30 + final CameraFacing cameraDirection;
  31 +
  32 + /// The error that occurred while setting up or using the canera.
  33 + final MobileScannerException? error;
  34 +
  35 + /// Whether the mobile scanner has initialized successfully.
  36 + final bool isInitialized;
  37 +
  38 + /// The size of the camera output.
  39 + final Size size;
  40 +
  41 + /// The current state of the flashlight of the camera.
  42 + final TorchState torchState;
  43 +
  44 + /// The current zoom scale of the camera.
  45 + final double zoomScale;
  46 +
  47 + /// Create a copy of this state with the given parameters.
  48 + MobileScannerState copyWith({
  49 + CameraFacing? cameraDirection,
  50 + MobileScannerException? error,
  51 + bool? isInitialized,
  52 + Size? size,
  53 + TorchState? torchState,
  54 + double? zoomScale,
  55 + }) {
  56 + return MobileScannerState(
  57 + cameraDirection: cameraDirection ?? this.cameraDirection,
  58 + error: error,
  59 + isInitialized: isInitialized ?? this.isInitialized,
  60 + size: size ?? this.size,
  61 + torchState: torchState ?? this.torchState,
  62 + zoomScale: zoomScale ?? this.zoomScale,
  63 + );
  64 + }
  65 +}