Showing
2 changed files
with
17 additions
and
1 deletions
| @@ -230,12 +230,14 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> { | @@ -230,12 +230,14 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> { | ||
| 230 | value = value.copyWith( | 230 | value = value.copyWith( |
| 231 | cameraDirection: effectiveDirection, | 231 | cameraDirection: effectiveDirection, |
| 232 | isInitialized: true, | 232 | isInitialized: true, |
| 233 | + isRunning: true, | ||
| 233 | size: viewAttributes.size, | 234 | size: viewAttributes.size, |
| 234 | // If the device has a flashlight, let the platform update the torch state. | 235 | // If the device has a flashlight, let the platform update the torch state. |
| 235 | // If it does not have one, provide the unavailable state directly. | 236 | // If it does not have one, provide the unavailable state directly. |
| 236 | torchState: viewAttributes.hasTorch ? null : TorchState.unavailable, | 237 | torchState: viewAttributes.hasTorch ? null : TorchState.unavailable, |
| 237 | ); | 238 | ); |
| 238 | } on MobileScannerException catch (error) { | 239 | } on MobileScannerException catch (error) { |
| 240 | + // The initialization finished with an error. | ||
| 239 | if (!_isDisposed) { | 241 | if (!_isDisposed) { |
| 240 | value = value.copyWith( | 242 | value = value.copyWith( |
| 241 | cameraDirection: facing, | 243 | cameraDirection: facing, |
| @@ -258,7 +260,10 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> { | @@ -258,7 +260,10 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> { | ||
| 258 | 260 | ||
| 259 | // After the camera stopped, set the torch state to off, | 261 | // After the camera stopped, set the torch state to off, |
| 260 | // as the torch state callback is never called when the camera is stopped. | 262 | // as the torch state callback is never called when the camera is stopped. |
| 261 | - value = value.copyWith(torchState: TorchState.off); | 263 | + value = value.copyWith( |
| 264 | + isRunning: false, | ||
| 265 | + torchState: TorchState.off, | ||
| 266 | + ); | ||
| 262 | } | 267 | } |
| 263 | 268 | ||
| 264 | /// Switch between the front and back camera. | 269 | /// Switch between the front and back camera. |
| @@ -10,6 +10,7 @@ class MobileScannerState { | @@ -10,6 +10,7 @@ class MobileScannerState { | ||
| 10 | const MobileScannerState({ | 10 | const MobileScannerState({ |
| 11 | required this.cameraDirection, | 11 | required this.cameraDirection, |
| 12 | required this.isInitialized, | 12 | required this.isInitialized, |
| 13 | + required this.isRunning, | ||
| 13 | required this.size, | 14 | required this.size, |
| 14 | required this.torchState, | 15 | required this.torchState, |
| 15 | required this.zoomScale, | 16 | required this.zoomScale, |
| @@ -21,6 +22,7 @@ class MobileScannerState { | @@ -21,6 +22,7 @@ class MobileScannerState { | ||
| 21 | : this( | 22 | : this( |
| 22 | cameraDirection: facing, | 23 | cameraDirection: facing, |
| 23 | isInitialized: false, | 24 | isInitialized: false, |
| 25 | + isRunning: false, | ||
| 24 | size: Size.zero, | 26 | size: Size.zero, |
| 25 | torchState: TorchState.unavailable, | 27 | torchState: TorchState.unavailable, |
| 26 | zoomScale: 1.0, | 28 | zoomScale: 1.0, |
| @@ -33,8 +35,15 @@ class MobileScannerState { | @@ -33,8 +35,15 @@ class MobileScannerState { | ||
| 33 | final MobileScannerException? error; | 35 | final MobileScannerException? error; |
| 34 | 36 | ||
| 35 | /// Whether the mobile scanner has initialized successfully. | 37 | /// Whether the mobile scanner has initialized successfully. |
| 38 | + /// | ||
| 39 | + /// This is `true` if the camera is ready to be used. | ||
| 36 | final bool isInitialized; | 40 | final bool isInitialized; |
| 37 | 41 | ||
| 42 | + /// Whether the mobile scanner is currently running. | ||
| 43 | + /// | ||
| 44 | + /// This is `true` if the camera is active. | ||
| 45 | + final bool isRunning; | ||
| 46 | + | ||
| 38 | /// The size of the camera output. | 47 | /// The size of the camera output. |
| 39 | final Size size; | 48 | final Size size; |
| 40 | 49 | ||
| @@ -49,6 +58,7 @@ class MobileScannerState { | @@ -49,6 +58,7 @@ class MobileScannerState { | ||
| 49 | CameraFacing? cameraDirection, | 58 | CameraFacing? cameraDirection, |
| 50 | MobileScannerException? error, | 59 | MobileScannerException? error, |
| 51 | bool? isInitialized, | 60 | bool? isInitialized, |
| 61 | + bool? isRunning, | ||
| 52 | Size? size, | 62 | Size? size, |
| 53 | TorchState? torchState, | 63 | TorchState? torchState, |
| 54 | double? zoomScale, | 64 | double? zoomScale, |
| @@ -57,6 +67,7 @@ class MobileScannerState { | @@ -57,6 +67,7 @@ class MobileScannerState { | ||
| 57 | cameraDirection: cameraDirection ?? this.cameraDirection, | 67 | cameraDirection: cameraDirection ?? this.cameraDirection, |
| 58 | error: error, | 68 | error: error, |
| 59 | isInitialized: isInitialized ?? this.isInitialized, | 69 | isInitialized: isInitialized ?? this.isInitialized, |
| 70 | + isRunning: isRunning ?? this.isRunning, | ||
| 60 | size: size ?? this.size, | 71 | size: size ?? this.size, |
| 61 | torchState: torchState ?? this.torchState, | 72 | torchState: torchState ?? this.torchState, |
| 62 | zoomScale: zoomScale ?? this.zoomScale, | 73 | zoomScale: zoomScale ?? this.zoomScale, |
-
Please register or login to post a comment