Showing
4 changed files
with
20 additions
and
1 deletions
| @@ -264,6 +264,7 @@ class MethodChannelMobileScanner extends MobileScannerPlatform { | @@ -264,6 +264,7 @@ class MethodChannelMobileScanner extends MobileScannerPlatform { | ||
| 264 | 264 | ||
| 265 | _textureId = textureId; | 265 | _textureId = textureId; |
| 266 | 266 | ||
| 267 | + final int? numberOfCameras = startResult['numberOfCameras'] as int?; | ||
| 267 | final bool hasTorch = startResult['torchable'] as bool? ?? false; | 268 | final bool hasTorch = startResult['torchable'] as bool? ?? false; |
| 268 | 269 | ||
| 269 | final Map<Object?, Object?>? sizeInfo = | 270 | final Map<Object?, Object?>? sizeInfo = |
| @@ -279,7 +280,11 @@ class MethodChannelMobileScanner extends MobileScannerPlatform { | @@ -279,7 +280,11 @@ class MethodChannelMobileScanner extends MobileScannerPlatform { | ||
| 279 | size = Size(width, height); | 280 | size = Size(width, height); |
| 280 | } | 281 | } |
| 281 | 282 | ||
| 282 | - return MobileScannerViewAttributes(hasTorch: hasTorch, size: size); | 283 | + return MobileScannerViewAttributes( |
| 284 | + hasTorch: hasTorch, | ||
| 285 | + numberOfCameras: numberOfCameras, | ||
| 286 | + size: size, | ||
| 287 | + ); | ||
| 283 | } | 288 | } |
| 284 | 289 | ||
| 285 | @override | 290 | @override |
| @@ -239,6 +239,7 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> { | @@ -239,6 +239,7 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> { | ||
| 239 | ); | 239 | ); |
| 240 | 240 | ||
| 241 | value = value.copyWith( | 241 | value = value.copyWith( |
| 242 | + availableCameras: viewAttributes.numberOfCameras, | ||
| 242 | cameraDirection: effectiveDirection, | 243 | cameraDirection: effectiveDirection, |
| 243 | isInitialized: true, | 244 | isInitialized: true, |
| 244 | isRunning: true, | 245 | isRunning: true, |
| @@ -4,12 +4,16 @@ import 'dart:ui'; | @@ -4,12 +4,16 @@ import 'dart:ui'; | ||
| 4 | class MobileScannerViewAttributes { | 4 | class MobileScannerViewAttributes { |
| 5 | const MobileScannerViewAttributes({ | 5 | const MobileScannerViewAttributes({ |
| 6 | required this.hasTorch, | 6 | required this.hasTorch, |
| 7 | + this.numberOfCameras, | ||
| 7 | required this.size, | 8 | required this.size, |
| 8 | }); | 9 | }); |
| 9 | 10 | ||
| 10 | /// Whether the current active camera has a torch. | 11 | /// Whether the current active camera has a torch. |
| 11 | final bool hasTorch; | 12 | final bool hasTorch; |
| 12 | 13 | ||
| 14 | + /// The number of available cameras. | ||
| 15 | + final int? numberOfCameras; | ||
| 16 | + | ||
| 13 | /// The size of the camera output. | 17 | /// The size of the camera output. |
| 14 | final Size size; | 18 | final Size size; |
| 15 | } | 19 | } |
| @@ -8,6 +8,7 @@ import 'package:mobile_scanner/src/mobile_scanner_exception.dart'; | @@ -8,6 +8,7 @@ import 'package:mobile_scanner/src/mobile_scanner_exception.dart'; | ||
| 8 | class MobileScannerState { | 8 | class MobileScannerState { |
| 9 | /// Create a new [MobileScannerState] instance. | 9 | /// Create a new [MobileScannerState] instance. |
| 10 | const MobileScannerState({ | 10 | const MobileScannerState({ |
| 11 | + required this.availableCameras, | ||
| 11 | required this.cameraDirection, | 12 | required this.cameraDirection, |
| 12 | required this.isInitialized, | 13 | required this.isInitialized, |
| 13 | required this.isRunning, | 14 | required this.isRunning, |
| @@ -20,6 +21,7 @@ class MobileScannerState { | @@ -20,6 +21,7 @@ class MobileScannerState { | ||
| 20 | /// Create a new [MobileScannerState] instance that is uninitialized. | 21 | /// Create a new [MobileScannerState] instance that is uninitialized. |
| 21 | const MobileScannerState.uninitialized(CameraFacing facing) | 22 | const MobileScannerState.uninitialized(CameraFacing facing) |
| 22 | : this( | 23 | : this( |
| 24 | + availableCameras: null, | ||
| 23 | cameraDirection: facing, | 25 | cameraDirection: facing, |
| 24 | isInitialized: false, | 26 | isInitialized: false, |
| 25 | isRunning: false, | 27 | isRunning: false, |
| @@ -28,6 +30,11 @@ class MobileScannerState { | @@ -28,6 +30,11 @@ class MobileScannerState { | ||
| 28 | zoomScale: 1.0, | 30 | zoomScale: 1.0, |
| 29 | ); | 31 | ); |
| 30 | 32 | ||
| 33 | + /// The number of available cameras. | ||
| 34 | + /// | ||
| 35 | + /// This is null if the number of cameras is unknown. | ||
| 36 | + final int? availableCameras; | ||
| 37 | + | ||
| 31 | /// The facing direction of the camera. | 38 | /// The facing direction of the camera. |
| 32 | final CameraFacing cameraDirection; | 39 | final CameraFacing cameraDirection; |
| 33 | 40 | ||
| @@ -55,6 +62,7 @@ class MobileScannerState { | @@ -55,6 +62,7 @@ class MobileScannerState { | ||
| 55 | 62 | ||
| 56 | /// Create a copy of this state with the given parameters. | 63 | /// Create a copy of this state with the given parameters. |
| 57 | MobileScannerState copyWith({ | 64 | MobileScannerState copyWith({ |
| 65 | + int? availableCameras, | ||
| 58 | CameraFacing? cameraDirection, | 66 | CameraFacing? cameraDirection, |
| 59 | MobileScannerException? error, | 67 | MobileScannerException? error, |
| 60 | bool? isInitialized, | 68 | bool? isInitialized, |
| @@ -64,6 +72,7 @@ class MobileScannerState { | @@ -64,6 +72,7 @@ class MobileScannerState { | ||
| 64 | double? zoomScale, | 72 | double? zoomScale, |
| 65 | }) { | 73 | }) { |
| 66 | return MobileScannerState( | 74 | return MobileScannerState( |
| 75 | + availableCameras: availableCameras ?? this.availableCameras, | ||
| 67 | cameraDirection: cameraDirection ?? this.cameraDirection, | 76 | cameraDirection: cameraDirection ?? this.cameraDirection, |
| 68 | error: error, | 77 | error: error, |
| 69 | isInitialized: isInitialized ?? this.isInitialized, | 78 | isInitialized: isInitialized ?? this.isInitialized, |
-
Please register or login to post a comment