Navaron Bracke

rename nrOfCameras to numberOfCameras

1 ## 3.5.6 1 ## 3.5.6
2 Bugs fixed: 2 Bugs fixed:
3 -* [web] Fixed a crash with the ZXing barcode format (@thanks @hazzo!) 3 +* [web] Fixed a crash with the ZXing barcode format (thanks @hazzo!)
4 * [web] Fixed stream controller not being closed on web. 4 * [web] Fixed stream controller not being closed on web.
5 * [iOS] Fixed a crash with unsupported torch modes. (thanks @navaronbracke !) 5 * [iOS] Fixed a crash with unsupported torch modes. (thanks @navaronbracke !)
6 * [iOS] Fixed a crash with the camera discovery session. (thanks @navaronbracke !) 6 * [iOS] Fixed a crash with the camera discovery session. (thanks @navaronbracke !)
@@ -8,7 +8,7 @@ Bugs fixed: @@ -8,7 +8,7 @@ Bugs fixed:
8 Improvements: 8 Improvements:
9 * Upgrade camera dependencies on Android. 9 * Upgrade camera dependencies on Android.
10 * Upgrade compileSdk version to 34 on Android. 10 * Upgrade compileSdk version to 34 on Android.
11 -* Add nrOfCameras parameter in MobileScannerArguments callback, which shows how many cameras there are available on Android. 11 +* Add numberOfCameras parameter in MobileScannerArguments callback, which shows how many cameras there are available on Android.
12 * [Android] Migrated to ResolutionSelector with ResolutionStrategy. You can opt in into the new selector by setting [useNewCameraSelector] in the [MobileScannerController] to true. 12 * [Android] Migrated to ResolutionSelector with ResolutionStrategy. You can opt in into the new selector by setting [useNewCameraSelector] in the [MobileScannerController] to true.
13 13
14 ## 3.5.5 14 ## 3.5.5
@@ -250,7 +250,7 @@ class MobileScanner( @@ -250,7 +250,7 @@ class MobileScanner(
250 250
251 cameraProviderFuture.addListener({ 251 cameraProviderFuture.addListener({
252 cameraProvider = cameraProviderFuture.get() 252 cameraProvider = cameraProviderFuture.get()
253 - val nrOfCameras = cameraProvider?.availableCameraInfos?.size 253 + val numberOfCameras = cameraProvider?.availableCameraInfos?.size
254 254
255 if (cameraProvider == null) { 255 if (cameraProvider == null) {
256 mobileScannerErrorCallback(CameraError()) 256 mobileScannerErrorCallback(CameraError())
@@ -374,7 +374,7 @@ class MobileScanner( @@ -374,7 +374,7 @@ class MobileScanner(
374 if (portrait) height else width, 374 if (portrait) height else width,
375 camera?.cameraInfo?.hasFlashUnit() ?: false, 375 camera?.cameraInfo?.hasFlashUnit() ?: false,
376 textureEntry!!.id(), 376 textureEntry!!.id(),
377 - nrOfCameras ?: 0 377 + numberOfCameras ?: 0
378 ) 378 )
379 ) 379 )
380 }, executor) 380 }, executor)
@@ -180,7 +180,7 @@ class MobileScannerHandler( @@ -180,7 +180,7 @@ class MobileScannerHandler(
180 "textureId" to it.id, 180 "textureId" to it.id,
181 "size" to mapOf("width" to it.width, "height" to it.height), 181 "size" to mapOf("width" to it.width, "height" to it.height),
182 "torchable" to it.hasFlashUnit, 182 "torchable" to it.hasFlashUnit,
183 - "nrOfCameras" to it.nrOfCameras 183 + "numberOfCameras" to it.numberOfCameras
184 )) 184 ))
185 } 185 }
186 }, 186 },
@@ -5,5 +5,5 @@ class MobileScannerStartParameters( @@ -5,5 +5,5 @@ class MobileScannerStartParameters(
5 val height: Double, 5 val height: Double,
6 val hasFlashUnit: Boolean, 6 val hasFlashUnit: Boolean,
7 val id: Long, 7 val id: Long,
8 - val nrOfCameras: Int 8 + val numberOfCameras: Int
9 ) 9 )
@@ -47,7 +47,7 @@ class _BarcodeScannerWithControllerState @@ -47,7 +47,7 @@ class _BarcodeScannerWithControllerState
47 } 47 }
48 } 48 }
49 49
50 - int? nrOfCameras; 50 + int? numberOfCameras;
51 51
52 @override 52 @override
53 Widget build(BuildContext context) { 53 Widget build(BuildContext context) {
@@ -60,8 +60,8 @@ class _BarcodeScannerWithControllerState @@ -60,8 +60,8 @@ class _BarcodeScannerWithControllerState
60 children: [ 60 children: [
61 MobileScanner( 61 MobileScanner(
62 onScannerStarted: (arguments) { 62 onScannerStarted: (arguments) {
63 - if (arguments?.nrOfCameras != null) {  
64 - nrOfCameras = arguments!.nrOfCameras; 63 + if (mounted && arguments?.numberOfCameras != null) {
  64 + numberOfCameras = arguments!.numberOfCameras;
65 setState(() {}); 65 setState(() {});
66 } 66 }
67 }, 67 },
@@ -154,7 +154,7 @@ class _BarcodeScannerWithControllerState @@ -154,7 +154,7 @@ class _BarcodeScannerWithControllerState
154 }, 154 },
155 ), 155 ),
156 iconSize: 32.0, 156 iconSize: 32.0,
157 - onPressed: nrOfCameras != null && nrOfCameras! < 2 157 + onPressed: (numberOfCameras ?? 0) < 2
158 ? null 158 ? null
159 : () => controller.switchCamera(), 159 : () => controller.switchCamera(),
160 ), 160 ),
@@ -229,7 +229,7 @@ class _MobileScannerState extends State<MobileScanner> @@ -229,7 +229,7 @@ class _MobileScannerState extends State<MobileScanner>
229 value.size, 229 value.size,
230 value.webId, 230 value.webId,
231 value.textureId, 231 value.textureId,
232 - value.nrOfCameras, 232 + value.numberOfCameras,
233 ), 233 ),
234 widget.overlay!, 234 widget.overlay!,
235 ], 235 ],
@@ -239,7 +239,7 @@ class _MobileScannerState extends State<MobileScanner> @@ -239,7 +239,7 @@ class _MobileScannerState extends State<MobileScanner>
239 value.size, 239 value.size,
240 value.webId, 240 value.webId,
241 value.textureId, 241 value.textureId,
242 - value.nrOfCameras, 242 + value.numberOfCameras,
243 ); 243 );
244 } 244 }
245 }, 245 },
@@ -248,7 +248,12 @@ class _MobileScannerState extends State<MobileScanner> @@ -248,7 +248,12 @@ class _MobileScannerState extends State<MobileScanner>
248 ); 248 );
249 } 249 }
250 250
251 - Widget _scanner(Size size, String? webId, int? textureId, int? nrOfCameras) { 251 + Widget _scanner(
  252 + Size size,
  253 + String? webId,
  254 + int? textureId,
  255 + int? numberOfCameras,
  256 + ) {
252 return ClipRect( 257 return ClipRect(
253 child: LayoutBuilder( 258 child: LayoutBuilder(
254 builder: (_, constraints) { 259 builder: (_, constraints) {
@@ -312,7 +312,7 @@ class MobileScannerController { @@ -312,7 +312,7 @@ class MobileScannerController {
312 312
313 isStarting = false; 313 isStarting = false;
314 return startArguments.value = MobileScannerArguments( 314 return startArguments.value = MobileScannerArguments(
315 - nrOfCameras: startResult['nrOfCameras'] as int?, 315 + numberOfCameras: startResult['numberOfCameras'] as int?,
316 size: size, 316 size: size,
317 hasTorch: hasTorch, 317 hasTorch: hasTorch,
318 textureId: kIsWeb ? null : startResult['textureId'] as int?, 318 textureId: kIsWeb ? null : startResult['textureId'] as int?,
@@ -16,14 +16,15 @@ class MobileScannerArguments { @@ -16,14 +16,15 @@ class MobileScannerArguments {
16 final String? webId; 16 final String? webId;
17 17
18 /// Indicates how many cameras are available. 18 /// Indicates how many cameras are available.
19 - /// Only available on Android  
20 - final int? nrOfCameras; 19 + ///
  20 + /// Currently only supported on Android.
  21 + final int? numberOfCameras;
21 22
22 MobileScannerArguments({ 23 MobileScannerArguments({
23 required this.size, 24 required this.size,
24 required this.hasTorch, 25 required this.hasTorch,
25 this.textureId, 26 this.textureId,
26 this.webId, 27 this.webId,
27 - this.nrOfCameras, 28 + this.numberOfCameras,
28 }); 29 });
29 } 30 }