From ca52df97c7f032b0c5b9f91568b7f7556ac2b953 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Fri, 11 Feb 2022 15:34:19 -0500 Subject: [PATCH 1/7] dart fix --- packages/camera/camera/analysis_options.yaml | 1 - .../example/integration_test/camera_test.dart | 22 +- packages/camera/camera/example/lib/main.dart | 76 ++-- packages/camera/camera/lib/camera.dart | 8 +- .../camera/lib/src/camera_controller.dart | 68 ++-- .../camera/camera/lib/src/camera_image.dart | 2 +- .../camera/camera/lib/src/camera_preview.dart | 4 +- .../camera/test/camera_image_stream_test.dart | 68 ++-- .../camera/camera/test/camera_image_test.dart | 10 +- .../camera/test/camera_preview_test.dart | 28 +- packages/camera/camera/test/camera_test.dart | 334 +++++++++--------- .../camera/camera/test/camera_value_test.dart | 26 +- .../test/utils/method_channel_mock.dart | 2 +- script/configs/custom_analysis.yaml | 1 - 14 files changed, 323 insertions(+), 327 deletions(-) delete mode 100644 packages/camera/camera/analysis_options.yaml diff --git a/packages/camera/camera/analysis_options.yaml b/packages/camera/camera/analysis_options.yaml deleted file mode 100644 index 5aeb4e7c5e21..000000000000 --- a/packages/camera/camera/analysis_options.yaml +++ /dev/null @@ -1 +0,0 @@ -include: ../../../analysis_options_legacy.yaml diff --git a/packages/camera/camera/example/integration_test/camera_test.dart b/packages/camera/camera/example/integration_test/camera_test.dart index 3af291afe63b..c2a88ccc2672 100644 --- a/packages/camera/camera/example/integration_test/camera_test.dart +++ b/packages/camera/camera/example/integration_test/camera_test.dart @@ -9,9 +9,9 @@ import 'dart:ui'; import 'package:camera/camera.dart'; import 'package:flutter/painting.dart'; import 'package:flutter_test/flutter_test.dart'; +import 'package:integration_test/integration_test.dart'; import 'package:path_provider/path_provider.dart'; import 'package:video_player/video_player.dart'; -import 'package:integration_test/integration_test.dart'; void main() { late Directory testDir; @@ -59,7 +59,7 @@ void main() { 'Capturing photo at $preset (${expectedSize.width}x${expectedSize.height}) using camera ${controller.description.name}'); // Take Picture - final file = await controller.takePicture(); + final XFile file = await controller.takePicture(); // Load picture final File fileImage = File(file.path); @@ -78,9 +78,9 @@ void main() { if (cameras.isEmpty) { return; } - for (CameraDescription cameraDescription in cameras) { + for (final CameraDescription cameraDescription in cameras) { bool previousPresetExactlySupported = true; - for (MapEntry preset + for (final MapEntry preset in presetExpectedSizes.entries) { final CameraController controller = CameraController(cameraDescription, preset.key); @@ -110,7 +110,7 @@ void main() { // Take Video await controller.startVideoRecording(); sleep(const Duration(milliseconds: 300)); - final file = await controller.stopVideoRecording(); + final XFile file = await controller.stopVideoRecording(); // Load video metadata final File videoFile = File(file.path); @@ -132,9 +132,9 @@ void main() { if (cameras.isEmpty) { return; } - for (CameraDescription cameraDescription in cameras) { + for (final CameraDescription cameraDescription in cameras) { bool previousPresetExactlySupported = true; - for (MapEntry preset + for (final MapEntry preset in presetExpectedSizes.entries) { final CameraController controller = CameraController(cameraDescription, preset.key); @@ -191,7 +191,7 @@ void main() { sleep(const Duration(milliseconds: 500)); - final file = await controller.stopVideoRecording(); + final XFile file = await controller.stopVideoRecording(); final int recordingTime = DateTime.now().millisecondsSinceEpoch - recordingStart; @@ -252,14 +252,14 @@ void main() { ); await controller.initialize(); - final _completer = Completer(); + final Completer _completer = Completer(); await controller.startImageStream((CameraImage image) { if (!_completer.isCompleted) { Future(() async { await controller.stopImageStream(); await controller.dispose(); - }).then((value) { + }).then((Object? value) { _completer.complete(image); }); } @@ -275,7 +275,7 @@ void main() { return; } - var _image = await startStreaming(cameras, null); + CameraImage _image = await startStreaming(cameras, null); expect(_image, isNotNull); expect(_image.format.group, ImageFormatGroup.bgra8888); expect(_image.planes.length, 1); diff --git a/packages/camera/camera/example/lib/main.dart b/packages/camera/camera/example/lib/main.dart index a3a5d1d46391..198cd67a3051 100644 --- a/packages/camera/camera/example/lib/main.dart +++ b/packages/camera/camera/example/lib/main.dart @@ -194,7 +194,7 @@ class _CameraExampleHomeState extends State behavior: HitTestBehavior.opaque, onScaleStart: _handleScaleStart, onScaleUpdate: _handleScaleUpdate, - onTapDown: (details) => onViewFinderTap(details, constraints), + onTapDown: (TapDownDetails details) => onViewFinderTap(details, constraints), ); }), ), @@ -228,9 +228,7 @@ class _CameraExampleHomeState extends State child: Row( mainAxisSize: MainAxisSize.min, children: [ - localVideoController == null && imageFile == null - ? Container() - : SizedBox( + if (localVideoController == null && imageFile == null) Container() else SizedBox( child: (localVideoController == null) ? ( // The captured image on the web contains a network-accessible URL @@ -271,28 +269,28 @@ class _CameraExampleHomeState extends State mainAxisSize: MainAxisSize.max, children: [ IconButton( - icon: Icon(Icons.flash_on), + icon: const Icon(Icons.flash_on), color: Colors.blue, onPressed: controller != null ? onFlashModeButtonPressed : null, ), // The exposure and focus mode are currently not supported on the web. - ...(!kIsWeb + ...!kIsWeb ? [ IconButton( - icon: Icon(Icons.exposure), + icon: const Icon(Icons.exposure), color: Colors.blue, onPressed: controller != null ? onExposureModeButtonPressed : null, ), IconButton( - icon: Icon(Icons.filter_center_focus), + icon: const Icon(Icons.filter_center_focus), color: Colors.blue, onPressed: controller != null ? onFocusModeButtonPressed : null, ) ] - : []), + : [], IconButton( icon: Icon(enableAudio ? Icons.volume_up : Icons.volume_mute), color: Colors.blue, @@ -325,7 +323,7 @@ class _CameraExampleHomeState extends State mainAxisSize: MainAxisSize.max, children: [ IconButton( - icon: Icon(Icons.flash_off), + icon: const Icon(Icons.flash_off), color: controller?.value.flashMode == FlashMode.off ? Colors.orange : Colors.blue, @@ -334,7 +332,7 @@ class _CameraExampleHomeState extends State : null, ), IconButton( - icon: Icon(Icons.flash_auto), + icon: const Icon(Icons.flash_auto), color: controller?.value.flashMode == FlashMode.auto ? Colors.orange : Colors.blue, @@ -343,7 +341,7 @@ class _CameraExampleHomeState extends State : null, ), IconButton( - icon: Icon(Icons.flash_on), + icon: const Icon(Icons.flash_on), color: controller?.value.flashMode == FlashMode.always ? Colors.orange : Colors.blue, @@ -352,7 +350,7 @@ class _CameraExampleHomeState extends State : null, ), IconButton( - icon: Icon(Icons.highlight), + icon: const Icon(Icons.highlight), color: controller?.value.flashMode == FlashMode.torch ? Colors.orange : Colors.blue, @@ -385,15 +383,15 @@ class _CameraExampleHomeState extends State color: Colors.grey.shade50, child: Column( children: [ - Center( - child: Text("Exposure Mode"), + const Center( + child: Text('Exposure Mode'), ), Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, mainAxisSize: MainAxisSize.max, children: [ TextButton( - child: Text('AUTO'), + child: const Text('AUTO'), style: styleAuto, onPressed: controller != null ? () => @@ -407,7 +405,7 @@ class _CameraExampleHomeState extends State }, ), TextButton( - child: Text('LOCKED'), + child: const Text('LOCKED'), style: styleLocked, onPressed: controller != null ? () => @@ -415,7 +413,7 @@ class _CameraExampleHomeState extends State : null, ), TextButton( - child: Text('RESET OFFSET'), + child: const Text('RESET OFFSET'), style: styleLocked, onPressed: controller != null ? () => controller!.setExposureOffset(0.0) @@ -423,8 +421,8 @@ class _CameraExampleHomeState extends State ), ], ), - Center( - child: Text("Exposure Offset"), + const Center( + child: Text('Exposure Offset'), ), Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, @@ -470,15 +468,15 @@ class _CameraExampleHomeState extends State color: Colors.grey.shade50, child: Column( children: [ - Center( - child: Text("Focus Mode"), + const Center( + child: Text('Focus Mode'), ), Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, mainAxisSize: MainAxisSize.max, children: [ TextButton( - child: Text('AUTO'), + child: const Text('AUTO'), style: styleAuto, onPressed: controller != null ? () => onSetFocusModeButtonPressed(FocusMode.auto) @@ -489,7 +487,7 @@ class _CameraExampleHomeState extends State }, ), TextButton( - child: Text('LOCKED'), + child: const Text('LOCKED'), style: styleLocked, onPressed: controller != null ? () => onSetFocusModeButtonPressed(FocusMode.locked) @@ -533,8 +531,8 @@ class _CameraExampleHomeState extends State IconButton( icon: cameraController != null && cameraController.value.isRecordingPaused - ? Icon(Icons.play_arrow) - : Icon(Icons.pause), + ? const Icon(Icons.play_arrow) + : const Icon(Icons.pause), color: Colors.blue, onPressed: cameraController != null && cameraController.value.isInitialized && @@ -570,7 +568,7 @@ class _CameraExampleHomeState extends State Widget _cameraTogglesRowWidget() { final List toggles = []; - final onChanged = (CameraDescription? description) { + final Null Function(CameraDescription? description) onChanged = (CameraDescription? description) { if (description == null) { return; } @@ -581,7 +579,7 @@ class _CameraExampleHomeState extends State if (cameras.isEmpty) { return const Text('No camera found'); } else { - for (CameraDescription cameraDescription in cameras) { + for (final CameraDescription cameraDescription in cameras) { toggles.add( SizedBox( width: 90.0, @@ -616,7 +614,7 @@ class _CameraExampleHomeState extends State final CameraController cameraController = controller!; - final offset = Offset( + final Offset offset = Offset( details.localPosition.dx / constraints.maxWidth, details.localPosition.dy / constraints.maxHeight, ); @@ -651,22 +649,22 @@ class _CameraExampleHomeState extends State await cameraController.initialize(); await Future.wait([ // The exposure mode is currently not supported on the web. - ...(!kIsWeb + ...!kIsWeb ? [ cameraController .getMinExposureOffset() - .then((value) => _minAvailableExposureOffset = value), + .then((double value) => _minAvailableExposureOffset = value), cameraController .getMaxExposureOffset() - .then((value) => _maxAvailableExposureOffset = value) + .then((double value) => _maxAvailableExposureOffset = value) ] - : []), + : [], cameraController .getMaxZoomLevel() - .then((value) => _maxAvailableZoom = value), + .then((double value) => _maxAvailableZoom = value), cameraController .getMinZoomLevel() - .then((value) => _minAvailableZoom = value), + .then((double value) => _minAvailableZoom = value), ]); } on CameraException catch (e) { _showCameraException(e); @@ -773,7 +771,7 @@ class _CameraExampleHomeState extends State } void onStopButtonPressed() { - stopVideoRecording().then((file) { + stopVideoRecording().then((XFile? file) { if (mounted) setState(() {}); if (file != null) { showInSnackBar('Video recorded to ${file.path}'); @@ -854,7 +852,7 @@ class _CameraExampleHomeState extends State final CameraController? cameraController = controller; if (cameraController == null || !cameraController.value.isRecordingVideo) { - return null; + return; } try { @@ -869,7 +867,7 @@ class _CameraExampleHomeState extends State final CameraController? cameraController = controller; if (cameraController == null || !cameraController.value.isRecordingVideo) { - return null; + return; } try { @@ -977,7 +975,7 @@ class _CameraExampleHomeState extends State } try { - XFile file = await cameraController.takePicture(); + final XFile file = await cameraController.takePicture(); return file; } on CameraException catch (e) { _showCameraException(e); diff --git a/packages/camera/camera/lib/camera.dart b/packages/camera/camera/lib/camera.dart index 1e24efbd3dc6..900c2633a5d7 100644 --- a/packages/camera/camera/lib/camera.dart +++ b/packages/camera/camera/lib/camera.dart @@ -2,10 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -export 'src/camera_controller.dart'; -export 'src/camera_image.dart'; -export 'src/camera_preview.dart'; - export 'package:camera_platform_interface/camera_platform_interface.dart' show CameraDescription, @@ -17,3 +13,7 @@ export 'package:camera_platform_interface/camera_platform_interface.dart' ResolutionPreset, XFile, ImageFormatGroup; + +export 'src/camera_controller.dart'; +export 'src/camera_image.dart'; +export 'src/camera_preview.dart'; diff --git a/packages/camera/camera/lib/src/camera_controller.dart b/packages/camera/camera/lib/src/camera_controller.dart index 8cf1e90e36c1..ed8dd524ad10 100644 --- a/packages/camera/camera/lib/src/camera_controller.dart +++ b/packages/camera/camera/lib/src/camera_controller.dart @@ -13,7 +13,7 @@ import 'package:flutter/services.dart'; import 'package:pedantic/pedantic.dart'; import 'package:quiver/core.dart'; -final MethodChannel _channel = const MethodChannel('plugins.flutter.io/camera'); +const MethodChannel _channel = MethodChannel('plugins.flutter.io/camera'); /// Signature for a callback receiving the a camera image. /// @@ -277,10 +277,10 @@ class CameraController extends ValueNotifier { ); } try { - Completer _initializeCompleter = Completer(); + final Completer _initializeCompleter = Completer(); _deviceOrientationSubscription = - CameraPlatform.instance.onDeviceOrientationChanged().listen((event) { + CameraPlatform.instance.onDeviceOrientationChanged().listen((DeviceOrientationChangedEvent event) { value = value.copyWith( deviceOrientation: event.orientation, ); @@ -295,7 +295,7 @@ class CameraController extends ValueNotifier { unawaited(CameraPlatform.instance .onCameraInitialized(_cameraId) .first - .then((event) { + .then((CameraInitializedEvent event) { _initializeCompleter.complete(event); })); @@ -312,13 +312,13 @@ class CameraController extends ValueNotifier { event.previewHeight, )), exposureMode: await _initializeCompleter.future - .then((event) => event.exposureMode), + .then((CameraInitializedEvent event) => event.exposureMode), focusMode: - await _initializeCompleter.future.then((event) => event.focusMode), + await _initializeCompleter.future.then((CameraInitializedEvent event) => event.focusMode), exposurePointSupported: await _initializeCompleter.future - .then((event) => event.exposurePointSupported), + .then((CameraInitializedEvent event) => event.exposurePointSupported), focusPointSupported: await _initializeCompleter.future - .then((event) => event.focusPointSupported), + .then((CameraInitializedEvent event) => event.focusPointSupported), ); } on PlatformException catch (e) { throw CameraException(e.code, e.message); @@ -351,7 +351,7 @@ class CameraController extends ValueNotifier { await CameraPlatform.instance.pausePreview(_cameraId); value = value.copyWith( isPreviewPaused: true, - previewPauseOrientation: Optional.of(this.value.deviceOrientation)); + previewPauseOrientation: Optional.of(value.deviceOrientation)); } on PlatformException catch (e) { throw CameraException(e.code, e.message); } @@ -365,7 +365,7 @@ class CameraController extends ValueNotifier { try { await CameraPlatform.instance.resumePreview(_cameraId); value = value.copyWith( - isPreviewPaused: false, previewPauseOrientation: Optional.absent()); + isPreviewPaused: false, previewPauseOrientation: const Optional.absent()); } on PlatformException catch (e) { throw CameraException(e.code, e.message); } @@ -375,7 +375,7 @@ class CameraController extends ValueNotifier { /// /// Throws a [CameraException] if the capture fails. Future takePicture() async { - _throwIfNotInitialized("takePicture"); + _throwIfNotInitialized('takePicture'); if (value.isTakingPicture) { throw CameraException( 'Previous capture has not returned yet.', @@ -384,7 +384,7 @@ class CameraController extends ValueNotifier { } try { value = value.copyWith(isTakingPicture: true); - XFile file = await CameraPlatform.instance.takePicture(_cameraId); + final XFile file = await CameraPlatform.instance.takePicture(_cameraId); value = value.copyWith(isTakingPicture: false); return file; } on PlatformException catch (e) { @@ -413,7 +413,7 @@ class CameraController extends ValueNotifier { Future startImageStream(onLatestImageAvailable onAvailable) async { assert(defaultTargetPlatform == TargetPlatform.android || defaultTargetPlatform == TargetPlatform.iOS); - _throwIfNotInitialized("startImageStream"); + _throwIfNotInitialized('startImageStream'); if (value.isRecordingVideo) { throw CameraException( 'A video recording is already started.', @@ -453,7 +453,7 @@ class CameraController extends ValueNotifier { Future stopImageStream() async { assert(defaultTargetPlatform == TargetPlatform.android || defaultTargetPlatform == TargetPlatform.iOS); - _throwIfNotInitialized("stopImageStream"); + _throwIfNotInitialized('stopImageStream'); if (value.isRecordingVideo) { throw CameraException( 'A video recording is already started.', @@ -483,7 +483,7 @@ class CameraController extends ValueNotifier { /// The video is returned as a [XFile] after calling [stopVideoRecording]. /// Throws a [CameraException] if the capture fails. Future startVideoRecording() async { - _throwIfNotInitialized("startVideoRecording"); + _throwIfNotInitialized('startVideoRecording'); if (value.isRecordingVideo) { throw CameraException( 'A video recording is already started.', @@ -513,7 +513,7 @@ class CameraController extends ValueNotifier { /// /// Throws a [CameraException] if the capture failed. Future stopVideoRecording() async { - _throwIfNotInitialized("stopVideoRecording"); + _throwIfNotInitialized('stopVideoRecording'); if (!value.isRecordingVideo) { throw CameraException( 'No video is recording', @@ -521,10 +521,10 @@ class CameraController extends ValueNotifier { ); } try { - XFile file = await CameraPlatform.instance.stopVideoRecording(_cameraId); + final XFile file = await CameraPlatform.instance.stopVideoRecording(_cameraId); value = value.copyWith( isRecordingVideo: false, - recordingOrientation: Optional.absent(), + recordingOrientation: const Optional.absent(), ); return file; } on PlatformException catch (e) { @@ -536,7 +536,7 @@ class CameraController extends ValueNotifier { /// /// This feature is only available on iOS and Android sdk 24+. Future pauseVideoRecording() async { - _throwIfNotInitialized("pauseVideoRecording"); + _throwIfNotInitialized('pauseVideoRecording'); if (!value.isRecordingVideo) { throw CameraException( 'No video is recording', @@ -555,7 +555,7 @@ class CameraController extends ValueNotifier { /// /// This feature is only available on iOS and Android sdk 24+. Future resumeVideoRecording() async { - _throwIfNotInitialized("resumeVideoRecording"); + _throwIfNotInitialized('resumeVideoRecording'); if (!value.isRecordingVideo) { throw CameraException( 'No video is recording', @@ -572,7 +572,7 @@ class CameraController extends ValueNotifier { /// Returns a widget showing a live camera preview. Widget buildPreview() { - _throwIfNotInitialized("buildPreview"); + _throwIfNotInitialized('buildPreview'); try { return CameraPlatform.instance.buildPreview(_cameraId); } on PlatformException catch (e) { @@ -582,7 +582,7 @@ class CameraController extends ValueNotifier { /// Gets the maximum supported zoom level for the selected camera. Future getMaxZoomLevel() { - _throwIfNotInitialized("getMaxZoomLevel"); + _throwIfNotInitialized('getMaxZoomLevel'); try { return CameraPlatform.instance.getMaxZoomLevel(_cameraId); } on PlatformException catch (e) { @@ -592,7 +592,7 @@ class CameraController extends ValueNotifier { /// Gets the minimum supported zoom level for the selected camera. Future getMinZoomLevel() { - _throwIfNotInitialized("getMinZoomLevel"); + _throwIfNotInitialized('getMinZoomLevel'); try { return CameraPlatform.instance.getMinZoomLevel(_cameraId); } on PlatformException catch (e) { @@ -606,7 +606,7 @@ class CameraController extends ValueNotifier { /// zoom level returned by the `getMaxZoomLevel`. Throws an `CameraException` /// when an illegal zoom level is suplied. Future setZoomLevel(double zoom) { - _throwIfNotInitialized("setZoomLevel"); + _throwIfNotInitialized('setZoomLevel'); try { return CameraPlatform.instance.setZoomLevel(_cameraId, zoom); } on PlatformException catch (e) { @@ -662,7 +662,7 @@ class CameraController extends ValueNotifier { /// Gets the minimum supported exposure offset for the selected camera in EV units. Future getMinExposureOffset() async { - _throwIfNotInitialized("getMinExposureOffset"); + _throwIfNotInitialized('getMinExposureOffset'); try { return CameraPlatform.instance.getMinExposureOffset(_cameraId); } on PlatformException catch (e) { @@ -672,7 +672,7 @@ class CameraController extends ValueNotifier { /// Gets the maximum supported exposure offset for the selected camera in EV units. Future getMaxExposureOffset() async { - _throwIfNotInitialized("getMaxExposureOffset"); + _throwIfNotInitialized('getMaxExposureOffset'); try { return CameraPlatform.instance.getMaxExposureOffset(_cameraId); } on PlatformException catch (e) { @@ -684,7 +684,7 @@ class CameraController extends ValueNotifier { /// /// Returns 0 when the camera supports using a free value without stepping. Future getExposureOffsetStepSize() async { - _throwIfNotInitialized("getExposureOffsetStepSize"); + _throwIfNotInitialized('getExposureOffsetStepSize'); try { return CameraPlatform.instance.getExposureOffsetStepSize(_cameraId); } on PlatformException catch (e) { @@ -704,21 +704,21 @@ class CameraController extends ValueNotifier { /// /// Returns the (rounded) offset value that was set. Future setExposureOffset(double offset) async { - _throwIfNotInitialized("setExposureOffset"); + _throwIfNotInitialized('setExposureOffset'); // Check if offset is in range - List range = + final List range = await Future.wait([getMinExposureOffset(), getMaxExposureOffset()]); if (offset < range[0] || offset > range[1]) { throw CameraException( - "exposureOffsetOutOfBounds", - "The provided exposure offset was outside the supported range for this device.", + 'exposureOffsetOutOfBounds', + 'The provided exposure offset was outside the supported range for this device.', ); } // Round to the closest step if needed - double stepSize = await getExposureOffsetStepSize(); + final double stepSize = await getExposureOffsetStepSize(); if (stepSize > 0) { - double inv = 1.0 / stepSize; + final double inv = 1.0 / stepSize; double roundedOffset = (offset * inv).roundToDouble() / inv; if (roundedOffset > range[1]) { roundedOffset = (offset * inv).floorToDouble() / inv; @@ -764,7 +764,7 @@ class CameraController extends ValueNotifier { Future unlockCaptureOrientation() async { try { await CameraPlatform.instance.unlockCaptureOrientation(_cameraId); - value = value.copyWith(lockedCaptureOrientation: Optional.absent()); + value = value.copyWith(lockedCaptureOrientation: const Optional.absent()); } on PlatformException catch (e) { throw CameraException(e.code, e.message); } diff --git a/packages/camera/camera/lib/src/camera_image.dart b/packages/camera/camera/lib/src/camera_image.dart index 43fa763bed48..a57e307c7c85 100644 --- a/packages/camera/camera/lib/src/camera_image.dart +++ b/packages/camera/camera/lib/src/camera_image.dart @@ -4,9 +4,9 @@ import 'dart:typed_data'; +import 'package:camera_platform_interface/camera_platform_interface.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; -import 'package:camera_platform_interface/camera_platform_interface.dart'; /// A single color plane of image data. /// diff --git a/packages/camera/camera/lib/src/camera_preview.dart b/packages/camera/camera/lib/src/camera_preview.dart index 5faa69f3cb9d..3b6d6f8931ef 100644 --- a/packages/camera/camera/lib/src/camera_preview.dart +++ b/packages/camera/camera/lib/src/camera_preview.dart @@ -23,7 +23,7 @@ class CameraPreview extends StatelessWidget { return controller.value.isInitialized ? ValueListenableBuilder( valueListenable: controller, - builder: (context, value, child) { + builder: (BuildContext context, Object? value, Widget? child) { return AspectRatio( aspectRatio: _isLandscape() ? controller.value.aspectRatio @@ -59,7 +59,7 @@ class CameraPreview extends StatelessWidget { } int _getQuarterTurns() { - Map turns = { + final Map turns = { DeviceOrientation.portraitUp: 0, DeviceOrientation.landscapeRight: 1, DeviceOrientation.portraitDown: 2, diff --git a/packages/camera/camera/test/camera_image_stream_test.dart b/packages/camera/camera/test/camera_image_stream_test.dart index 840770d1eed7..8dddd3f79e3f 100644 --- a/packages/camera/camera/test/camera_image_stream_test.dart +++ b/packages/camera/camera/test/camera_image_stream_test.dart @@ -17,24 +17,24 @@ void main() { }); test('startImageStream() throws $CameraException when uninitialized', () { - CameraController cameraController = CameraController( - CameraDescription( + final CameraController cameraController = CameraController( + const CameraDescription( name: 'cam', lensDirection: CameraLensDirection.back, sensorOrientation: 90), ResolutionPreset.max); expect( - () => cameraController.startImageStream((image) => null), + () => cameraController.startImageStream((CameraImage image) => null), throwsA( isA() .having( - (error) => error.code, + (CameraException error) => error.code, 'code', 'Uninitialized CameraController', ) .having( - (error) => error.description, + (CameraException error) => error.description, 'description', 'startImageStream() was called on an uninitialized CameraController.', ), @@ -44,8 +44,8 @@ void main() { test('startImageStream() throws $CameraException when recording videos', () async { - CameraController cameraController = CameraController( - CameraDescription( + final CameraController cameraController = CameraController( + const CameraDescription( name: 'cam', lensDirection: CameraLensDirection.back, sensorOrientation: 90), @@ -57,9 +57,9 @@ void main() { cameraController.value.copyWith(isRecordingVideo: true); expect( - () => cameraController.startImageStream((image) => null), + () => cameraController.startImageStream((CameraImage image) => null), throwsA(isA().having( - (error) => error.description, + (CameraException error) => error.description, 'A video recording is already started.', 'startImageStream was called while a video is being recorded.', ))); @@ -67,8 +67,8 @@ void main() { test( 'startImageStream() throws $CameraException when already streaming images', () async { - CameraController cameraController = CameraController( - CameraDescription( + final CameraController cameraController = CameraController( + const CameraDescription( name: 'cam', lensDirection: CameraLensDirection.back, sensorOrientation: 90), @@ -78,31 +78,31 @@ void main() { cameraController.value = cameraController.value.copyWith(isStreamingImages: true); expect( - () => cameraController.startImageStream((image) => null), + () => cameraController.startImageStream((CameraImage image) => null), throwsA(isA().having( - (error) => error.description, + (CameraException error) => error.description, 'A camera has started streaming images.', 'startImageStream was called while a camera was streaming images.', ))); }); test('startImageStream() calls CameraPlatform', () async { - MethodChannelMock cameraChannelMock = MethodChannelMock( + final MethodChannelMock cameraChannelMock = MethodChannelMock( channelName: 'plugins.flutter.io/camera', methods: {'startImageStream': {}}); - MethodChannelMock streamChannelMock = MethodChannelMock( + final MethodChannelMock streamChannelMock = MethodChannelMock( channelName: 'plugins.flutter.io/camera/imageStream', methods: {'listen': {}}); - CameraController cameraController = CameraController( - CameraDescription( + final CameraController cameraController = CameraController( + const CameraDescription( name: 'cam', lensDirection: CameraLensDirection.back, sensorOrientation: 90), ResolutionPreset.max); await cameraController.initialize(); - await cameraController.startImageStream((image) => null); + await cameraController.startImageStream((CameraImage image) => null); expect(cameraChannelMock.log, [isMethodCall('startImageStream', arguments: null)]); @@ -111,8 +111,8 @@ void main() { }); test('stopImageStream() throws $CameraException when uninitialized', () { - CameraController cameraController = CameraController( - CameraDescription( + final CameraController cameraController = CameraController( + const CameraDescription( name: 'cam', lensDirection: CameraLensDirection.back, sensorOrientation: 90), @@ -123,12 +123,12 @@ void main() { throwsA( isA() .having( - (error) => error.code, + (CameraException error) => error.code, 'code', 'Uninitialized CameraController', ) .having( - (error) => error.description, + (CameraException error) => error.description, 'description', 'stopImageStream() was called on an uninitialized CameraController.', ), @@ -138,21 +138,21 @@ void main() { test('stopImageStream() throws $CameraException when recording videos', () async { - CameraController cameraController = CameraController( - CameraDescription( + final CameraController cameraController = CameraController( + const CameraDescription( name: 'cam', lensDirection: CameraLensDirection.back, sensorOrientation: 90), ResolutionPreset.max); await cameraController.initialize(); - await cameraController.startImageStream((image) => null); + await cameraController.startImageStream((CameraImage image) => null); cameraController.value = cameraController.value.copyWith(isRecordingVideo: true); expect( cameraController.stopImageStream, throwsA(isA().having( - (error) => error.description, + (CameraException error) => error.description, 'A video recording is already started.', 'stopImageStream was called while a video is being recorded.', ))); @@ -160,8 +160,8 @@ void main() { test('stopImageStream() throws $CameraException when not streaming images', () async { - CameraController cameraController = CameraController( - CameraDescription( + final CameraController cameraController = CameraController( + const CameraDescription( name: 'cam', lensDirection: CameraLensDirection.back, sensorOrientation: 90), @@ -171,28 +171,28 @@ void main() { expect( cameraController.stopImageStream, throwsA(isA().having( - (error) => error.description, + (CameraException error) => error.description, 'No camera is streaming images', 'stopImageStream was called when no camera is streaming images.', ))); }); test('stopImageStream() intended behaviour', () async { - MethodChannelMock cameraChannelMock = MethodChannelMock( + final MethodChannelMock cameraChannelMock = MethodChannelMock( channelName: 'plugins.flutter.io/camera', methods: {'startImageStream': {}, 'stopImageStream': {}}); - MethodChannelMock streamChannelMock = MethodChannelMock( + final MethodChannelMock streamChannelMock = MethodChannelMock( channelName: 'plugins.flutter.io/camera/imageStream', methods: {'listen': {}, 'cancel': {}}); - CameraController cameraController = CameraController( - CameraDescription( + final CameraController cameraController = CameraController( + const CameraDescription( name: 'cam', lensDirection: CameraLensDirection.back, sensorOrientation: 90), ResolutionPreset.max); await cameraController.initialize(); - await cameraController.startImageStream((image) => null); + await cameraController.startImageStream((CameraImage image) => null); await cameraController.stopImageStream(); expect(cameraChannelMock.log, [ diff --git a/packages/camera/camera/test/camera_image_test.dart b/packages/camera/camera/test/camera_image_test.dart index 85d613f41485..817d8da2fe65 100644 --- a/packages/camera/camera/test/camera_image_test.dart +++ b/packages/camera/camera/test/camera_image_test.dart @@ -14,7 +14,7 @@ void main() { group('$CameraImage tests', () { test('$CameraImage can be created', () { debugDefaultTargetPlatformOverride = TargetPlatform.android; - CameraImage cameraImage = CameraImage.fromPlatformData({ + final CameraImage cameraImage = CameraImage.fromPlatformData({ 'format': 35, 'height': 1, 'width': 4, @@ -40,7 +40,7 @@ void main() { test('$CameraImage has ImageFormatGroup.yuv420 for iOS', () { debugDefaultTargetPlatformOverride = TargetPlatform.iOS; - CameraImage cameraImage = CameraImage.fromPlatformData({ + final CameraImage cameraImage = CameraImage.fromPlatformData({ 'format': 875704438, 'height': 1, 'width': 4, @@ -63,7 +63,7 @@ void main() { test('$CameraImage has ImageFormatGroup.yuv420 for Android', () { debugDefaultTargetPlatformOverride = TargetPlatform.android; - CameraImage cameraImage = CameraImage.fromPlatformData({ + final CameraImage cameraImage = CameraImage.fromPlatformData({ 'format': 35, 'height': 1, 'width': 4, @@ -86,7 +86,7 @@ void main() { test('$CameraImage has ImageFormatGroup.bgra8888 for iOS', () { debugDefaultTargetPlatformOverride = TargetPlatform.iOS; - CameraImage cameraImage = CameraImage.fromPlatformData({ + final CameraImage cameraImage = CameraImage.fromPlatformData({ 'format': 1111970369, 'height': 1, 'width': 4, @@ -106,7 +106,7 @@ void main() { expect(cameraImage.format.group, ImageFormatGroup.bgra8888); }); test('$CameraImage has ImageFormatGroup.unknown', () { - CameraImage cameraImage = CameraImage.fromPlatformData({ + final CameraImage cameraImage = CameraImage.fromPlatformData({ 'format': null, 'height': 1, 'width': 4, diff --git a/packages/camera/camera/test/camera_preview_test.dart b/packages/camera/camera/test/camera_preview_test.dart index 32718f4d5169..2adb09446cd9 100644 --- a/packages/camera/camera/test/camera_preview_test.dart +++ b/packages/camera/camera/test/camera_preview_test.dart @@ -23,7 +23,7 @@ class FakeController extends ValueNotifier @override Widget buildPreview() { - return Texture(textureId: CameraController.kUninitializedCameraId); + return const Texture(textureId: CameraController.kUninitializedCameraId); } @override @@ -33,7 +33,7 @@ class FakeController extends ValueNotifier void debugCheckIsDisposed() {} @override - CameraDescription get description => CameraDescription( + CameraDescription get description => const CameraDescription( name: '', lensDirection: CameraLensDirection.back, sensorOrientation: 0); @override @@ -136,10 +136,10 @@ void main() { isRecordingVideo: true, deviceOrientation: DeviceOrientation.portraitUp, lockedCaptureOrientation: - Optional.fromNullable(DeviceOrientation.landscapeRight), + const Optional.fromNullable(DeviceOrientation.landscapeRight), recordingOrientation: - Optional.fromNullable(DeviceOrientation.landscapeLeft), - previewSize: Size(480, 640), + const Optional.fromNullable(DeviceOrientation.landscapeLeft), + previewSize: const Size(480, 640), ); await tester.pumpWidget( @@ -150,7 +150,7 @@ void main() { ); expect(find.byType(RotatedBox), findsOneWidget); - RotatedBox rotatedBox = + final RotatedBox rotatedBox = tester.widget(find.byType(RotatedBox)); expect(rotatedBox.quarterTurns, 3); @@ -169,10 +169,10 @@ void main() { isInitialized: true, deviceOrientation: DeviceOrientation.portraitUp, lockedCaptureOrientation: - Optional.fromNullable(DeviceOrientation.landscapeRight), + const Optional.fromNullable(DeviceOrientation.landscapeRight), recordingOrientation: - Optional.fromNullable(DeviceOrientation.landscapeLeft), - previewSize: Size(480, 640), + const Optional.fromNullable(DeviceOrientation.landscapeLeft), + previewSize: const Size(480, 640), ); await tester.pumpWidget( @@ -183,7 +183,7 @@ void main() { ); expect(find.byType(RotatedBox), findsOneWidget); - RotatedBox rotatedBox = + final RotatedBox rotatedBox = tester.widget(find.byType(RotatedBox)); expect(rotatedBox.quarterTurns, 1); @@ -203,8 +203,8 @@ void main() { deviceOrientation: DeviceOrientation.portraitUp, lockedCaptureOrientation: null, recordingOrientation: - Optional.fromNullable(DeviceOrientation.landscapeLeft), - previewSize: Size(480, 640), + const Optional.fromNullable(DeviceOrientation.landscapeLeft), + previewSize: const Size(480, 640), ); await tester.pumpWidget( @@ -215,7 +215,7 @@ void main() { ); expect(find.byType(RotatedBox), findsOneWidget); - RotatedBox rotatedBox = + final RotatedBox rotatedBox = tester.widget(find.byType(RotatedBox)); expect(rotatedBox.quarterTurns, 0); @@ -229,7 +229,7 @@ void main() { final FakeController controller = FakeController(); controller.value = controller.value.copyWith( isInitialized: true, - previewSize: Size(480, 640), + previewSize: const Size(480, 640), ); await tester.pumpWidget( diff --git a/packages/camera/camera/test/camera_test.dart b/packages/camera/camera/test/camera_test.dart index 6904e68ef89f..5dd1e83cf864 100644 --- a/packages/camera/camera/test/camera_test.dart +++ b/packages/camera/camera/test/camera_test.dart @@ -15,20 +15,20 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:mockito/mockito.dart'; import 'package:plugin_platform_interface/plugin_platform_interface.dart'; -get mockAvailableCameras => [ - CameraDescription( +List get mockAvailableCameras => [ + const CameraDescription( name: 'camBack', lensDirection: CameraLensDirection.back, sensorOrientation: 90), - CameraDescription( + const CameraDescription( name: 'camFront', lensDirection: CameraLensDirection.front, sensorOrientation: 180), ]; -get mockInitializeCamera => 13; +int get mockInitializeCamera => 13; -get mockOnCameraInitializedEvent => CameraInitializedEvent( +CameraInitializedEvent get mockOnCameraInitializedEvent => const CameraInitializedEvent( 13, 75, 75, @@ -38,16 +38,16 @@ get mockOnCameraInitializedEvent => CameraInitializedEvent( true, ); -get mockOnDeviceOrientationChangedEvent => - DeviceOrientationChangedEvent(DeviceOrientation.portraitUp); +DeviceOrientationChangedEvent get mockOnDeviceOrientationChangedEvent => + const DeviceOrientationChangedEvent(DeviceOrientation.portraitUp); -get mockOnCameraClosingEvent => null; +void get mockOnCameraClosingEvent => null; -get mockOnCameraErrorEvent => CameraErrorEvent(13, 'closing'); +CameraErrorEvent get mockOnCameraErrorEvent => const CameraErrorEvent(13, 'closing'); XFile mockTakePicture = XFile('foo/bar.png'); -get mockVideoRecordingXFile => null; +void get mockVideoRecordingXFile => null; bool mockPlatformException = false; @@ -57,7 +57,7 @@ void main() { group('camera', () { test('debugCheckIsDisposed should not throw assertion error when disposed', () { - final MockCameraDescription description = MockCameraDescription(); + const MockCameraDescription description = MockCameraDescription(); final CameraController controller = CameraController( description, ResolutionPreset.low, @@ -70,7 +70,7 @@ void main() { test('debugCheckIsDisposed should throw assertion error when not disposed', () { - final MockCameraDescription description = MockCameraDescription(); + const MockCameraDescription description = MockCameraDescription(); final CameraController controller = CameraController( description, ResolutionPreset.low, @@ -85,7 +85,7 @@ void main() { test('availableCameras() has camera', () async { CameraPlatform.instance = MockCameraPlatform(); - var camList = await availableCameras(); + final List camList = await availableCameras(); expect(camList, equals(mockAvailableCameras)); }); @@ -97,8 +97,8 @@ void main() { }); test('Can be initialized', () async { - CameraController cameraController = CameraController( - CameraDescription( + final CameraController cameraController = CameraController( + const CameraDescription( name: 'cam', lensDirection: CameraLensDirection.back, sensorOrientation: 90), @@ -106,13 +106,13 @@ void main() { await cameraController.initialize(); expect(cameraController.value.aspectRatio, 1); - expect(cameraController.value.previewSize, Size(75, 75)); + expect(cameraController.value.previewSize, const Size(75, 75)); expect(cameraController.value.isInitialized, isTrue); }); test('can be disposed', () async { - CameraController cameraController = CameraController( - CameraDescription( + final CameraController cameraController = CameraController( + const CameraDescription( name: 'cam', lensDirection: CameraLensDirection.back, sensorOrientation: 90), @@ -120,7 +120,7 @@ void main() { await cameraController.initialize(); expect(cameraController.value.aspectRatio, 1); - expect(cameraController.value.previewSize, Size(75, 75)); + expect(cameraController.value.previewSize, const Size(75, 75)); expect(cameraController.value.isInitialized, isTrue); await cameraController.dispose(); @@ -129,8 +129,8 @@ void main() { }); test('initialize() throws CameraException when disposed', () async { - CameraController cameraController = CameraController( - CameraDescription( + final CameraController cameraController = CameraController( + const CameraDescription( name: 'cam', lensDirection: CameraLensDirection.back, sensorOrientation: 90), @@ -138,7 +138,7 @@ void main() { await cameraController.initialize(); expect(cameraController.value.aspectRatio, 1); - expect(cameraController.value.previewSize, Size(75, 75)); + expect(cameraController.value.previewSize, const Size(75, 75)); expect(cameraController.value.isInitialized, isTrue); await cameraController.dispose(); @@ -148,7 +148,7 @@ void main() { expect( cameraController.initialize, throwsA(isA().having( - (error) => error.description, + (CameraException error) => error.description, 'Error description', 'initialize was called on a disposed CameraController', ))); @@ -156,8 +156,8 @@ void main() { test('initialize() throws $CameraException on $PlatformException ', () async { - CameraController cameraController = CameraController( - CameraDescription( + final CameraController cameraController = CameraController( + const CameraDescription( name: 'cam', lensDirection: CameraLensDirection.back, sensorOrientation: 90), @@ -168,7 +168,7 @@ void main() { expect( cameraController.initialize, throwsA(isA().having( - (error) => error.description, + (CameraException error) => error.description, 'foo', 'bar', ))); @@ -177,8 +177,8 @@ void main() { test('initialize() sets imageFormat', () async { debugDefaultTargetPlatformOverride = TargetPlatform.android; - CameraController cameraController = CameraController( - CameraDescription( + final CameraController cameraController = CameraController( + const CameraDescription( name: 'cam', lensDirection: CameraLensDirection.back, sensorOrientation: 90), @@ -192,8 +192,8 @@ void main() { }); test('prepareForVideoRecording() calls $CameraPlatform ', () async { - CameraController cameraController = CameraController( - CameraDescription( + final CameraController cameraController = CameraController( + const CameraDescription( name: 'cam', lensDirection: CameraLensDirection.back, sensorOrientation: 90), @@ -206,8 +206,8 @@ void main() { }); test('takePicture() throws $CameraException when uninitialized ', () async { - CameraController cameraController = CameraController( - CameraDescription( + final CameraController cameraController = CameraController( + const CameraDescription( name: 'cam', lensDirection: CameraLensDirection.back, sensorOrientation: 90), @@ -217,12 +217,12 @@ void main() { throwsA( isA() .having( - (error) => error.code, + (CameraException error) => error.code, 'code', 'Uninitialized CameraController', ) .having( - (error) => error.description, + (CameraException error) => error.description, 'description', 'takePicture() was called on an uninitialized CameraController.', ), @@ -232,8 +232,8 @@ void main() { test('takePicture() throws $CameraException when takePicture is true', () async { - CameraController cameraController = CameraController( - CameraDescription( + final CameraController cameraController = CameraController( + const CameraDescription( name: 'cam', lensDirection: CameraLensDirection.back, sensorOrientation: 90), @@ -245,29 +245,29 @@ void main() { expect( cameraController.takePicture(), throwsA(isA().having( - (error) => error.description, + (CameraException error) => error.description, 'Previous capture has not returned yet.', 'takePicture was called before the previous capture returned.', ))); }); test('takePicture() returns $XFile', () async { - CameraController cameraController = CameraController( - CameraDescription( + final CameraController cameraController = CameraController( + const CameraDescription( name: 'cam', lensDirection: CameraLensDirection.back, sensorOrientation: 90), ResolutionPreset.max); await cameraController.initialize(); - XFile xFile = await cameraController.takePicture(); + final XFile xFile = await cameraController.takePicture(); expect(xFile.path, mockTakePicture.path); }); test('takePicture() throws $CameraException on $PlatformException', () async { - CameraController cameraController = CameraController( - CameraDescription( + final CameraController cameraController = CameraController( + const CameraDescription( name: 'cam', lensDirection: CameraLensDirection.back, sensorOrientation: 90), @@ -278,7 +278,7 @@ void main() { expect( cameraController.takePicture(), throwsA(isA().having( - (error) => error.description, + (CameraException error) => error.description, 'foo', 'bar', ))); @@ -287,8 +287,8 @@ void main() { test('startVideoRecording() throws $CameraException when uninitialized', () async { - CameraController cameraController = CameraController( - CameraDescription( + final CameraController cameraController = CameraController( + const CameraDescription( name: 'cam', lensDirection: CameraLensDirection.back, sensorOrientation: 90), @@ -299,12 +299,12 @@ void main() { throwsA( isA() .having( - (error) => error.code, + (CameraException error) => error.code, 'code', 'Uninitialized CameraController', ) .having( - (error) => error.description, + (CameraException error) => error.description, 'description', 'startVideoRecording() was called on an uninitialized CameraController.', ), @@ -313,8 +313,8 @@ void main() { }); test('startVideoRecording() throws $CameraException when recording videos', () async { - CameraController cameraController = CameraController( - CameraDescription( + final CameraController cameraController = CameraController( + const CameraDescription( name: 'cam', lensDirection: CameraLensDirection.back, sensorOrientation: 90), @@ -328,7 +328,7 @@ void main() { expect( cameraController.startVideoRecording(), throwsA(isA().having( - (error) => error.description, + (CameraException error) => error.description, 'A video recording is already started.', 'startVideoRecording was called when a recording is already started.', ))); @@ -337,8 +337,8 @@ void main() { test( 'startVideoRecording() throws $CameraException when already streaming images', () async { - CameraController cameraController = CameraController( - CameraDescription( + final CameraController cameraController = CameraController( + const CameraDescription( name: 'cam', lensDirection: CameraLensDirection.back, sensorOrientation: 90), @@ -352,7 +352,7 @@ void main() { expect( cameraController.startVideoRecording(), throwsA(isA().having( - (error) => error.description, + (CameraException error) => error.description, 'A camera has started streaming images.', 'startVideoRecording was called while a camera was streaming images.', ))); @@ -360,8 +360,8 @@ void main() { test('getMaxZoomLevel() throws $CameraException when uninitialized', () async { - CameraController cameraController = CameraController( - CameraDescription( + final CameraController cameraController = CameraController( + const CameraDescription( name: 'cam', lensDirection: CameraLensDirection.back, sensorOrientation: 90), @@ -372,12 +372,12 @@ void main() { throwsA( isA() .having( - (error) => error.code, + (CameraException error) => error.code, 'code', 'Uninitialized CameraController', ) .having( - (error) => error.description, + (CameraException error) => error.description, 'description', 'getMaxZoomLevel() was called on an uninitialized CameraController.', ), @@ -386,8 +386,8 @@ void main() { }); test('getMaxZoomLevel() throws $CameraException when disposed', () async { - CameraController cameraController = CameraController( - CameraDescription( + final CameraController cameraController = CameraController( + const CameraDescription( name: 'cam', lensDirection: CameraLensDirection.back, sensorOrientation: 90), @@ -401,12 +401,12 @@ void main() { throwsA( isA() .having( - (error) => error.code, + (CameraException error) => error.code, 'code', 'Disposed CameraController', ) .having( - (error) => error.description, + (CameraException error) => error.description, 'description', 'getMaxZoomLevel() was called on a disposed CameraController.', ), @@ -417,8 +417,8 @@ void main() { test( 'getMaxZoomLevel() throws $CameraException when a platform exception occured.', () async { - CameraController cameraController = CameraController( - CameraDescription( + final CameraController cameraController = CameraController( + const CameraDescription( name: 'cam', lensDirection: CameraLensDirection.back, sensorOrientation: 90), @@ -434,17 +434,17 @@ void main() { expect( cameraController.getMaxZoomLevel, throwsA(isA() - .having((error) => error.code, 'code', 'TEST_ERROR') + .having((CameraException error) => error.code, 'code', 'TEST_ERROR') .having( - (error) => error.description, + (CameraException error) => error.description, 'description', 'This is a test error messge', ))); }); test('getMaxZoomLevel() returns max zoom level.', () async { - CameraController cameraController = CameraController( - CameraDescription( + final CameraController cameraController = CameraController( + const CameraDescription( name: 'cam', lensDirection: CameraLensDirection.back, sensorOrientation: 90), @@ -454,14 +454,14 @@ void main() { when(CameraPlatform.instance.getMaxZoomLevel(mockInitializeCamera)) .thenAnswer((_) => Future.value(42.0)); - final maxZoomLevel = await cameraController.getMaxZoomLevel(); + final double maxZoomLevel = await cameraController.getMaxZoomLevel(); expect(maxZoomLevel, 42.0); }); test('getMinZoomLevel() throws $CameraException when uninitialized', () async { - CameraController cameraController = CameraController( - CameraDescription( + final CameraController cameraController = CameraController( + const CameraDescription( name: 'cam', lensDirection: CameraLensDirection.back, sensorOrientation: 90), @@ -472,12 +472,12 @@ void main() { throwsA( isA() .having( - (error) => error.code, + (CameraException error) => error.code, 'code', 'Uninitialized CameraController', ) .having( - (error) => error.description, + (CameraException error) => error.description, 'description', 'getMinZoomLevel() was called on an uninitialized CameraController.', ), @@ -486,8 +486,8 @@ void main() { }); test('getMinZoomLevel() throws $CameraException when disposed', () async { - CameraController cameraController = CameraController( - CameraDescription( + final CameraController cameraController = CameraController( + const CameraDescription( name: 'cam', lensDirection: CameraLensDirection.back, sensorOrientation: 90), @@ -501,12 +501,12 @@ void main() { throwsA( isA() .having( - (error) => error.code, + (CameraException error) => error.code, 'code', 'Disposed CameraController', ) .having( - (error) => error.description, + (CameraException error) => error.description, 'description', 'getMinZoomLevel() was called on a disposed CameraController.', ), @@ -517,8 +517,8 @@ void main() { test( 'getMinZoomLevel() throws $CameraException when a platform exception occured.', () async { - CameraController cameraController = CameraController( - CameraDescription( + final CameraController cameraController = CameraController( + const CameraDescription( name: 'cam', lensDirection: CameraLensDirection.back, sensorOrientation: 90), @@ -534,17 +534,17 @@ void main() { expect( cameraController.getMinZoomLevel, throwsA(isA() - .having((error) => error.code, 'code', 'TEST_ERROR') + .having((CameraException error) => error.code, 'code', 'TEST_ERROR') .having( - (error) => error.description, + (CameraException error) => error.description, 'description', 'This is a test error messge', ))); }); test('getMinZoomLevel() returns max zoom level.', () async { - CameraController cameraController = CameraController( - CameraDescription( + final CameraController cameraController = CameraController( + const CameraDescription( name: 'cam', lensDirection: CameraLensDirection.back, sensorOrientation: 90), @@ -554,13 +554,13 @@ void main() { when(CameraPlatform.instance.getMinZoomLevel(mockInitializeCamera)) .thenAnswer((_) => Future.value(42.0)); - final maxZoomLevel = await cameraController.getMinZoomLevel(); + final double maxZoomLevel = await cameraController.getMinZoomLevel(); expect(maxZoomLevel, 42.0); }); test('setZoomLevel() throws $CameraException when uninitialized', () async { - CameraController cameraController = CameraController( - CameraDescription( + final CameraController cameraController = CameraController( + const CameraDescription( name: 'cam', lensDirection: CameraLensDirection.back, sensorOrientation: 90), @@ -571,12 +571,12 @@ void main() { throwsA( isA() .having( - (error) => error.code, + (CameraException error) => error.code, 'code', 'Uninitialized CameraController', ) .having( - (error) => error.description, + (CameraException error) => error.description, 'description', 'setZoomLevel() was called on an uninitialized CameraController.', ), @@ -585,8 +585,8 @@ void main() { }); test('setZoomLevel() throws $CameraException when disposed', () async { - CameraController cameraController = CameraController( - CameraDescription( + final CameraController cameraController = CameraController( + const CameraDescription( name: 'cam', lensDirection: CameraLensDirection.back, sensorOrientation: 90), @@ -600,12 +600,12 @@ void main() { throwsA( isA() .having( - (error) => error.code, + (CameraException error) => error.code, 'code', 'Disposed CameraController', ) .having( - (error) => error.description, + (CameraException error) => error.description, 'description', 'setZoomLevel() was called on a disposed CameraController.', ), @@ -616,8 +616,8 @@ void main() { test( 'setZoomLevel() throws $CameraException when a platform exception occured.', () async { - CameraController cameraController = CameraController( - CameraDescription( + final CameraController cameraController = CameraController( + const CameraDescription( name: 'cam', lensDirection: CameraLensDirection.back, sensorOrientation: 90), @@ -633,9 +633,9 @@ void main() { expect( () => cameraController.setZoomLevel(42), throwsA(isA() - .having((error) => error.code, 'code', 'TEST_ERROR') + .having((CameraException error) => error.code, 'code', 'TEST_ERROR') .having( - (error) => error.description, + (CameraException error) => error.description, 'description', 'This is a test error messge', ))); @@ -646,8 +646,8 @@ void main() { test( 'setZoomLevel() completes and calls method channel with correct value.', () async { - CameraController cameraController = CameraController( - CameraDescription( + final CameraController cameraController = CameraController( + const CameraDescription( name: 'cam', lensDirection: CameraLensDirection.back, sensorOrientation: 90), @@ -661,8 +661,8 @@ void main() { }); test('setFlashMode() calls $CameraPlatform', () async { - CameraController cameraController = CameraController( - CameraDescription( + final CameraController cameraController = CameraController( + const CameraDescription( name: 'cam', lensDirection: CameraLensDirection.back, sensorOrientation: 90), @@ -678,8 +678,8 @@ void main() { test('setFlashMode() throws $CameraException on $PlatformException', () async { - CameraController cameraController = CameraController( - CameraDescription( + final CameraController cameraController = CameraController( + const CameraDescription( name: 'cam', lensDirection: CameraLensDirection.back, sensorOrientation: 90), @@ -699,15 +699,15 @@ void main() { expect( cameraController.setFlashMode(FlashMode.always), throwsA(isA().having( - (error) => error.description, + (CameraException error) => error.description, 'TEST_ERROR', 'This is a test error message', ))); }); test('setExposureMode() calls $CameraPlatform', () async { - CameraController cameraController = CameraController( - CameraDescription( + final CameraController cameraController = CameraController( + const CameraDescription( name: 'cam', lensDirection: CameraLensDirection.back, sensorOrientation: 90), @@ -723,8 +723,8 @@ void main() { test('setExposureMode() throws $CameraException on $PlatformException', () async { - CameraController cameraController = CameraController( - CameraDescription( + final CameraController cameraController = CameraController( + const CameraDescription( name: 'cam', lensDirection: CameraLensDirection.back, sensorOrientation: 90), @@ -744,32 +744,32 @@ void main() { expect( cameraController.setExposureMode(ExposureMode.auto), throwsA(isA().having( - (error) => error.description, + (CameraException error) => error.description, 'TEST_ERROR', 'This is a test error message', ))); }); test('setExposurePoint() calls $CameraPlatform', () async { - CameraController cameraController = CameraController( - CameraDescription( + final CameraController cameraController = CameraController( + const CameraDescription( name: 'cam', lensDirection: CameraLensDirection.back, sensorOrientation: 90), ResolutionPreset.max); await cameraController.initialize(); - await cameraController.setExposurePoint(Offset(0.5, 0.5)); + await cameraController.setExposurePoint(const Offset(0.5, 0.5)); verify(CameraPlatform.instance.setExposurePoint( - cameraController.cameraId, Point(0.5, 0.5))) + cameraController.cameraId, const Point(0.5, 0.5))) .called(1); }); test('setExposurePoint() throws $CameraException on $PlatformException', () async { - CameraController cameraController = CameraController( - CameraDescription( + final CameraController cameraController = CameraController( + const CameraDescription( name: 'cam', lensDirection: CameraLensDirection.back, sensorOrientation: 90), @@ -777,7 +777,7 @@ void main() { await cameraController.initialize(); when(CameraPlatform.instance.setExposurePoint( - cameraController.cameraId, Point(0.5, 0.5))) + cameraController.cameraId, const Point(0.5, 0.5))) .thenThrow( PlatformException( code: 'TEST_ERROR', @@ -787,17 +787,17 @@ void main() { ); expect( - cameraController.setExposurePoint(Offset(0.5, 0.5)), + cameraController.setExposurePoint(const Offset(0.5, 0.5)), throwsA(isA().having( - (error) => error.description, + (CameraException error) => error.description, 'TEST_ERROR', 'This is a test error message', ))); }); test('getMinExposureOffset() calls $CameraPlatform', () async { - CameraController cameraController = CameraController( - CameraDescription( + final CameraController cameraController = CameraController( + const CameraDescription( name: 'cam', lensDirection: CameraLensDirection.back, sensorOrientation: 90), @@ -817,8 +817,8 @@ void main() { test('getMinExposureOffset() throws $CameraException on $PlatformException', () async { - CameraController cameraController = CameraController( - CameraDescription( + final CameraController cameraController = CameraController( + const CameraDescription( name: 'cam', lensDirection: CameraLensDirection.back, sensorOrientation: 90), @@ -837,15 +837,15 @@ void main() { expect( cameraController.getMinExposureOffset(), throwsA(isA().having( - (error) => error.description, + (CameraException error) => error.description, 'TEST_ERROR', 'This is a test error message', ))); }); test('getMaxExposureOffset() calls $CameraPlatform', () async { - CameraController cameraController = CameraController( - CameraDescription( + final CameraController cameraController = CameraController( + const CameraDescription( name: 'cam', lensDirection: CameraLensDirection.back, sensorOrientation: 90), @@ -865,8 +865,8 @@ void main() { test('getMaxExposureOffset() throws $CameraException on $PlatformException', () async { - CameraController cameraController = CameraController( - CameraDescription( + final CameraController cameraController = CameraController( + const CameraDescription( name: 'cam', lensDirection: CameraLensDirection.back, sensorOrientation: 90), @@ -885,15 +885,15 @@ void main() { expect( cameraController.getMaxExposureOffset(), throwsA(isA().having( - (error) => error.description, + (CameraException error) => error.description, 'TEST_ERROR', 'This is a test error message', ))); }); test('getExposureOffsetStepSize() calls $CameraPlatform', () async { - CameraController cameraController = CameraController( - CameraDescription( + final CameraController cameraController = CameraController( + const CameraDescription( name: 'cam', lensDirection: CameraLensDirection.back, sensorOrientation: 90), @@ -914,8 +914,8 @@ void main() { test( 'getExposureOffsetStepSize() throws $CameraException on $PlatformException', () async { - CameraController cameraController = CameraController( - CameraDescription( + final CameraController cameraController = CameraController( + const CameraDescription( name: 'cam', lensDirection: CameraLensDirection.back, sensorOrientation: 90), @@ -934,15 +934,15 @@ void main() { expect( cameraController.getExposureOffsetStepSize(), throwsA(isA().having( - (error) => error.description, + (CameraException error) => error.description, 'TEST_ERROR', 'This is a test error message', ))); }); test('setExposureOffset() calls $CameraPlatform', () async { - CameraController cameraController = CameraController( - CameraDescription( + final CameraController cameraController = CameraController( + const CameraDescription( name: 'cam', lensDirection: CameraLensDirection.back, sensorOrientation: 90), @@ -970,8 +970,8 @@ void main() { test('setExposureOffset() throws $CameraException on $PlatformException', () async { - CameraController cameraController = CameraController( - CameraDescription( + final CameraController cameraController = CameraController( + const CameraDescription( name: 'cam', lensDirection: CameraLensDirection.back, sensorOrientation: 90), @@ -998,7 +998,7 @@ void main() { expect( cameraController.setExposureOffset(1.0), throwsA(isA().having( - (error) => error.description, + (CameraException error) => error.description, 'TEST_ERROR', 'This is a test error message', ))); @@ -1007,8 +1007,8 @@ void main() { test( 'setExposureOffset() throws $CameraException when offset is out of bounds', () async { - CameraController cameraController = CameraController( - CameraDescription( + final CameraController cameraController = CameraController( + const CameraDescription( name: 'cam', lensDirection: CameraLensDirection.back, sensorOrientation: 90), @@ -1036,14 +1036,14 @@ void main() { expect( cameraController.setExposureOffset(3.0), throwsA(isA().having( - (error) => error.description, + (CameraException error) => error.description, 'exposureOffsetOutOfBounds', 'The provided exposure offset was outside the supported range for this device.', ))); expect( cameraController.setExposureOffset(-2.0), throwsA(isA().having( - (error) => error.description, + (CameraException error) => error.description, 'exposureOffsetOutOfBounds', 'The provided exposure offset was outside the supported range for this device.', ))); @@ -1064,8 +1064,8 @@ void main() { }); test('setExposureOffset() rounds offset to nearest step', () async { - CameraController cameraController = CameraController( - CameraDescription( + final CameraController cameraController = CameraController( + const CameraDescription( name: 'cam', lensDirection: CameraLensDirection.back, sensorOrientation: 90), @@ -1138,8 +1138,8 @@ void main() { }); test('pausePreview() calls $CameraPlatform', () async { - CameraController cameraController = CameraController( - CameraDescription( + final CameraController cameraController = CameraController( + const CameraDescription( name: 'cam', lensDirection: CameraLensDirection.back, sensorOrientation: 90), @@ -1159,8 +1159,8 @@ void main() { test('pausePreview() does not call $CameraPlatform when already paused', () async { - CameraController cameraController = CameraController( - CameraDescription( + final CameraController cameraController = CameraController( + const CameraDescription( name: 'cam', lensDirection: CameraLensDirection.back, sensorOrientation: 90), @@ -1178,8 +1178,8 @@ void main() { test('pausePreview() throws $CameraException on $PlatformException', () async { - CameraController cameraController = CameraController( - CameraDescription( + final CameraController cameraController = CameraController( + const CameraDescription( name: 'cam', lensDirection: CameraLensDirection.back, sensorOrientation: 90), @@ -1197,15 +1197,15 @@ void main() { expect( cameraController.pausePreview(), throwsA(isA().having( - (error) => error.description, + (CameraException error) => error.description, 'TEST_ERROR', 'This is a test error message', ))); }); test('resumePreview() calls $CameraPlatform', () async { - CameraController cameraController = CameraController( - CameraDescription( + final CameraController cameraController = CameraController( + const CameraDescription( name: 'cam', lensDirection: CameraLensDirection.back, sensorOrientation: 90), @@ -1223,8 +1223,8 @@ void main() { test('resumePreview() does not call $CameraPlatform when not paused', () async { - CameraController cameraController = CameraController( - CameraDescription( + final CameraController cameraController = CameraController( + const CameraDescription( name: 'cam', lensDirection: CameraLensDirection.back, sensorOrientation: 90), @@ -1242,8 +1242,8 @@ void main() { test('resumePreview() throws $CameraException on $PlatformException', () async { - CameraController cameraController = CameraController( - CameraDescription( + final CameraController cameraController = CameraController( + const CameraDescription( name: 'cam', lensDirection: CameraLensDirection.back, sensorOrientation: 90), @@ -1263,15 +1263,15 @@ void main() { expect( cameraController.resumePreview(), throwsA(isA().having( - (error) => error.description, + (CameraException error) => error.description, 'TEST_ERROR', 'This is a test error message', ))); }); test('lockCaptureOrientation() calls $CameraPlatform', () async { - CameraController cameraController = CameraController( - CameraDescription( + final CameraController cameraController = CameraController( + const CameraDescription( name: 'cam', lensDirection: CameraLensDirection.back, sensorOrientation: 90), @@ -1297,8 +1297,8 @@ void main() { test( 'lockCaptureOrientation() throws $CameraException on $PlatformException', () async { - CameraController cameraController = CameraController( - CameraDescription( + final CameraController cameraController = CameraController( + const CameraDescription( name: 'cam', lensDirection: CameraLensDirection.back, sensorOrientation: 90), @@ -1317,15 +1317,15 @@ void main() { expect( cameraController.lockCaptureOrientation(DeviceOrientation.portraitUp), throwsA(isA().having( - (error) => error.description, + (CameraException error) => error.description, 'TEST_ERROR', 'This is a test error message', ))); }); test('unlockCaptureOrientation() calls $CameraPlatform', () async { - CameraController cameraController = CameraController( - CameraDescription( + final CameraController cameraController = CameraController( + const CameraDescription( name: 'cam', lensDirection: CameraLensDirection.back, sensorOrientation: 90), @@ -1343,8 +1343,8 @@ void main() { test( 'unlockCaptureOrientation() throws $CameraException on $PlatformException', () async { - CameraController cameraController = CameraController( - CameraDescription( + final CameraController cameraController = CameraController( + const CameraDescription( name: 'cam', lensDirection: CameraLensDirection.back, sensorOrientation: 90), @@ -1363,7 +1363,7 @@ void main() { expect( cameraController.unlockCaptureOrientation(), throwsA(isA().having( - (error) => error.description, + (CameraException error) => error.description, 'TEST_ERROR', 'This is a test error message', ))); @@ -1514,7 +1514,7 @@ class MockCameraPlatform extends Mock class MockCameraDescription extends CameraDescription { /// Creates a new camera description with the given properties. - MockCameraDescription() + const MockCameraDescription() : super( name: 'Test', lensDirection: CameraLensDirection.back, diff --git a/packages/camera/camera/test/camera_value_test.dart b/packages/camera/camera/test/camera_value_test.dart index 4718d8943c34..62df1fd1a2a1 100644 --- a/packages/camera/camera/test/camera_value_test.dart +++ b/packages/camera/camera/test/camera_value_test.dart @@ -13,7 +13,7 @@ import 'package:flutter_test/flutter_test.dart'; void main() { group('camera_value', () { test('Can be created', () { - var cameraValue = const CameraValue( + const CameraValue cameraValue = CameraValue( isInitialized: false, errorDescription: null, previewSize: Size(10, 10), @@ -36,7 +36,7 @@ void main() { expect(cameraValue, isA()); expect(cameraValue.isInitialized, isFalse); expect(cameraValue.errorDescription, null); - expect(cameraValue.previewSize, Size(10, 10)); + expect(cameraValue.previewSize, const Size(10, 10)); expect(cameraValue.isRecordingPaused, isFalse); expect(cameraValue.isRecordingVideo, isFalse); expect(cameraValue.isTakingPicture, isFalse); @@ -53,7 +53,7 @@ void main() { }); test('Can be created as uninitialized', () { - var cameraValue = const CameraValue.uninitialized(); + const CameraValue cameraValue = CameraValue.uninitialized(); expect(cameraValue, isA()); expect(cameraValue.isInitialized, isFalse); @@ -75,8 +75,8 @@ void main() { }); test('Can be copied with isInitialized', () { - var cv = const CameraValue.uninitialized(); - var cameraValue = cv.copyWith(isInitialized: true); + const CameraValue cv = CameraValue.uninitialized(); + final CameraValue cameraValue = cv.copyWith(isInitialized: true); expect(cameraValue, isA()); expect(cameraValue.isInitialized, isTrue); @@ -98,24 +98,24 @@ void main() { }); test('Has aspectRatio after setting size', () { - var cv = const CameraValue.uninitialized(); - var cameraValue = - cv.copyWith(isInitialized: true, previewSize: Size(20, 10)); + const CameraValue cv = CameraValue.uninitialized(); + final CameraValue cameraValue = + cv.copyWith(isInitialized: true, previewSize: const Size(20, 10)); expect(cameraValue.aspectRatio, 2.0); }); test('hasError is true after setting errorDescription', () { - var cv = const CameraValue.uninitialized(); - var cameraValue = cv.copyWith(errorDescription: 'error'); + const CameraValue cv = CameraValue.uninitialized(); + final CameraValue cameraValue = cv.copyWith(errorDescription: 'error'); expect(cameraValue.hasError, isTrue); expect(cameraValue.errorDescription, 'error'); }); test('Recording paused is false when not recording', () { - var cv = const CameraValue.uninitialized(); - var cameraValue = cv.copyWith( + const CameraValue cv = CameraValue.uninitialized(); + final CameraValue cameraValue = cv.copyWith( isInitialized: true, isRecordingVideo: false, isRecordingPaused: true); @@ -124,7 +124,7 @@ void main() { }); test('toString() works as expected', () { - var cameraValue = const CameraValue( + const CameraValue cameraValue = CameraValue( isInitialized: false, errorDescription: null, previewSize: Size(10, 10), diff --git a/packages/camera/camera/test/utils/method_channel_mock.dart b/packages/camera/camera/test/utils/method_channel_mock.dart index 60d8def6a2e3..e6e2b58e9b16 100644 --- a/packages/camera/camera/test/utils/method_channel_mock.dart +++ b/packages/camera/camera/test/utils/method_channel_mock.dart @@ -9,7 +9,7 @@ class MethodChannelMock { final Duration? delay; final MethodChannel methodChannel; final Map methods; - final log = []; + final List log = []; MethodChannelMock({ required String channelName, diff --git a/script/configs/custom_analysis.yaml b/script/configs/custom_analysis.yaml index 493b6e69a54c..7e4d3832056e 100644 --- a/script/configs/custom_analysis.yaml +++ b/script/configs/custom_analysis.yaml @@ -11,7 +11,6 @@ # TODO(ecosystem): Remove everything from this list. See: # https://github.com/flutter/flutter/issues/76229 -- camera/camera - camera/camera_web - google_maps_flutter/google_maps_flutter - google_maps_flutter/google_maps_flutter_platform_interface From 6d5afedcd8ba98c317e4a81df9643c85a0ceefe0 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Fri, 11 Feb 2022 16:05:28 -0500 Subject: [PATCH 2/7] Manual fixes --- .../example/integration_test/camera_test.dart | 6 +- packages/camera/camera/example/lib/main.dart | 143 +++++++++++------- packages/camera/camera/example/pubspec.yaml | 7 +- .../example/test_driver/integration_test.dart | 4 +- .../camera/lib/src/camera_controller.dart | 52 ++++--- .../camera/camera/lib/src/camera_image.dart | 25 +-- .../camera/camera/lib/src/camera_preview.dart | 12 +- packages/camera/camera/pubspec.yaml | 7 +- .../camera/test/camera_image_stream_test.dart | 14 +- .../camera/camera/test/camera_image_test.dart | 45 +++--- .../camera/test/camera_preview_test.dart | 20 +-- packages/camera/camera/test/camera_test.dart | 104 +++++++------ .../test/utils/method_channel_mock.dart | 18 +-- 13 files changed, 260 insertions(+), 197 deletions(-) diff --git a/packages/camera/camera/example/integration_test/camera_test.dart b/packages/camera/camera/example/integration_test/camera_test.dart index c2a88ccc2672..557f4858acab 100644 --- a/packages/camera/camera/example/integration_test/camera_test.dart +++ b/packages/camera/camera/example/integration_test/camera_test.dart @@ -224,7 +224,9 @@ void main() { bool _isDetecting = false; await controller.startImageStream((CameraImage image) { - if (_isDetecting) return; + if (_isDetecting) { + return; + } _isDetecting = true; @@ -256,7 +258,7 @@ void main() { await controller.startImageStream((CameraImage image) { if (!_completer.isCompleted) { - Future(() async { + Future(() async { await controller.stopImageStream(); await controller.dispose(); }).then((Object? value) { diff --git a/packages/camera/camera/example/lib/main.dart b/packages/camera/camera/example/lib/main.dart index 198cd67a3051..d47edfed69e2 100644 --- a/packages/camera/camera/example/lib/main.dart +++ b/packages/camera/camera/example/lib/main.dart @@ -194,7 +194,8 @@ class _CameraExampleHomeState extends State behavior: HitTestBehavior.opaque, onScaleStart: _handleScaleStart, onScaleUpdate: _handleScaleUpdate, - onTapDown: (TapDownDetails details) => onViewFinderTap(details, constraints), + onTapDown: (TapDownDetails details) => + onViewFinderTap(details, constraints), ); }), ), @@ -228,32 +229,34 @@ class _CameraExampleHomeState extends State child: Row( mainAxisSize: MainAxisSize.min, children: [ - if (localVideoController == null && imageFile == null) Container() else SizedBox( - child: (localVideoController == null) - ? ( - // The captured image on the web contains a network-accessible URL - // pointing to a location within the browser. It may be displayed - // either with Image.network or Image.memory after loading the image - // bytes to memory. - kIsWeb - ? Image.network(imageFile!.path) - : Image.file(File(imageFile!.path))) - : Container( - child: Center( - child: AspectRatio( - aspectRatio: - localVideoController.value.size != null - ? localVideoController - .value.aspectRatio - : 1.0, - child: VideoPlayer(localVideoController)), - ), - decoration: BoxDecoration( - border: Border.all(color: Colors.pink)), - ), - width: 64.0, - height: 64.0, - ), + if (localVideoController == null && imageFile == null) + Container() + else + SizedBox( + child: (localVideoController == null) + ? ( + // The captured image on the web contains a network-accessible URL + // pointing to a location within the browser. It may be displayed + // either with Image.network or Image.memory after loading the image + // bytes to memory. + kIsWeb + ? Image.network(imageFile!.path) + : Image.file(File(imageFile!.path))) + : Container( + child: Center( + child: AspectRatio( + aspectRatio: + localVideoController.value.size != null + ? localVideoController.value.aspectRatio + : 1.0, + child: VideoPlayer(localVideoController)), + ), + decoration: BoxDecoration( + border: Border.all(color: Colors.pink)), + ), + width: 64.0, + height: 64.0, + ), ], ), ), @@ -263,7 +266,7 @@ class _CameraExampleHomeState extends State /// Display a bar with buttons to change the flash and exposure modes Widget _modeControlRowWidget() { return Column( - children: [ + children: [ Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, mainAxisSize: MainAxisSize.max, @@ -275,7 +278,7 @@ class _CameraExampleHomeState extends State ), // The exposure and focus mode are currently not supported on the web. ...!kIsWeb - ? [ + ? [ IconButton( icon: const Icon(Icons.exposure), color: Colors.blue, @@ -290,7 +293,7 @@ class _CameraExampleHomeState extends State controller != null ? onFocusModeButtonPressed : null, ) ] - : [], + : [], IconButton( icon: Icon(enableAudio ? Icons.volume_up : Icons.volume_mute), color: Colors.blue, @@ -321,7 +324,7 @@ class _CameraExampleHomeState extends State child: Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, mainAxisSize: MainAxisSize.max, - children: [ + children: [ IconButton( icon: const Icon(Icons.flash_off), color: controller?.value.flashMode == FlashMode.off @@ -382,14 +385,14 @@ class _CameraExampleHomeState extends State child: Container( color: Colors.grey.shade50, child: Column( - children: [ + children: [ const Center( child: Text('Exposure Mode'), ), Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, mainAxisSize: MainAxisSize.max, - children: [ + children: [ TextButton( child: const Text('AUTO'), style: styleAuto, @@ -427,7 +430,7 @@ class _CameraExampleHomeState extends State Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, mainAxisSize: MainAxisSize.max, - children: [ + children: [ Text(_minAvailableExposureOffset.toString()), Slider( value: _currentExposureOffset, @@ -467,14 +470,14 @@ class _CameraExampleHomeState extends State child: Container( color: Colors.grey.shade50, child: Column( - children: [ + children: [ const Center( child: Text('Focus Mode'), ), Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, mainAxisSize: MainAxisSize.max, - children: [ + children: [ TextButton( child: const Text('AUTO'), style: styleAuto, @@ -482,7 +485,9 @@ class _CameraExampleHomeState extends State ? () => onSetFocusModeButtonPressed(FocusMode.auto) : null, onLongPress: () { - if (controller != null) controller!.setFocusPoint(null); + if (controller != null) { + controller!.setFocusPoint(null); + } showInSnackBar('Resetting focus point'); }, ), @@ -568,7 +573,8 @@ class _CameraExampleHomeState extends State Widget _cameraTogglesRowWidget() { final List toggles = []; - final Null Function(CameraDescription? description) onChanged = (CameraDescription? description) { + final Null Function(CameraDescription? description) onChanged = + (CameraDescription? description) { if (description == null) { return; } @@ -622,7 +628,7 @@ class _CameraExampleHomeState extends State cameraController.setFocusPoint(offset); } - void onNewCameraSelected(CameraDescription cameraDescription) async { + Future onNewCameraSelected(CameraDescription cameraDescription) async { if (controller != null) { await controller!.dispose(); } @@ -638,7 +644,9 @@ class _CameraExampleHomeState extends State // If the controller is updated then update the UI. cameraController.addListener(() { - if (mounted) setState(() {}); + if (mounted) { + setState(() {}); + } if (cameraController.value.hasError) { showInSnackBar( 'Camera error ${cameraController.value.errorDescription}'); @@ -647,18 +655,17 @@ class _CameraExampleHomeState extends State try { await cameraController.initialize(); - await Future.wait([ + await Future.wait(>[ // The exposure mode is currently not supported on the web. ...!kIsWeb - ? [ - cameraController - .getMinExposureOffset() - .then((double value) => _minAvailableExposureOffset = value), + ? >[ + cameraController.getMinExposureOffset().then( + (double value) => _minAvailableExposureOffset = value), cameraController .getMaxExposureOffset() .then((double value) => _maxAvailableExposureOffset = value) ] - : [], + : >[], cameraController .getMaxZoomLevel() .then((double value) => _maxAvailableZoom = value), @@ -683,7 +690,9 @@ class _CameraExampleHomeState extends State videoController?.dispose(); videoController = null; }); - if (file != null) showInSnackBar('Picture saved to ${file.path}'); + if (file != null) { + showInSnackBar('Picture saved to ${file.path}'); + } } }); } @@ -725,7 +734,7 @@ class _CameraExampleHomeState extends State } } - void onCaptureOrientationLockButtonPressed() async { + Future onCaptureOrientationLockButtonPressed() async { try { if (controller != null) { final CameraController cameraController = controller!; @@ -745,34 +754,44 @@ class _CameraExampleHomeState extends State void onSetFlashModeButtonPressed(FlashMode mode) { setFlashMode(mode).then((_) { - if (mounted) setState(() {}); + if (mounted) { + setState(() {}); + } showInSnackBar('Flash mode set to ${mode.toString().split('.').last}'); }); } void onSetExposureModeButtonPressed(ExposureMode mode) { setExposureMode(mode).then((_) { - if (mounted) setState(() {}); + if (mounted) { + setState(() {}); + } showInSnackBar('Exposure mode set to ${mode.toString().split('.').last}'); }); } void onSetFocusModeButtonPressed(FocusMode mode) { setFocusMode(mode).then((_) { - if (mounted) setState(() {}); + if (mounted) { + setState(() {}); + } showInSnackBar('Focus mode set to ${mode.toString().split('.').last}'); }); } void onVideoRecordButtonPressed() { startVideoRecording().then((_) { - if (mounted) setState(() {}); + if (mounted) { + setState(() {}); + } }); } void onStopButtonPressed() { stopVideoRecording().then((XFile? file) { - if (mounted) setState(() {}); + if (mounted) { + setState(() {}); + } if (file != null) { showInSnackBar('Video recorded to ${file.path}'); videoFile = file; @@ -795,19 +814,25 @@ class _CameraExampleHomeState extends State await cameraController.pausePreview(); } - if (mounted) setState(() {}); + if (mounted) { + setState(() {}); + } } void onPauseButtonPressed() { pauseVideoRecording().then((_) { - if (mounted) setState(() {}); + if (mounted) { + setState(() {}); + } showInSnackBar('Video recording paused'); }); } void onResumeButtonPressed() { resumeVideoRecording().then((_) { - if (mounted) setState(() {}); + if (mounted) { + setState(() {}); + } showInSnackBar('Video recording resumed'); }); } @@ -945,7 +970,9 @@ class _CameraExampleHomeState extends State videoPlayerListener = () { if (videoController != null && videoController!.value.size != null) { // Refreshing the state to update video player with the correct ratio. - if (mounted) setState(() {}); + if (mounted) { + setState(() {}); + } videoController!.removeListener(videoPlayerListener!); } }; @@ -998,7 +1025,7 @@ class CameraApp extends StatelessWidget { } } -List cameras = []; +List cameras = []; Future main() async { // Fetch the available cameras before initializing the app. diff --git a/packages/camera/camera/example/pubspec.yaml b/packages/camera/camera/example/pubspec.yaml index 1899835aca50..1700074f1f88 100644 --- a/packages/camera/camera/example/pubspec.yaml +++ b/packages/camera/camera/example/pubspec.yaml @@ -14,19 +14,18 @@ dependencies: # The example app is bundled with the plugin so we use a path dependency on # the parent directory to use the current plugin's version. path: ../ - path_provider: ^2.0.0 flutter: sdk: flutter + path_provider: ^2.0.0 video_player: ^2.1.4 dev_dependencies: - flutter_test: - sdk: flutter flutter_driver: sdk: flutter + flutter_test: + sdk: flutter integration_test: sdk: flutter - pedantic: ^1.10.0 flutter: uses-material-design: true diff --git a/packages/camera/camera/example/test_driver/integration_test.dart b/packages/camera/camera/example/test_driver/integration_test.dart index dedb2537fb88..4ec97e66d36c 100644 --- a/packages/camera/camera/example/test_driver/integration_test.dart +++ b/packages/camera/camera/example/test_driver/integration_test.dart @@ -18,7 +18,7 @@ Future main() async { final bool adbExists = Process.runSync('which', ['adb']).exitCode == 0; if (!adbExists) { - print('This test needs ADB to exist on the \$PATH. Skipping...'); + print(r'This test needs ADB to exist on the $PATH. Skipping...'); exit(0); } print('Granting camera permissions...'); @@ -59,6 +59,6 @@ Future main() async { 'android.permission.RECORD_AUDIO' ]); - final Map result = jsonDecode(data); + final Map result = jsonDecode(data) as Map; exit(result['result'] == 'true' ? 0 : 1); } diff --git a/packages/camera/camera/lib/src/camera_controller.dart b/packages/camera/camera/lib/src/camera_controller.dart index ed8dd524ad10..b05049ec6503 100644 --- a/packages/camera/camera/lib/src/camera_controller.dart +++ b/packages/camera/camera/lib/src/camera_controller.dart @@ -18,7 +18,9 @@ const MethodChannel _channel = MethodChannel('plugins.flutter.io/camera'); /// Signature for a callback receiving the a camera image. /// /// This is used by [CameraController.startImageStream]. -// ignore: inference_failure_on_function_return_type +// TODO(stuartmorgan): Fix this naming the next time there's a breaking change +// to this package. +// ignore: camel_case_types typedef onLatestImageAvailable = Function(CameraImage image); /// Completes with a list of available cameras. @@ -192,7 +194,7 @@ class CameraValue { @override String toString() { - return '$runtimeType(' + return '${objectRuntimeType(this, 'CameraValue')}(' 'isRecordingVideo: $isRecordingVideo, ' 'isInitialized: $isInitialized, ' 'errorDescription: $errorDescription, ' @@ -254,7 +256,8 @@ class CameraController extends ValueNotifier { bool _isDisposed = false; StreamSubscription? _imageStreamSubscription; FutureOr? _initCalled; - StreamSubscription? _deviceOrientationSubscription; + StreamSubscription? + _deviceOrientationSubscription; /// Checks whether [CameraController.dispose] has completed successfully. /// @@ -277,10 +280,12 @@ class CameraController extends ValueNotifier { ); } try { - final Completer _initializeCompleter = Completer(); + final Completer _initializeCompleter = + Completer(); - _deviceOrientationSubscription = - CameraPlatform.instance.onDeviceOrientationChanged().listen((DeviceOrientationChangedEvent event) { + _deviceOrientationSubscription = CameraPlatform.instance + .onDeviceOrientationChanged() + .listen((DeviceOrientationChangedEvent event) { value = value.copyWith( deviceOrientation: event.orientation, ); @@ -313,10 +318,10 @@ class CameraController extends ValueNotifier { )), exposureMode: await _initializeCompleter.future .then((CameraInitializedEvent event) => event.exposureMode), - focusMode: - await _initializeCompleter.future.then((CameraInitializedEvent event) => event.focusMode), - exposurePointSupported: await _initializeCompleter.future - .then((CameraInitializedEvent event) => event.exposurePointSupported), + focusMode: await _initializeCompleter.future + .then((CameraInitializedEvent event) => event.focusMode), + exposurePointSupported: await _initializeCompleter.future.then( + (CameraInitializedEvent event) => event.exposurePointSupported), focusPointSupported: await _initializeCompleter.future .then((CameraInitializedEvent event) => event.focusPointSupported), ); @@ -351,7 +356,8 @@ class CameraController extends ValueNotifier { await CameraPlatform.instance.pausePreview(_cameraId); value = value.copyWith( isPreviewPaused: true, - previewPauseOrientation: Optional.of(value.deviceOrientation)); + previewPauseOrientation: + Optional.of(value.deviceOrientation)); } on PlatformException catch (e) { throw CameraException(e.code, e.message); } @@ -365,7 +371,8 @@ class CameraController extends ValueNotifier { try { await CameraPlatform.instance.resumePreview(_cameraId); value = value.copyWith( - isPreviewPaused: false, previewPauseOrientation: const Optional.absent()); + isPreviewPaused: false, + previewPauseOrientation: const Optional.absent()); } on PlatformException catch (e) { throw CameraException(e.code, e.message); } @@ -438,7 +445,8 @@ class CameraController extends ValueNotifier { _imageStreamSubscription = cameraEventChannel.receiveBroadcastStream().listen( (dynamic imageData) { - onAvailable(CameraImage.fromPlatformData(imageData)); + onAvailable( + CameraImage.fromPlatformData(imageData as Map)); }, ); } @@ -502,7 +510,7 @@ class CameraController extends ValueNotifier { value = value.copyWith( isRecordingVideo: true, isRecordingPaused: false, - recordingOrientation: Optional.fromNullable( + recordingOrientation: Optional.fromNullable( value.lockedCaptureOrientation ?? value.deviceOrientation)); } on PlatformException catch (e) { throw CameraException(e.code, e.message); @@ -521,10 +529,11 @@ class CameraController extends ValueNotifier { ); } try { - final XFile file = await CameraPlatform.instance.stopVideoRecording(_cameraId); + final XFile file = + await CameraPlatform.instance.stopVideoRecording(_cameraId); value = value.copyWith( isRecordingVideo: false, - recordingOrientation: const Optional.absent(), + recordingOrientation: const Optional.absent(), ); return file; } on PlatformException catch (e) { @@ -706,8 +715,8 @@ class CameraController extends ValueNotifier { Future setExposureOffset(double offset) async { _throwIfNotInitialized('setExposureOffset'); // Check if offset is in range - final List range = - await Future.wait([getMinExposureOffset(), getMaxExposureOffset()]); + final List range = await Future.wait( + >[getMinExposureOffset(), getMaxExposureOffset()]); if (offset < range[0] || offset > range[1]) { throw CameraException( 'exposureOffsetOutOfBounds', @@ -743,8 +752,8 @@ class CameraController extends ValueNotifier { await CameraPlatform.instance.lockCaptureOrientation( _cameraId, orientation ?? value.deviceOrientation); value = value.copyWith( - lockedCaptureOrientation: - Optional.fromNullable(orientation ?? value.deviceOrientation)); + lockedCaptureOrientation: Optional.fromNullable( + orientation ?? value.deviceOrientation)); } on PlatformException catch (e) { throw CameraException(e.code, e.message); } @@ -764,7 +773,8 @@ class CameraController extends ValueNotifier { Future unlockCaptureOrientation() async { try { await CameraPlatform.instance.unlockCaptureOrientation(_cameraId); - value = value.copyWith(lockedCaptureOrientation: const Optional.absent()); + value = value.copyWith( + lockedCaptureOrientation: const Optional.absent()); } on PlatformException catch (e) { throw CameraException(e.code, e.message); } diff --git a/packages/camera/camera/lib/src/camera_image.dart b/packages/camera/camera/lib/src/camera_image.dart index a57e307c7c85..cb68d0e41d0e 100644 --- a/packages/camera/camera/lib/src/camera_image.dart +++ b/packages/camera/camera/lib/src/camera_image.dart @@ -14,11 +14,11 @@ import 'package:flutter/material.dart'; /// format of the Image. class Plane { Plane._fromPlatformData(Map data) - : bytes = data['bytes'], - bytesPerPixel = data['bytesPerPixel'], - bytesPerRow = data['bytesPerRow'], - height = data['height'], - width = data['width']; + : bytes = data['bytes'] as Uint8List, + bytesPerPixel = data['bytesPerPixel'] as int?, + bytesPerRow = data['bytesPerRow'] as int, + height = data['height'] as int?, + width = data['width'] as int?; /// Bytes representing this plane. final Uint8List bytes; @@ -98,13 +98,14 @@ class CameraImage { /// CameraImage Constructor CameraImage.fromPlatformData(Map data) : format = ImageFormat._fromPlatformData(data['format']), - height = data['height'], - width = data['width'], - lensAperture = data['lensAperture'], - sensorExposureTime = data['sensorExposureTime'], - sensorSensitivity = data['sensorSensitivity'], - planes = List.unmodifiable(data['planes'] - .map((dynamic planeData) => Plane._fromPlatformData(planeData))); + height = data['height'] as int, + width = data['width'] as int, + lensAperture = data['lensAperture'] as double?, + sensorExposureTime = data['sensorExposureTime'] as int?, + sensorSensitivity = data['sensorSensitivity'] as double?, + planes = List.unmodifiable((data['planes'] as List) + .map((dynamic planeData) => + Plane._fromPlatformData(planeData as Map))); /// Format of the image provided. /// diff --git a/packages/camera/camera/lib/src/camera_preview.dart b/packages/camera/camera/lib/src/camera_preview.dart index 3b6d6f8931ef..a9b3f2143b49 100644 --- a/packages/camera/camera/lib/src/camera_preview.dart +++ b/packages/camera/camera/lib/src/camera_preview.dart @@ -21,7 +21,7 @@ class CameraPreview extends StatelessWidget { @override Widget build(BuildContext context) { return controller.value.isInitialized - ? ValueListenableBuilder( + ? ValueListenableBuilder( valueListenable: controller, builder: (BuildContext context, Object? value, Widget? child) { return AspectRatio( @@ -30,7 +30,7 @@ class CameraPreview extends StatelessWidget { : (1 / controller.value.aspectRatio), child: Stack( fit: StackFit.expand, - children: [ + children: [ _wrapInRotatedBox(child: controller.buildPreview()), child ?? Container(), ], @@ -54,12 +54,14 @@ class CameraPreview extends StatelessWidget { } bool _isLandscape() { - return [DeviceOrientation.landscapeLeft, DeviceOrientation.landscapeRight] - .contains(_getApplicableOrientation()); + return [ + DeviceOrientation.landscapeLeft, + DeviceOrientation.landscapeRight + ].contains(_getApplicableOrientation()); } int _getQuarterTurns() { - final Map turns = { + final Map turns = { DeviceOrientation.portraitUp: 0, DeviceOrientation.landscapeRight: 1, DeviceOrientation.portraitDown: 2, diff --git a/packages/camera/camera/pubspec.yaml b/packages/camera/camera/pubspec.yaml index f522608f8744..c12942a53487 100644 --- a/packages/camera/camera/pubspec.yaml +++ b/packages/camera/camera/pubspec.yaml @@ -26,15 +26,14 @@ dependencies: camera_web: ^0.2.1 flutter: sdk: flutter - pedantic: ^1.10.0 - quiver: ^3.0.0 flutter_plugin_android_lifecycle: ^2.0.2 + quiver: ^3.0.0 dev_dependencies: - flutter_test: - sdk: flutter flutter_driver: sdk: flutter + flutter_test: + sdk: flutter mockito: ^5.0.0 plugin_platform_interface: ^2.0.0 video_player: ^2.0.0 diff --git a/packages/camera/camera/test/camera_image_stream_test.dart b/packages/camera/camera/test/camera_image_stream_test.dart index 8dddd3f79e3f..7055b2239a5a 100644 --- a/packages/camera/camera/test/camera_image_stream_test.dart +++ b/packages/camera/camera/test/camera_image_stream_test.dart @@ -89,10 +89,10 @@ void main() { test('startImageStream() calls CameraPlatform', () async { final MethodChannelMock cameraChannelMock = MethodChannelMock( channelName: 'plugins.flutter.io/camera', - methods: {'startImageStream': {}}); + methods: {'startImageStream': {}}); final MethodChannelMock streamChannelMock = MethodChannelMock( channelName: 'plugins.flutter.io/camera/imageStream', - methods: {'listen': {}}); + methods: {'listen': {}}); final CameraController cameraController = CameraController( const CameraDescription( @@ -180,10 +180,16 @@ void main() { test('stopImageStream() intended behaviour', () async { final MethodChannelMock cameraChannelMock = MethodChannelMock( channelName: 'plugins.flutter.io/camera', - methods: {'startImageStream': {}, 'stopImageStream': {}}); + methods: { + 'startImageStream': {}, + 'stopImageStream': {} + }); final MethodChannelMock streamChannelMock = MethodChannelMock( channelName: 'plugins.flutter.io/camera/imageStream', - methods: {'listen': {}, 'cancel': {}}); + methods: { + 'listen': {}, + 'cancel': {} + }); final CameraController cameraController = CameraController( const CameraDescription( diff --git a/packages/camera/camera/test/camera_image_test.dart b/packages/camera/camera/test/camera_image_test.dart index 817d8da2fe65..b09a14177121 100644 --- a/packages/camera/camera/test/camera_image_test.dart +++ b/packages/camera/camera/test/camera_image_test.dart @@ -14,16 +14,17 @@ void main() { group('$CameraImage tests', () { test('$CameraImage can be created', () { debugDefaultTargetPlatformOverride = TargetPlatform.android; - final CameraImage cameraImage = CameraImage.fromPlatformData({ + final CameraImage cameraImage = + CameraImage.fromPlatformData({ 'format': 35, 'height': 1, 'width': 4, 'lensAperture': 1.8, 'sensorExposureTime': 9991324, 'sensorSensitivity': 92.0, - 'planes': [ - { - 'bytes': Uint8List.fromList([1, 2, 3, 4]), + 'planes': [ + { + 'bytes': Uint8List.fromList([1, 2, 3, 4]), 'bytesPerPixel': 1, 'bytesPerRow': 4, 'height': 1, @@ -40,16 +41,17 @@ void main() { test('$CameraImage has ImageFormatGroup.yuv420 for iOS', () { debugDefaultTargetPlatformOverride = TargetPlatform.iOS; - final CameraImage cameraImage = CameraImage.fromPlatformData({ + final CameraImage cameraImage = + CameraImage.fromPlatformData({ 'format': 875704438, 'height': 1, 'width': 4, 'lensAperture': 1.8, 'sensorExposureTime': 9991324, 'sensorSensitivity': 92.0, - 'planes': [ - { - 'bytes': Uint8List.fromList([1, 2, 3, 4]), + 'planes': [ + { + 'bytes': Uint8List.fromList([1, 2, 3, 4]), 'bytesPerPixel': 1, 'bytesPerRow': 4, 'height': 1, @@ -63,16 +65,17 @@ void main() { test('$CameraImage has ImageFormatGroup.yuv420 for Android', () { debugDefaultTargetPlatformOverride = TargetPlatform.android; - final CameraImage cameraImage = CameraImage.fromPlatformData({ + final CameraImage cameraImage = + CameraImage.fromPlatformData({ 'format': 35, 'height': 1, 'width': 4, 'lensAperture': 1.8, 'sensorExposureTime': 9991324, 'sensorSensitivity': 92.0, - 'planes': [ - { - 'bytes': Uint8List.fromList([1, 2, 3, 4]), + 'planes': [ + { + 'bytes': Uint8List.fromList([1, 2, 3, 4]), 'bytesPerPixel': 1, 'bytesPerRow': 4, 'height': 1, @@ -86,16 +89,17 @@ void main() { test('$CameraImage has ImageFormatGroup.bgra8888 for iOS', () { debugDefaultTargetPlatformOverride = TargetPlatform.iOS; - final CameraImage cameraImage = CameraImage.fromPlatformData({ + final CameraImage cameraImage = + CameraImage.fromPlatformData({ 'format': 1111970369, 'height': 1, 'width': 4, 'lensAperture': 1.8, 'sensorExposureTime': 9991324, 'sensorSensitivity': 92.0, - 'planes': [ - { - 'bytes': Uint8List.fromList([1, 2, 3, 4]), + 'planes': [ + { + 'bytes': Uint8List.fromList([1, 2, 3, 4]), 'bytesPerPixel': 1, 'bytesPerRow': 4, 'height': 1, @@ -106,16 +110,17 @@ void main() { expect(cameraImage.format.group, ImageFormatGroup.bgra8888); }); test('$CameraImage has ImageFormatGroup.unknown', () { - final CameraImage cameraImage = CameraImage.fromPlatformData({ + final CameraImage cameraImage = + CameraImage.fromPlatformData({ 'format': null, 'height': 1, 'width': 4, 'lensAperture': 1.8, 'sensorExposureTime': 9991324, 'sensorSensitivity': 92.0, - 'planes': [ - { - 'bytes': Uint8List.fromList([1, 2, 3, 4]), + 'planes': [ + { + 'bytes': Uint8List.fromList([1, 2, 3, 4]), 'bytesPerPixel': 1, 'bytesPerRow': 4, 'height': 1, diff --git a/packages/camera/camera/test/camera_preview_test.dart b/packages/camera/camera/test/camera_preview_test.dart index 2adb09446cd9..76bfe40605d7 100644 --- a/packages/camera/camera/test/camera_preview_test.dart +++ b/packages/camera/camera/test/camera_preview_test.dart @@ -97,7 +97,7 @@ class FakeController extends ValueNotifier Future setZoomLevel(double zoom) async {} @override - Future startImageStream(onAvailable) async {} + Future startImageStream(onLatestImageAvailable onAvailable) async {} @override Future startVideoRecording() async {} @@ -136,9 +136,10 @@ void main() { isRecordingVideo: true, deviceOrientation: DeviceOrientation.portraitUp, lockedCaptureOrientation: - const Optional.fromNullable(DeviceOrientation.landscapeRight), - recordingOrientation: - const Optional.fromNullable(DeviceOrientation.landscapeLeft), + const Optional.fromNullable( + DeviceOrientation.landscapeRight), + recordingOrientation: const Optional.fromNullable( + DeviceOrientation.landscapeLeft), previewSize: const Size(480, 640), ); @@ -169,9 +170,10 @@ void main() { isInitialized: true, deviceOrientation: DeviceOrientation.portraitUp, lockedCaptureOrientation: - const Optional.fromNullable(DeviceOrientation.landscapeRight), - recordingOrientation: - const Optional.fromNullable(DeviceOrientation.landscapeLeft), + const Optional.fromNullable( + DeviceOrientation.landscapeRight), + recordingOrientation: const Optional.fromNullable( + DeviceOrientation.landscapeLeft), previewSize: const Size(480, 640), ); @@ -202,8 +204,8 @@ void main() { isInitialized: true, deviceOrientation: DeviceOrientation.portraitUp, lockedCaptureOrientation: null, - recordingOrientation: - const Optional.fromNullable(DeviceOrientation.landscapeLeft), + recordingOrientation: const Optional.fromNullable( + DeviceOrientation.landscapeLeft), previewSize: const Size(480, 640), ); diff --git a/packages/camera/camera/test/camera_test.dart b/packages/camera/camera/test/camera_test.dart index 5dd1e83cf864..6062ad4d01ae 100644 --- a/packages/camera/camera/test/camera_test.dart +++ b/packages/camera/camera/test/camera_test.dart @@ -15,7 +15,7 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:mockito/mockito.dart'; import 'package:plugin_platform_interface/plugin_platform_interface.dart'; -List get mockAvailableCameras => [ +List get mockAvailableCameras => [ const CameraDescription( name: 'camBack', lensDirection: CameraLensDirection.back, @@ -28,7 +28,8 @@ List get mockAvailableCameras => [ int get mockInitializeCamera => 13; -CameraInitializedEvent get mockOnCameraInitializedEvent => const CameraInitializedEvent( +CameraInitializedEvent get mockOnCameraInitializedEvent => + const CameraInitializedEvent( 13, 75, 75, @@ -41,13 +42,14 @@ CameraInitializedEvent get mockOnCameraInitializedEvent => const CameraInitializ DeviceOrientationChangedEvent get mockOnDeviceOrientationChangedEvent => const DeviceOrientationChangedEvent(DeviceOrientation.portraitUp); -void get mockOnCameraClosingEvent => null; +CameraClosingEvent get mockOnCameraClosingEvent => const CameraClosingEvent(13); -CameraErrorEvent get mockOnCameraErrorEvent => const CameraErrorEvent(13, 'closing'); +CameraErrorEvent get mockOnCameraErrorEvent => + const CameraErrorEvent(13, 'closing'); XFile mockTakePicture = XFile('foo/bar.png'); -void get mockVideoRecordingXFile => null; +XFile mockVideoRecordingXFile = XFile('foo/bar.mpeg'); bool mockPlatformException = false; @@ -434,7 +436,8 @@ void main() { expect( cameraController.getMaxZoomLevel, throwsA(isA() - .having((CameraException error) => error.code, 'code', 'TEST_ERROR') + .having( + (CameraException error) => error.code, 'code', 'TEST_ERROR') .having( (CameraException error) => error.description, 'description', @@ -452,7 +455,7 @@ void main() { await cameraController.initialize(); when(CameraPlatform.instance.getMaxZoomLevel(mockInitializeCamera)) - .thenAnswer((_) => Future.value(42.0)); + .thenAnswer((_) => Future.value(42.0)); final double maxZoomLevel = await cameraController.getMaxZoomLevel(); expect(maxZoomLevel, 42.0); @@ -534,7 +537,8 @@ void main() { expect( cameraController.getMinZoomLevel, throwsA(isA() - .having((CameraException error) => error.code, 'code', 'TEST_ERROR') + .having( + (CameraException error) => error.code, 'code', 'TEST_ERROR') .having( (CameraException error) => error.description, 'description', @@ -552,7 +556,7 @@ void main() { await cameraController.initialize(); when(CameraPlatform.instance.getMinZoomLevel(mockInitializeCamera)) - .thenAnswer((_) => Future.value(42.0)); + .thenAnswer((_) => Future.value(42.0)); final double maxZoomLevel = await cameraController.getMinZoomLevel(); expect(maxZoomLevel, 42.0); @@ -633,7 +637,8 @@ void main() { expect( () => cameraController.setZoomLevel(42), throwsA(isA() - .having((CameraException error) => error.code, 'code', 'TEST_ERROR') + .having( + (CameraException error) => error.code, 'code', 'TEST_ERROR') .having( (CameraException error) => error.description, 'description', @@ -806,7 +811,7 @@ void main() { when(CameraPlatform.instance .getMinExposureOffset(cameraController.cameraId)) - .thenAnswer((_) => Future.value(0.0)); + .thenAnswer((_) => Future.value(0.0)); await cameraController.getMinExposureOffset(); @@ -854,7 +859,7 @@ void main() { when(CameraPlatform.instance .getMaxExposureOffset(cameraController.cameraId)) - .thenAnswer((_) => Future.value(1.0)); + .thenAnswer((_) => Future.value(1.0)); await cameraController.getMaxExposureOffset(); @@ -902,7 +907,7 @@ void main() { when(CameraPlatform.instance .getExposureOffsetStepSize(cameraController.cameraId)) - .thenAnswer((_) => Future.value(0.0)); + .thenAnswer((_) => Future.value(0.0)); await cameraController.getExposureOffsetStepSize(); @@ -1381,20 +1386,20 @@ class MockCameraPlatform extends Mock }) async => super.noSuchMethod(Invocation.method( #initializeCamera, - [cameraId], - { + [cameraId], + { #imageFormatGroup: imageFormatGroup, }, )); @override Future dispose(int? cameraId) async { - return super.noSuchMethod(Invocation.method(#dispose, [cameraId])); + return super.noSuchMethod(Invocation.method(#dispose, [cameraId])); } @override Future> availableCameras() => - Future.value(mockAvailableCameras); + Future>.value(mockAvailableCameras); @override Future createCamera( @@ -1404,28 +1409,29 @@ class MockCameraPlatform extends Mock }) => mockPlatformException ? throw PlatformException(code: 'foo', message: 'bar') - : Future.value(mockInitializeCamera); + : Future.value(mockInitializeCamera); @override Stream onCameraInitialized(int cameraId) => - Stream.value(mockOnCameraInitializedEvent); + Stream.value(mockOnCameraInitializedEvent); @override Stream onCameraClosing(int cameraId) => - Stream.value(mockOnCameraClosingEvent); + Stream.value(mockOnCameraClosingEvent); @override Stream onCameraError(int cameraId) => - Stream.value(mockOnCameraErrorEvent); + Stream.value(mockOnCameraErrorEvent); @override Stream onDeviceOrientationChanged() => - Stream.value(mockOnDeviceOrientationChangedEvent); + Stream.value( + mockOnDeviceOrientationChangedEvent); @override Future takePicture(int cameraId) => mockPlatformException ? throw PlatformException(code: 'foo', message: 'bar') - : Future.value(mockTakePicture); + : Future.value(mockTakePicture); @override Future prepareForVideoRecording() async => @@ -1434,82 +1440,86 @@ class MockCameraPlatform extends Mock @override Future startVideoRecording(int cameraId, {Duration? maxVideoDuration}) => - Future.value(mockVideoRecordingXFile); + Future.value(mockVideoRecordingXFile); @override Future lockCaptureOrientation( int? cameraId, DeviceOrientation? orientation) async => - super.noSuchMethod( - Invocation.method(#lockCaptureOrientation, [cameraId, orientation])); + super.noSuchMethod(Invocation.method( + #lockCaptureOrientation, [cameraId, orientation])); @override - Future unlockCaptureOrientation(int? cameraId) async => super - .noSuchMethod(Invocation.method(#unlockCaptureOrientation, [cameraId])); + Future unlockCaptureOrientation(int? cameraId) async => + super.noSuchMethod( + Invocation.method(#unlockCaptureOrientation, [cameraId])); @override Future pausePreview(int? cameraId) async => - super.noSuchMethod(Invocation.method(#pausePreview, [cameraId])); + super.noSuchMethod(Invocation.method(#pausePreview, [cameraId])); @override - Future resumePreview(int? cameraId) async => - super.noSuchMethod(Invocation.method(#resumePreview, [cameraId])); + Future resumePreview(int? cameraId) async => super + .noSuchMethod(Invocation.method(#resumePreview, [cameraId])); @override Future getMaxZoomLevel(int? cameraId) async => super.noSuchMethod( - Invocation.method(#getMaxZoomLevel, [cameraId]), + Invocation.method(#getMaxZoomLevel, [cameraId]), returnValue: 1.0, - ); + ) as Future; @override Future getMinZoomLevel(int? cameraId) async => super.noSuchMethod( - Invocation.method(#getMinZoomLevel, [cameraId]), + Invocation.method(#getMinZoomLevel, [cameraId]), returnValue: 0.0, - ); + ) as Future; @override Future setZoomLevel(int? cameraId, double? zoom) async => - super.noSuchMethod(Invocation.method(#setZoomLevel, [cameraId, zoom])); + super.noSuchMethod( + Invocation.method(#setZoomLevel, [cameraId, zoom])); @override Future setFlashMode(int? cameraId, FlashMode? mode) async => - super.noSuchMethod(Invocation.method(#setFlashMode, [cameraId, mode])); + super.noSuchMethod( + Invocation.method(#setFlashMode, [cameraId, mode])); @override Future setExposureMode(int? cameraId, ExposureMode? mode) async => - super.noSuchMethod(Invocation.method(#setExposureMode, [cameraId, mode])); + super.noSuchMethod( + Invocation.method(#setExposureMode, [cameraId, mode])); @override Future setExposurePoint(int? cameraId, Point? point) async => super.noSuchMethod( - Invocation.method(#setExposurePoint, [cameraId, point])); + Invocation.method(#setExposurePoint, [cameraId, point])); @override Future getMinExposureOffset(int? cameraId) async => super.noSuchMethod( - Invocation.method(#getMinExposureOffset, [cameraId]), + Invocation.method(#getMinExposureOffset, [cameraId]), returnValue: 0.0, - ); + ) as Future; @override Future getMaxExposureOffset(int? cameraId) async => super.noSuchMethod( - Invocation.method(#getMaxExposureOffset, [cameraId]), + Invocation.method(#getMaxExposureOffset, [cameraId]), returnValue: 1.0, - ); + ) as Future; @override Future getExposureOffsetStepSize(int? cameraId) async => super.noSuchMethod( - Invocation.method(#getExposureOffsetStepSize, [cameraId]), + Invocation.method(#getExposureOffsetStepSize, [cameraId]), returnValue: 1.0, - ); + ) as Future; @override Future setExposureOffset(int? cameraId, double? offset) async => super.noSuchMethod( - Invocation.method(#setExposureOffset, [cameraId, offset]), + Invocation.method(#setExposureOffset, [cameraId, offset]), returnValue: 1.0, - ); + ) as Future; } class MockCameraDescription extends CameraDescription { diff --git a/packages/camera/camera/test/utils/method_channel_mock.dart b/packages/camera/camera/test/utils/method_channel_mock.dart index e6e2b58e9b16..7c8b4ca3d3f0 100644 --- a/packages/camera/camera/test/utils/method_channel_mock.dart +++ b/packages/camera/camera/test/utils/method_channel_mock.dart @@ -6,11 +6,6 @@ import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; class MethodChannelMock { - final Duration? delay; - final MethodChannel methodChannel; - final Map methods; - final List log = []; - MethodChannelMock({ required String channelName, this.delay, @@ -19,7 +14,12 @@ class MethodChannelMock { methodChannel.setMockMethodCallHandler(_handler); } - Future _handler(MethodCall methodCall) async { + final Duration? delay; + final MethodChannel methodChannel; + final Map methods; + final List log = []; + + Future _handler(MethodCall methodCall) async { log.add(methodCall); if (!methods.containsKey(methodCall.method)) { @@ -27,13 +27,13 @@ class MethodChannelMock { '${methodCall.method} on channel ${methodChannel.name}'); } - return Future.delayed(delay ?? Duration.zero, () { - final result = methods[methodCall.method]; + return Future.delayed(delay ?? Duration.zero, () { + final Object? result = methods[methodCall.method]; if (result is Exception) { throw result; } - return Future.value(result); + return Future.value(result); }); } } From 96d0da5dd4b6eba5c59b92514d1fda055469766b Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Fri, 11 Feb 2022 16:07:10 -0500 Subject: [PATCH 3/7] Version bump --- packages/camera/camera/CHANGELOG.md | 17 +++++++++-------- packages/camera/camera/pubspec.yaml | 2 +- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/packages/camera/camera/CHANGELOG.md b/packages/camera/camera/CHANGELOG.md index e92a7a815625..d2b2f907a6fb 100644 --- a/packages/camera/camera/CHANGELOG.md +++ b/packages/camera/camera/CHANGELOG.md @@ -1,19 +1,20 @@ -## NEXT +## 0.9.4+12 * Skips unnecessary AppDelegate setup for unit tests on iOS. - +* Internal code cleanup for stricter analysis options. + ## 0.9.4+11 -* Manages iOS camera's orientation-related states on a background queue to prevent potential race conditions. +* Manages iOS camera's orientation-related states on a background queue to prevent potential race conditions. ## 0.9.4+10 -* iOS performance improvement by moving file writing from the main queue to a background IO queue. +* iOS performance improvement by moving file writing from the main queue to a background IO queue. ## 0.9.4+9 -* iOS performance improvement by moving sample buffer handling from the main queue to a background session queue. -* Minor iOS internal code cleanup related to camera class and its delegate. +* iOS performance improvement by moving sample buffer handling from the main queue to a background session queue. +* Minor iOS internal code cleanup related to camera class and its delegate. * Minor iOS internal code cleanup related to resolution preset, video format, focus mode, exposure mode and device orientation. * Minor iOS internal code cleanup related to flash mode. @@ -23,12 +24,12 @@ ## 0.9.4+7 -* Fixes a crash in iOS when passing null queue pointer into AVFoundation API due to race condition. +* Fixes a crash in iOS when passing null queue pointer into AVFoundation API due to race condition. * Minor iOS internal code cleanup related to dispatch queue. ## 0.9.4+6 -* Fixes a crash in iOS when using image stream due to calling Flutter engine API on non-main thread. +* Fixes a crash in iOS when using image stream due to calling Flutter engine API on non-main thread. ## 0.9.4+5 diff --git a/packages/camera/camera/pubspec.yaml b/packages/camera/camera/pubspec.yaml index c12942a53487..7421a7738ddd 100644 --- a/packages/camera/camera/pubspec.yaml +++ b/packages/camera/camera/pubspec.yaml @@ -4,7 +4,7 @@ description: A Flutter plugin for controlling the camera. Supports previewing Dart. repository: https://github.com/flutter/plugins/tree/main/packages/camera/camera issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22 -version: 0.9.4+11 +version: 0.9.4+12 environment: sdk: ">=2.14.0 <3.0.0" From f88cbb06938012e928b8670afe9c3c23e98cff55 Mon Sep 17 00:00:00 2001 From: stuartmorgan Date: Mon, 14 Feb 2022 10:44:11 -0500 Subject: [PATCH 4/7] Remove pedantic --- packages/camera/camera/lib/src/camera_controller.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/camera/camera/lib/src/camera_controller.dart b/packages/camera/camera/lib/src/camera_controller.dart index b05049ec6503..0ae7d2db214c 100644 --- a/packages/camera/camera/lib/src/camera_controller.dart +++ b/packages/camera/camera/lib/src/camera_controller.dart @@ -10,7 +10,6 @@ import 'package:camera_platform_interface/camera_platform_interface.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; -import 'package:pedantic/pedantic.dart'; import 'package:quiver/core.dart'; const MethodChannel _channel = MethodChannel('plugins.flutter.io/camera'); From cd9a9449f5ea159c1820e932fcadc0c1027dcc2e Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Mon, 14 Feb 2022 12:57:52 -0500 Subject: [PATCH 5/7] Fix default mock return value types --- packages/camera/camera/test/camera_test.dart | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/camera/camera/test/camera_test.dart b/packages/camera/camera/test/camera_test.dart index 6062ad4d01ae..c4e0c9388231 100644 --- a/packages/camera/camera/test/camera_test.dart +++ b/packages/camera/camera/test/camera_test.dart @@ -1464,13 +1464,13 @@ class MockCameraPlatform extends Mock @override Future getMaxZoomLevel(int? cameraId) async => super.noSuchMethod( Invocation.method(#getMaxZoomLevel, [cameraId]), - returnValue: 1.0, + returnValue: Future.value(1.0), ) as Future; @override Future getMinZoomLevel(int? cameraId) async => super.noSuchMethod( Invocation.method(#getMinZoomLevel, [cameraId]), - returnValue: 0.0, + returnValue: Future.value(0.0), ) as Future; @override @@ -1497,28 +1497,28 @@ class MockCameraPlatform extends Mock Future getMinExposureOffset(int? cameraId) async => super.noSuchMethod( Invocation.method(#getMinExposureOffset, [cameraId]), - returnValue: 0.0, + returnValue: Future.value(0.0), ) as Future; @override Future getMaxExposureOffset(int? cameraId) async => super.noSuchMethod( Invocation.method(#getMaxExposureOffset, [cameraId]), - returnValue: 1.0, + returnValue: Future.value(1.0), ) as Future; @override Future getExposureOffsetStepSize(int? cameraId) async => super.noSuchMethod( Invocation.method(#getExposureOffsetStepSize, [cameraId]), - returnValue: 1.0, + returnValue: Future.value(1.0), ) as Future; @override Future setExposureOffset(int? cameraId, double? offset) async => super.noSuchMethod( Invocation.method(#setExposureOffset, [cameraId, offset]), - returnValue: 1.0, + returnValue: Future.value(1.0), ) as Future; } From 2407aacd795d5d6b5aead31a741e315d78f4a92c Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Mon, 14 Feb 2022 12:59:09 -0500 Subject: [PATCH 6/7] Fix a bad cast --- packages/camera/camera/lib/src/camera_image.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/camera/camera/lib/src/camera_image.dart b/packages/camera/camera/lib/src/camera_image.dart index cb68d0e41d0e..fd3a3d6233bc 100644 --- a/packages/camera/camera/lib/src/camera_image.dart +++ b/packages/camera/camera/lib/src/camera_image.dart @@ -105,7 +105,7 @@ class CameraImage { sensorSensitivity = data['sensorSensitivity'] as double?, planes = List.unmodifiable((data['planes'] as List) .map((dynamic planeData) => - Plane._fromPlatformData(planeData as Map))); + Plane._fromPlatformData(planeData as Map))); /// Format of the image provided. /// From e49efc30b6513b177b47c7d26ae866b90df15410 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Mon, 14 Feb 2022 13:21:44 -0500 Subject: [PATCH 7/7] Fix one more dangerous cast --- packages/camera/camera/lib/src/camera_controller.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/camera/camera/lib/src/camera_controller.dart b/packages/camera/camera/lib/src/camera_controller.dart index 0ae7d2db214c..835ac1680c6e 100644 --- a/packages/camera/camera/lib/src/camera_controller.dart +++ b/packages/camera/camera/lib/src/camera_controller.dart @@ -445,7 +445,7 @@ class CameraController extends ValueNotifier { cameraEventChannel.receiveBroadcastStream().listen( (dynamic imageData) { onAvailable( - CameraImage.fromPlatformData(imageData as Map)); + CameraImage.fromPlatformData(imageData as Map)); }, ); }