From 9a92621ce91a07efb62358debc590fed2a1694bf Mon Sep 17 00:00:00 2001 From: Maurits van Beusekom Date: Tue, 2 Feb 2021 14:56:49 +0100 Subject: [PATCH 01/12] Migrate camera_platform_interface to null safety --- .../method_channel_camera_test.dart | 62 +++++++++---------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/packages/camera/camera_platform_interface/test/method_channel/method_channel_camera_test.dart b/packages/camera/camera_platform_interface/test/method_channel/method_channel_camera_test.dart index 5248d34c46b9..f1d4c837685a 100644 --- a/packages/camera/camera_platform_interface/test/method_channel/method_channel_camera_test.dart +++ b/packages/camera/camera_platform_interface/test/method_channel/method_channel_camera_test.dart @@ -395,10 +395,10 @@ void main() { ), ResolutionPreset.high, ); - Future initializeFuture = camera.initializeCamera(cameraId); + Future initializeFuture = camera.initializeCamera(cameraId!); camera.cameraEventStreamController.add( CameraInitializedEvent( - cameraId, + cameraId!, 1920, 1080, ExposureMode.auto, @@ -471,7 +471,7 @@ void main() { methods: {'takePicture': '/test/path.jpg'}); // Act - XFile file = await camera.takePicture(cameraId); + XFile file = await camera.takePicture(cameraId!); // Assert expect(channel.log, [ @@ -506,7 +506,7 @@ void main() { ); // Act - await camera.startVideoRecording(cameraId); + await camera.startVideoRecording(cameraId!); // Assert expect(channel.log, [ @@ -527,7 +527,7 @@ void main() { // Act await camera.startVideoRecording( - cameraId, + cameraId!, maxVideoDuration: Duration(seconds: 10), ); @@ -546,7 +546,7 @@ void main() { ); // Act - XFile file = await camera.stopVideoRecording(cameraId); + XFile file = await camera.stopVideoRecording(cameraId!); // Assert expect(channel.log, [ @@ -565,7 +565,7 @@ void main() { ); // Act - await camera.pauseVideoRecording(cameraId); + await camera.pauseVideoRecording(cameraId!); // Assert expect(channel.log, [ @@ -583,7 +583,7 @@ void main() { ); // Act - await camera.resumeVideoRecording(cameraId); + await camera.resumeVideoRecording(cameraId!); // Assert expect(channel.log, [ @@ -601,10 +601,10 @@ void main() { ); // Act - await camera.setFlashMode(cameraId, FlashMode.torch); - await camera.setFlashMode(cameraId, FlashMode.always); - await camera.setFlashMode(cameraId, FlashMode.auto); - await camera.setFlashMode(cameraId, FlashMode.off); + await camera.setFlashMode(cameraId!, FlashMode.torch); + await camera.setFlashMode(cameraId!, FlashMode.always); + await camera.setFlashMode(cameraId!, FlashMode.auto); + await camera.setFlashMode(cameraId!, FlashMode.off); // Assert expect(channel.log, [ @@ -627,8 +627,8 @@ void main() { ); // Act - await camera.setExposureMode(cameraId, ExposureMode.auto); - await camera.setExposureMode(cameraId, ExposureMode.locked); + await camera.setExposureMode(cameraId!, ExposureMode.auto); + await camera.setExposureMode(cameraId!, ExposureMode.locked); // Assert expect(channel.log, [ @@ -647,8 +647,8 @@ void main() { ); // Act - await camera.setExposurePoint(cameraId, Point(0.5, 0.5)); - await camera.setExposurePoint(cameraId, null); + await camera.setExposurePoint(cameraId!, Point(0.5, 0.5)); + await camera.setExposurePoint(cameraId!, null); // Assert expect(channel.log, [ @@ -675,7 +675,7 @@ void main() { ); // Act - final minExposureOffset = await camera.getMinExposureOffset(cameraId); + final minExposureOffset = await camera.getMinExposureOffset(cameraId!); // Assert expect(minExposureOffset, 2.0); @@ -694,7 +694,7 @@ void main() { ); // Act - final maxExposureOffset = await camera.getMaxExposureOffset(cameraId); + final maxExposureOffset = await camera.getMaxExposureOffset(cameraId!); // Assert expect(maxExposureOffset, 2.0); @@ -713,7 +713,7 @@ void main() { ); // Act - final stepSize = await camera.getExposureOffsetStepSize(cameraId); + final stepSize = await camera.getExposureOffsetStepSize(cameraId!); // Assert expect(stepSize, 0.25); @@ -732,7 +732,7 @@ void main() { ); // Act - final actualOffset = await camera.setExposureOffset(cameraId, 0.5); + final actualOffset = await camera.setExposureOffset(cameraId!, 0.5); // Assert expect(actualOffset, 0.6); @@ -752,8 +752,8 @@ void main() { ); // Act - await camera.setFocusMode(cameraId, FocusMode.auto); - await camera.setFocusMode(cameraId, FocusMode.locked); + await camera.setFocusMode(cameraId!, FocusMode.auto); + await camera.setFocusMode(cameraId!, FocusMode.locked); // Assert expect(channel.log, [ @@ -772,8 +772,8 @@ void main() { ); // Act - await camera.setFocusPoint(cameraId, Point(0.5, 0.5)); - await camera.setFocusPoint(cameraId, null); + await camera.setFocusPoint(cameraId!, Point(0.5, 0.5)); + await camera.setFocusPoint(cameraId!, null); // Assert expect(channel.log, [ @@ -794,7 +794,7 @@ void main() { test('Should build a texture widget as preview widget', () async { // Act - Widget widget = camera.buildPreview(cameraId); + Widget widget = camera.buildPreview(cameraId!); // Act expect(widget is Texture, isTrue); @@ -819,7 +819,7 @@ void main() { ); // Act - final maxZoomLevel = await camera.getMaxZoomLevel(cameraId); + final maxZoomLevel = await camera.getMaxZoomLevel(cameraId!); // Assert expect(maxZoomLevel, 10.0); @@ -838,7 +838,7 @@ void main() { ); // Act - final maxZoomLevel = await camera.getMinZoomLevel(cameraId); + final maxZoomLevel = await camera.getMinZoomLevel(cameraId!); // Assert expect(maxZoomLevel, 1.0); @@ -857,7 +857,7 @@ void main() { ); // Act - await camera.setZoomLevel(cameraId, 2.0); + await camera.setZoomLevel(cameraId!, 2.0); // Assert expect(channel.log, [ @@ -882,7 +882,7 @@ void main() { // Act & assert expect( - () => camera.setZoomLevel(cameraId, -1.0), + () => camera.setZoomLevel(cameraId!, -1.0), throwsA(isA() .having((e) => e.code, 'code', 'ZOOM_ERROR') .having((e) => e.description, 'description', @@ -898,7 +898,7 @@ void main() { // Act await camera.lockCaptureOrientation( - cameraId, DeviceOrientation.portraitUp); + cameraId!, DeviceOrientation.portraitUp); // Assert expect(channel.log, [ @@ -915,7 +915,7 @@ void main() { ); // Act - await camera.unlockCaptureOrientation(cameraId); + await camera.unlockCaptureOrientation(cameraId!); // Assert expect(channel.log, [ From e94c6d87ca8aac8cf9ef40d171582923db9b62fb Mon Sep 17 00:00:00 2001 From: Maurits van Beusekom Date: Tue, 2 Feb 2021 15:43:13 +0100 Subject: [PATCH 02/12] Exclude camera_platform_interface from all plugins script --- script/build_all_plugins_app.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/script/build_all_plugins_app.sh b/script/build_all_plugins_app.sh index 399f1f1b79f7..ceeb50b3e72a 100755 --- a/script/build_all_plugins_app.sh +++ b/script/build_all_plugins_app.sh @@ -19,6 +19,7 @@ source "$SCRIPT_DIR/nnbd_plugins.sh" check_changed_packages > /dev/null readonly EXCLUDED_PLUGINS_LIST=( + "camera_platform_interface" # currently out of sync with google_maps_flutter due to NNBD migration "connectivity_macos" "connectivity_platform_interface" "connectivity_web" From 3147b589619268dffa40519c315bfaa6870d5d6e Mon Sep 17 00:00:00 2001 From: Maurits van Beusekom Date: Wed, 3 Feb 2021 08:51:50 +0100 Subject: [PATCH 03/12] Convert CameraId in test to non-nullable --- .../method_channel_camera_test.dart | 62 +++++++++---------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/packages/camera/camera_platform_interface/test/method_channel/method_channel_camera_test.dart b/packages/camera/camera_platform_interface/test/method_channel/method_channel_camera_test.dart index f1d4c837685a..5248d34c46b9 100644 --- a/packages/camera/camera_platform_interface/test/method_channel/method_channel_camera_test.dart +++ b/packages/camera/camera_platform_interface/test/method_channel/method_channel_camera_test.dart @@ -395,10 +395,10 @@ void main() { ), ResolutionPreset.high, ); - Future initializeFuture = camera.initializeCamera(cameraId!); + Future initializeFuture = camera.initializeCamera(cameraId); camera.cameraEventStreamController.add( CameraInitializedEvent( - cameraId!, + cameraId, 1920, 1080, ExposureMode.auto, @@ -471,7 +471,7 @@ void main() { methods: {'takePicture': '/test/path.jpg'}); // Act - XFile file = await camera.takePicture(cameraId!); + XFile file = await camera.takePicture(cameraId); // Assert expect(channel.log, [ @@ -506,7 +506,7 @@ void main() { ); // Act - await camera.startVideoRecording(cameraId!); + await camera.startVideoRecording(cameraId); // Assert expect(channel.log, [ @@ -527,7 +527,7 @@ void main() { // Act await camera.startVideoRecording( - cameraId!, + cameraId, maxVideoDuration: Duration(seconds: 10), ); @@ -546,7 +546,7 @@ void main() { ); // Act - XFile file = await camera.stopVideoRecording(cameraId!); + XFile file = await camera.stopVideoRecording(cameraId); // Assert expect(channel.log, [ @@ -565,7 +565,7 @@ void main() { ); // Act - await camera.pauseVideoRecording(cameraId!); + await camera.pauseVideoRecording(cameraId); // Assert expect(channel.log, [ @@ -583,7 +583,7 @@ void main() { ); // Act - await camera.resumeVideoRecording(cameraId!); + await camera.resumeVideoRecording(cameraId); // Assert expect(channel.log, [ @@ -601,10 +601,10 @@ void main() { ); // Act - await camera.setFlashMode(cameraId!, FlashMode.torch); - await camera.setFlashMode(cameraId!, FlashMode.always); - await camera.setFlashMode(cameraId!, FlashMode.auto); - await camera.setFlashMode(cameraId!, FlashMode.off); + await camera.setFlashMode(cameraId, FlashMode.torch); + await camera.setFlashMode(cameraId, FlashMode.always); + await camera.setFlashMode(cameraId, FlashMode.auto); + await camera.setFlashMode(cameraId, FlashMode.off); // Assert expect(channel.log, [ @@ -627,8 +627,8 @@ void main() { ); // Act - await camera.setExposureMode(cameraId!, ExposureMode.auto); - await camera.setExposureMode(cameraId!, ExposureMode.locked); + await camera.setExposureMode(cameraId, ExposureMode.auto); + await camera.setExposureMode(cameraId, ExposureMode.locked); // Assert expect(channel.log, [ @@ -647,8 +647,8 @@ void main() { ); // Act - await camera.setExposurePoint(cameraId!, Point(0.5, 0.5)); - await camera.setExposurePoint(cameraId!, null); + await camera.setExposurePoint(cameraId, Point(0.5, 0.5)); + await camera.setExposurePoint(cameraId, null); // Assert expect(channel.log, [ @@ -675,7 +675,7 @@ void main() { ); // Act - final minExposureOffset = await camera.getMinExposureOffset(cameraId!); + final minExposureOffset = await camera.getMinExposureOffset(cameraId); // Assert expect(minExposureOffset, 2.0); @@ -694,7 +694,7 @@ void main() { ); // Act - final maxExposureOffset = await camera.getMaxExposureOffset(cameraId!); + final maxExposureOffset = await camera.getMaxExposureOffset(cameraId); // Assert expect(maxExposureOffset, 2.0); @@ -713,7 +713,7 @@ void main() { ); // Act - final stepSize = await camera.getExposureOffsetStepSize(cameraId!); + final stepSize = await camera.getExposureOffsetStepSize(cameraId); // Assert expect(stepSize, 0.25); @@ -732,7 +732,7 @@ void main() { ); // Act - final actualOffset = await camera.setExposureOffset(cameraId!, 0.5); + final actualOffset = await camera.setExposureOffset(cameraId, 0.5); // Assert expect(actualOffset, 0.6); @@ -752,8 +752,8 @@ void main() { ); // Act - await camera.setFocusMode(cameraId!, FocusMode.auto); - await camera.setFocusMode(cameraId!, FocusMode.locked); + await camera.setFocusMode(cameraId, FocusMode.auto); + await camera.setFocusMode(cameraId, FocusMode.locked); // Assert expect(channel.log, [ @@ -772,8 +772,8 @@ void main() { ); // Act - await camera.setFocusPoint(cameraId!, Point(0.5, 0.5)); - await camera.setFocusPoint(cameraId!, null); + await camera.setFocusPoint(cameraId, Point(0.5, 0.5)); + await camera.setFocusPoint(cameraId, null); // Assert expect(channel.log, [ @@ -794,7 +794,7 @@ void main() { test('Should build a texture widget as preview widget', () async { // Act - Widget widget = camera.buildPreview(cameraId!); + Widget widget = camera.buildPreview(cameraId); // Act expect(widget is Texture, isTrue); @@ -819,7 +819,7 @@ void main() { ); // Act - final maxZoomLevel = await camera.getMaxZoomLevel(cameraId!); + final maxZoomLevel = await camera.getMaxZoomLevel(cameraId); // Assert expect(maxZoomLevel, 10.0); @@ -838,7 +838,7 @@ void main() { ); // Act - final maxZoomLevel = await camera.getMinZoomLevel(cameraId!); + final maxZoomLevel = await camera.getMinZoomLevel(cameraId); // Assert expect(maxZoomLevel, 1.0); @@ -857,7 +857,7 @@ void main() { ); // Act - await camera.setZoomLevel(cameraId!, 2.0); + await camera.setZoomLevel(cameraId, 2.0); // Assert expect(channel.log, [ @@ -882,7 +882,7 @@ void main() { // Act & assert expect( - () => camera.setZoomLevel(cameraId!, -1.0), + () => camera.setZoomLevel(cameraId, -1.0), throwsA(isA() .having((e) => e.code, 'code', 'ZOOM_ERROR') .having((e) => e.description, 'description', @@ -898,7 +898,7 @@ void main() { // Act await camera.lockCaptureOrientation( - cameraId!, DeviceOrientation.portraitUp); + cameraId, DeviceOrientation.portraitUp); // Assert expect(channel.log, [ @@ -915,7 +915,7 @@ void main() { ); // Act - await camera.unlockCaptureOrientation(cameraId!); + await camera.unlockCaptureOrientation(cameraId); // Assert expect(channel.log, [ From 96a9383aab2f03ddc185bbd895ebeaf44acee4e3 Mon Sep 17 00:00:00 2001 From: Maurits van Beusekom Date: Thu, 4 Feb 2021 16:27:07 +0100 Subject: [PATCH 04/12] Migrate to nullsafety --- .../camera/lib/src/camera_controller.dart | 93 ++++---- .../camera/camera/lib/src/camera_image.dart | 6 +- .../camera/camera/lib/src/camera_preview.dart | 6 +- packages/camera/camera/pubspec.yaml | 26 ++- packages/camera/camera/test/camera_test.dart | 211 ++++++++++++++---- .../camera/camera/test/camera_value_test.dart | 1 + .../test/utils/method_channel_mock.dart | 6 +- 7 files changed, 244 insertions(+), 105 deletions(-) diff --git a/packages/camera/camera/lib/src/camera_controller.dart b/packages/camera/camera/lib/src/camera_controller.dart index 80e83c867954..0eebcec75a0b 100644 --- a/packages/camera/camera/lib/src/camera_controller.dart +++ b/packages/camera/camera/lib/src/camera_controller.dart @@ -32,19 +32,19 @@ Future> availableCameras() async { class CameraValue { /// Creates a new camera controller state. const CameraValue({ - this.isInitialized, + required this.isInitialized, this.errorDescription, this.previewSize, - this.isRecordingVideo, - this.isTakingPicture, - this.isStreamingImages, - bool isRecordingPaused, - this.flashMode, + required this.isRecordingVideo, + required this.isTakingPicture, + required this.isStreamingImages, + required bool isRecordingPaused, + required this.flashMode, this.exposureMode, this.focusMode, - this.exposurePointSupported, - this.focusPointSupported, - this.deviceOrientation, + required this.exposurePointSupported, + required this.focusPointSupported, + required this.deviceOrientation, this.lockedCaptureOrientation, this.recordingOrientation, }) : _isRecordingPaused = isRecordingPaused; @@ -84,17 +84,17 @@ class CameraValue { /// /// This is null while the controller is not in an error state. /// When [hasError] is true this contains the error description. - final String errorDescription; + final String? errorDescription; /// The size of the preview in pixels. /// /// Is `null` until [isInitialized] is `true`. - final Size previewSize; + final Size? previewSize; /// Convenience getter for `previewSize.width / previewSize.height`. /// /// Can only be called when [initialize] is done. - double get aspectRatio => previewSize.width / previewSize.height; + double get aspectRatio => previewSize!.width / previewSize!.height; /// Whether the controller is in an error state. /// @@ -105,10 +105,10 @@ class CameraValue { final FlashMode flashMode; /// The exposure mode the camera is currently set to. - final ExposureMode exposureMode; + final ExposureMode? exposureMode; /// The focus mode the camera is currently set to. - final FocusMode focusMode; + final FocusMode? focusMode; /// Whether setting the exposure point is supported. final bool exposurePointSupported; @@ -120,34 +120,34 @@ class CameraValue { final DeviceOrientation deviceOrientation; /// The currently locked capture orientation. - final DeviceOrientation lockedCaptureOrientation; + final DeviceOrientation? lockedCaptureOrientation; /// Whether the capture orientation is currently locked. bool get isCaptureOrientationLocked => lockedCaptureOrientation != null; /// The orientation of the currently running video recording. - final DeviceOrientation recordingOrientation; + final DeviceOrientation? recordingOrientation; /// Creates a modified copy of the object. /// /// Explicitly specified fields get the specified value, all other fields get /// the same value of the current object. CameraValue copyWith({ - bool isInitialized, - bool isRecordingVideo, - bool isTakingPicture, - bool isStreamingImages, - String errorDescription, - Size previewSize, - bool isRecordingPaused, - FlashMode flashMode, - ExposureMode exposureMode, - FocusMode focusMode, - bool exposurePointSupported, - bool focusPointSupported, - DeviceOrientation deviceOrientation, - Optional lockedCaptureOrientation, - Optional recordingOrientation, + bool? isInitialized, + bool? isRecordingVideo, + bool? isTakingPicture, + bool? isStreamingImages, + String? errorDescription, + Size? previewSize, + bool? isRecordingPaused, + FlashMode? flashMode, + ExposureMode? exposureMode, + FocusMode? focusMode, + bool? exposurePointSupported, + bool? focusPointSupported, + DeviceOrientation? deviceOrientation, + Optional? lockedCaptureOrientation, + Optional? recordingOrientation, }) { return CameraValue( isInitialized: isInitialized ?? this.isInitialized, @@ -225,13 +225,17 @@ class CameraController extends ValueNotifier { /// The [ImageFormatGroup] describes the output of the raw image format. /// /// When null the imageFormat will fallback to the platforms default. - final ImageFormatGroup imageFormatGroup; + final ImageFormatGroup? imageFormatGroup; + + /// The id of a camera that hasn't been initialized. + @visibleForTesting + static const int kUninitializedCameraId = -1; + int _cameraId = kUninitializedCameraId; - int _cameraId; bool _isDisposed = false; - StreamSubscription _imageStreamSubscription; - FutureOr _initCalled; - StreamSubscription _deviceOrientationSubscription; + StreamSubscription? _imageStreamSubscription; + FutureOr? _initCalled; + StreamSubscription? _deviceOrientationSubscription; /// Checks whether [CameraController.dispose] has completed successfully. /// @@ -278,7 +282,7 @@ class CameraController extends ValueNotifier { await CameraPlatform.instance.initializeCamera( _cameraId, - imageFormatGroup: imageFormatGroup, + imageFormatGroup: imageFormatGroup ?? ImageFormatGroup.unknown, ); value = value.copyWith( @@ -422,7 +426,7 @@ class CameraController extends ValueNotifier { throw CameraException(e.code, e.message); } - await _imageStreamSubscription.cancel(); + await _imageStreamSubscription?.cancel(); _imageStreamSubscription = null; } @@ -583,12 +587,16 @@ class CameraController extends ValueNotifier { } /// Sets the exposure point for automatically determining the exposure value. - Future setExposurePoint(Offset point) async { + /// + /// Supplying a `null` value will reset the exposure point to it's default + /// value. + Future setExposurePoint(Offset? point) async { if (point != null && (point.dx < 0 || point.dx > 1 || point.dy < 0 || point.dy > 1)) { throw ArgumentError( 'The values of point should be anywhere between (0,0) and (1,1).'); } + try { await CameraPlatform.instance.setExposurePoint( _cameraId, @@ -682,7 +690,7 @@ class CameraController extends ValueNotifier { /// Locks the capture orientation. /// /// If [orientation] is omitted, the current device orientation is used. - Future lockCaptureOrientation([DeviceOrientation orientation]) async { + Future lockCaptureOrientation([DeviceOrientation? orientation]) async { try { await CameraPlatform.instance.lockCaptureOrientation( _cameraId, orientation ?? value.deviceOrientation); @@ -715,7 +723,10 @@ class CameraController extends ValueNotifier { } /// Sets the focus point for automatically determining the focus value. - Future setFocusPoint(Offset point) async { + /// + /// Supplying a `null` value will reset the focus point to it's default + /// value. + Future setFocusPoint(Offset? point) async { if (point != null && (point.dx < 0 || point.dx > 1 || point.dy < 0 || point.dy > 1)) { throw ArgumentError( diff --git a/packages/camera/camera/lib/src/camera_image.dart b/packages/camera/camera/lib/src/camera_image.dart index dffa5066d14f..46aa2a6e3091 100644 --- a/packages/camera/camera/lib/src/camera_image.dart +++ b/packages/camera/camera/lib/src/camera_image.dart @@ -26,7 +26,7 @@ class Plane { /// The distance between adjacent pixel samples on Android, in bytes. /// /// Will be `null` on iOS. - final int bytesPerPixel; + final int? bytesPerPixel; /// The row stride for this color plane, in bytes. final int bytesPerRow; @@ -34,12 +34,12 @@ class Plane { /// Height of the pixel buffer on iOS. /// /// Will be `null` on Android - final int height; + final int? height; /// Width of the pixel buffer on iOS. /// /// Will be `null` on Android. - final int width; + final int? width; } /// Describes how pixels are represented in an image. diff --git a/packages/camera/camera/lib/src/camera_preview.dart b/packages/camera/camera/lib/src/camera_preview.dart index 05e969004233..f6d357b41b77 100644 --- a/packages/camera/camera/lib/src/camera_preview.dart +++ b/packages/camera/camera/lib/src/camera_preview.dart @@ -17,7 +17,7 @@ class CameraPreview extends StatelessWidget { final CameraController controller; /// A widget to overlay on top of the camera preview - final Widget child; + final Widget? child; @override Widget build(BuildContext context) { @@ -43,7 +43,7 @@ class CameraPreview extends StatelessWidget { DeviceOrientation _getApplicableOrientation() { return controller.value.isRecordingVideo - ? controller.value.recordingOrientation + ? controller.value.recordingOrientation! : (controller.value.lockedCaptureOrientation ?? controller.value.deviceOrientation); } @@ -61,6 +61,6 @@ class CameraPreview extends StatelessWidget { DeviceOrientation.portraitDown: 2, DeviceOrientation.landscapeRight: 3, }; - return turns[_getApplicableOrientation()] + platformOffset; + return turns[_getApplicableOrientation()]! + platformOffset; } } diff --git a/packages/camera/camera/pubspec.yaml b/packages/camera/camera/pubspec.yaml index 5ac4b57a15ef..807ffdfaa465 100644 --- a/packages/camera/camera/pubspec.yaml +++ b/packages/camera/camera/pubspec.yaml @@ -2,25 +2,33 @@ name: camera description: A Flutter plugin for getting information about and controlling the camera on Android and iOS. Supports previewing the camera feed, capturing images, capturing video, and streaming image buffers to dart. -version: 0.7.0+4 +version: 0.8.0-nullsafety homepage: https://github.com/flutter/plugins/tree/master/packages/camera/camera +# TODO(mvanbeusekom): Contains temporary path reference so should not be publishable. Remove once +# PR 3497 has been merged and published. +publish_to: none + dependencies: flutter: sdk: flutter - camera_platform_interface: ^1.5.0 - pedantic: ^1.8.0 - quiver: ^2.1.5 + + # TODO(mvanbeusekom): Temporary reference via path to continue NNDB development. Remove once + # PR 3497 has been merged and published. + camera_platform_interface: + path: ../camera_platform_interface + + pedantic: ^1.10.0-nullsafety.3 + quiver: ^3.0.0-nullsafety.3 dev_dependencies: - path_provider: ^0.5.0 - video_player: ^0.10.0 + video_player: ^2.0.0-nullsafety.7 flutter_test: sdk: flutter flutter_driver: sdk: flutter - mockito: ^4.1.3 - plugin_platform_interface: ^1.0.3 + mockito: ^5.0.0-nullsafety.5 + plugin_platform_interface: ^1.1.0-nullsafety.2 flutter: plugin: @@ -32,5 +40,5 @@ flutter: pluginClass: CameraPlugin environment: - sdk: ">=2.7.0 <3.0.0" + sdk: '>=2.12.0-133.7.beta <3.0.0' flutter: ">=1.12.13+hotfix.5" diff --git a/packages/camera/camera/test/camera_test.dart b/packages/camera/camera/test/camera_test.dart index d0b09fae1304..68c1b38fbc44 100644 --- a/packages/camera/camera/test/camera_test.dart +++ b/packages/camera/camera/test/camera_test.dart @@ -426,10 +426,10 @@ void main() { await cameraController.initialize(); when(CameraPlatform.instance.getMaxZoomLevel(mockInitializeCamera)) - .thenThrow(PlatformException( - code: 'TEST_ERROR', - message: 'This is a test error messge', - details: null)); + .thenThrow(CameraException( + 'TEST_ERROR', + 'This is a test error messge', + )); expect( cameraController.getMaxZoomLevel, @@ -526,10 +526,10 @@ void main() { await cameraController.initialize(); when(CameraPlatform.instance.getMinZoomLevel(mockInitializeCamera)) - .thenThrow(PlatformException( - code: 'TEST_ERROR', - message: 'This is a test error messge', - details: null)); + .thenThrow(CameraException( + 'TEST_ERROR', + 'This is a test error messge', + )); expect( cameraController.getMinZoomLevel, @@ -625,10 +625,10 @@ void main() { await cameraController.initialize(); when(CameraPlatform.instance.setZoomLevel(mockInitializeCamera, 42.0)) - .thenThrow(PlatformException( - code: 'TEST_ERROR', - message: 'This is a test error messge', - details: null)); + .thenThrow(CameraException( + 'TEST_ERROR', + 'This is a test error messge', + )); expect( () => cameraController.setZoomLevel(42), @@ -804,6 +804,10 @@ void main() { ResolutionPreset.max); await cameraController.initialize(); + when(CameraPlatform.instance + .getMinExposureOffset(cameraController.cameraId)) + .thenAnswer((_) => Future.value(0.0)); + await cameraController.getMinExposureOffset(); verify(CameraPlatform.instance @@ -824,10 +828,9 @@ void main() { when(CameraPlatform.instance .getMinExposureOffset(cameraController.cameraId)) .thenThrow( - PlatformException( - code: 'TEST_ERROR', - message: 'This is a test error message', - details: null, + CameraException( + 'TEST_ERROR', + 'This is a test error message', ), ); @@ -849,6 +852,10 @@ void main() { ResolutionPreset.max); await cameraController.initialize(); + when(CameraPlatform.instance + .getMaxExposureOffset(cameraController.cameraId)) + .thenAnswer((_) => Future.value(1.0)); + await cameraController.getMaxExposureOffset(); verify(CameraPlatform.instance @@ -869,10 +876,9 @@ void main() { when(CameraPlatform.instance .getMaxExposureOffset(cameraController.cameraId)) .thenThrow( - PlatformException( - code: 'TEST_ERROR', - message: 'This is a test error message', - details: null, + CameraException( + 'TEST_ERROR', + 'This is a test error message', ), ); @@ -894,10 +900,14 @@ void main() { ResolutionPreset.max); await cameraController.initialize(); + when(CameraPlatform.instance + .getExposureOffsetStepSize(cameraController.cameraId)) + .thenAnswer((_) => Future.value(0.0)); + await cameraController.getExposureOffsetStepSize(); verify(CameraPlatform.instance - .getMinExposureOffset(cameraController.cameraId)) + .getExposureOffsetStepSize(cameraController.cameraId)) .called(1); }); @@ -915,10 +925,9 @@ void main() { when(CameraPlatform.instance .getExposureOffsetStepSize(cameraController.cameraId)) .thenThrow( - PlatformException( - code: 'TEST_ERROR', - message: 'This is a test error message', - details: null, + CameraException( + 'TEST_ERROR', + 'This is a test error message', ), ); @@ -948,6 +957,9 @@ void main() { when(CameraPlatform.instance .getExposureOffsetStepSize(cameraController.cameraId)) .thenAnswer((_) async => 1.0); + when(CameraPlatform.instance + .setExposureOffset(cameraController.cameraId, 1.0)) + .thenAnswer((_) async => 1.0); await cameraController.setExposureOffset(1.0); @@ -977,10 +989,9 @@ void main() { when(CameraPlatform.instance .setExposureOffset(cameraController.cameraId, 1.0)) .thenThrow( - PlatformException( - code: 'TEST_ERROR', - message: 'This is a test error message', - details: null, + CameraException( + 'TEST_ERROR', + 'This is a test error message', ), ); @@ -1012,6 +1023,15 @@ void main() { when(CameraPlatform.instance .getExposureOffsetStepSize(cameraController.cameraId)) .thenAnswer((_) async => 1.0); + when(CameraPlatform.instance + .setExposureOffset(cameraController.cameraId, 0.0)) + .thenAnswer((_) async => 0.0); + when(CameraPlatform.instance + .setExposureOffset(cameraController.cameraId, -1.0)) + .thenAnswer((_) async => 0.0); + when(CameraPlatform.instance + .setExposureOffset(cameraController.cameraId, 2.0)) + .thenAnswer((_) async => 0.0); expect( cameraController.setExposureOffset(3.0), @@ -1028,17 +1048,18 @@ void main() { 'The provided exposure offset was outside the supported range for this device.', ))); - await cameraController.setExposureOffset(2.0); + await cameraController.setExposureOffset(0.0); await cameraController.setExposureOffset(-1.0); - await cameraController.setExposureOffset(-0.0); + await cameraController.setExposureOffset(2.0); + verify(CameraPlatform.instance - .setExposureOffset(cameraController.cameraId, 2.0)) + .setExposureOffset(cameraController.cameraId, 0.0)) .called(1); verify(CameraPlatform.instance .setExposureOffset(cameraController.cameraId, -1.0)) .called(1); verify(CameraPlatform.instance - .setExposureOffset(cameraController.cameraId, 0.0)) + .setExposureOffset(cameraController.cameraId, 2.0)) .called(1); }); @@ -1052,19 +1073,38 @@ void main() { await cameraController.initialize(); when(CameraPlatform.instance .getMinExposureOffset(cameraController.cameraId)) - .thenAnswer((_) async => -1.0); + .thenAnswer((_) async => -1.2); when(CameraPlatform.instance .getMaxExposureOffset(cameraController.cameraId)) - .thenAnswer((_) async => 1.0); + .thenAnswer((_) async => 1.2); when(CameraPlatform.instance .getExposureOffsetStepSize(cameraController.cameraId)) .thenAnswer((_) async => 0.4); + when(CameraPlatform.instance - .setExposureOffset(cameraController.cameraId, 1.0)) - .thenAnswer((_) async => 1.0); + .setExposureOffset(cameraController.cameraId, -1.2)) + .thenAnswer((_) async => -1.2); + when(CameraPlatform.instance + .setExposureOffset(cameraController.cameraId, -0.8)) + .thenAnswer((_) async => -0.8); + when(CameraPlatform.instance + .setExposureOffset(cameraController.cameraId, -0.4)) + .thenAnswer((_) async => -0.4); + when(CameraPlatform.instance + .setExposureOffset(cameraController.cameraId, 0.0)) + .thenAnswer((_) async => 0.0); + when(CameraPlatform.instance + .setExposureOffset(cameraController.cameraId, 0.4)) + .thenAnswer((_) async => 0.4); + when(CameraPlatform.instance + .setExposureOffset(cameraController.cameraId, 0.8)) + .thenAnswer((_) async => 0.8); + when(CameraPlatform.instance + .setExposureOffset(cameraController.cameraId, 1.2)) + .thenAnswer((_) async => 1.2); - await cameraController.setExposureOffset(1.0); - await cameraController.setExposureOffset(-1.0); + await cameraController.setExposureOffset(1.2); + await cameraController.setExposureOffset(-1.2); await cameraController.setExposureOffset(0.1); await cameraController.setExposureOffset(0.2); await cameraController.setExposureOffset(0.3); @@ -1082,10 +1122,10 @@ void main() { verify(CameraPlatform.instance .setExposureOffset(cameraController.cameraId, 0.8)) - .called(3); + .called(2); verify(CameraPlatform.instance .setExposureOffset(cameraController.cameraId, -0.8)) - .called(3); + .called(2); verify(CameraPlatform.instance .setExposureOffset(cameraController.cameraId, 0.0)) .called(2); @@ -1203,8 +1243,22 @@ class MockCameraPlatform extends Mock with MockPlatformInterfaceMixin implements CameraPlatform { @override - Future initializeCamera(int cameraId, - {ImageFormatGroup imageFormatGroup}); + Future initializeCamera( + int? cameraId, { + ImageFormatGroup? imageFormatGroup = ImageFormatGroup.unknown, + }) async => + super.noSuchMethod(Invocation.method( + #initializeCamera, + [cameraId], + { + #imageFormatGroup: imageFormatGroup, + }, + )); + + @override + Future dispose(int? cameraId) async { + return super.noSuchMethod(Invocation.method(#dispose, [cameraId])); + } @override Future> availableCameras() => @@ -1213,8 +1267,8 @@ class MockCameraPlatform extends Mock @override Future createCamera( CameraDescription description, - ResolutionPreset resolutionPreset, { - bool enableAudio, + ResolutionPreset? resolutionPreset, { + bool enableAudio = true, }) => mockPlatformException ? throw PlatformException(code: 'foo', message: 'bar') @@ -1241,13 +1295,78 @@ class MockCameraPlatform extends Mock ? throw PlatformException(code: 'foo', message: 'bar') : Future.value(mockTakePicture); + @override + Future prepareForVideoRecording() async => + super.noSuchMethod(Invocation.method(#prepareForVideoRecording, null)); + @override Future startVideoRecording(int cameraId, - {Duration maxVideoDuration}) => + {Duration? maxVideoDuration}) => Future.value(mockVideoRecordingXFile); + + @override + Future lockCaptureOrientation( + int? cameraId, DeviceOrientation? orientation) async => + super.noSuchMethod( + Invocation.method(#lockCaptureOrientation, [cameraId, orientation])); + + @override + Future unlockCaptureOrientation(int? cameraId) async => super + .noSuchMethod(Invocation.method(#unlockCaptureOrientation, [cameraId])); + + @override + Future getMaxZoomLevel(int? cameraId) async => + super.noSuchMethod(Invocation.method(#getMaxZoomLevel, [cameraId]), 1.0); + + @override + Future getMinZoomLevel(int? cameraId) async => + super.noSuchMethod(Invocation.method(#getMinZoomLevel, [cameraId]), 0.0); + + @override + Future setZoomLevel(int? cameraId, double? zoom) async => + super.noSuchMethod(Invocation.method(#setZoomLevel, [cameraId, zoom])); + + @override + Future setFlashMode(int? cameraId, FlashMode? mode) async => + super.noSuchMethod(Invocation.method(#setFlashMode, [cameraId, mode])); + + @override + Future setExposureMode(int? cameraId, ExposureMode? mode) async => + super.noSuchMethod(Invocation.method(#setExposureMode, [cameraId, mode])); + + @override + Future setExposurePoint(int? cameraId, Point? point) async => + super.noSuchMethod( + Invocation.method(#setExposurePoint, [cameraId, point])); + + @override + Future getMinExposureOffset(int? cameraId) async => super + .noSuchMethod(Invocation.method(#getMinExposureOffset, [cameraId]), 0.0); + + @override + Future getMaxExposureOffset(int? cameraId) async => super + .noSuchMethod(Invocation.method(#getMaxExposureOffset, [cameraId]), 1.0); + + @override + Future getExposureOffsetStepSize(int? cameraId) async => + super.noSuchMethod( + Invocation.method(#getExposureOffsetStepSize, [cameraId]), 1.0); + + @override + Future setExposureOffset(int? cameraId, double? offset) async => + super.noSuchMethod( + Invocation.method(#setExposureOffset, [cameraId, offset]), 1.0); } class MockCameraDescription extends CameraDescription { + /// Creates a new camera description with the given properties. + MockCameraDescription() + : super( + name: 'Test', + lensDirection: CameraLensDirection.back, + sensorOrientation: 0, + ); + @override CameraLensDirection get lensDirection => CameraLensDirection.back; diff --git a/packages/camera/camera/test/camera_value_test.dart b/packages/camera/camera/test/camera_value_test.dart index c365f6ddb9de..8610962655ac 100644 --- a/packages/camera/camera/test/camera_value_test.dart +++ b/packages/camera/camera/test/camera_value_test.dart @@ -27,6 +27,7 @@ void main() { deviceOrientation: DeviceOrientation.portraitUp, lockedCaptureOrientation: DeviceOrientation.portraitUp, recordingOrientation: DeviceOrientation.portraitUp, + focusPointSupported: true, ); expect(cameraValue, isA()); diff --git a/packages/camera/camera/test/utils/method_channel_mock.dart b/packages/camera/camera/test/utils/method_channel_mock.dart index cdf393f82b5f..fdbd9a18f29c 100644 --- a/packages/camera/camera/test/utils/method_channel_mock.dart +++ b/packages/camera/camera/test/utils/method_channel_mock.dart @@ -5,15 +5,15 @@ import 'package:flutter/services.dart'; class MethodChannelMock { - final Duration delay; + final Duration? delay; final MethodChannel methodChannel; final Map methods; final log = []; MethodChannelMock({ - String channelName, + required String channelName, this.delay, - this.methods, + required this.methods, }) : methodChannel = MethodChannel(channelName) { methodChannel.setMockMethodCallHandler(_handler); } From 29559b5d51197b06d1c79cbfe2c26ecf55b47d24 Mon Sep 17 00:00:00 2001 From: Maurits van Beusekom Date: Fri, 5 Feb 2021 18:19:29 +0100 Subject: [PATCH 05/12] Attempt to fix dependency problem building all plugins --- script/build_all_plugins_app.sh | 1 - script/nnbd_plugins.sh | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/script/build_all_plugins_app.sh b/script/build_all_plugins_app.sh index ceeb50b3e72a..399f1f1b79f7 100755 --- a/script/build_all_plugins_app.sh +++ b/script/build_all_plugins_app.sh @@ -19,7 +19,6 @@ source "$SCRIPT_DIR/nnbd_plugins.sh" check_changed_packages > /dev/null readonly EXCLUDED_PLUGINS_LIST=( - "camera_platform_interface" # currently out of sync with google_maps_flutter due to NNBD migration "connectivity_macos" "connectivity_platform_interface" "connectivity_web" diff --git a/script/nnbd_plugins.sh b/script/nnbd_plugins.sh index a2c22c67948a..6061bd36752a 100644 --- a/script/nnbd_plugins.sh +++ b/script/nnbd_plugins.sh @@ -8,7 +8,7 @@ readonly NNBD_PLUGINS_LIST=( "android_alarm_manager" "android_intent" "battery" - "camera" + "camera_platform_interface" "connectivity" "cross_file" "device_info" From 6cc215b4f5f8dd3699e83d2b7f6e5ab2a755ac89 Mon Sep 17 00:00:00 2001 From: Maurits van Beusekom Date: Wed, 10 Feb 2021 11:05:07 +0100 Subject: [PATCH 06/12] Update version information --- .../camera/example/ios/Flutter/Debug.xcconfig | 1 + .../example/ios/Flutter/Release.xcconfig | 1 + .../ios/Runner.xcodeproj/project.pbxproj | 19 ----------- .../contents.xcworkspacedata | 2 +- packages/camera/camera/pubspec.yaml | 8 ++--- packages/camera/camera/test/camera_test.dart | 34 +++++++++++++------ 6 files changed, 31 insertions(+), 34 deletions(-) diff --git a/packages/camera/camera/example/ios/Flutter/Debug.xcconfig b/packages/camera/camera/example/ios/Flutter/Debug.xcconfig index e8efba114687..b2f5fae9c254 100644 --- a/packages/camera/camera/example/ios/Flutter/Debug.xcconfig +++ b/packages/camera/camera/example/ios/Flutter/Debug.xcconfig @@ -1,2 +1,3 @@ +#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig" #include "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig" #include "Generated.xcconfig" diff --git a/packages/camera/camera/example/ios/Flutter/Release.xcconfig b/packages/camera/camera/example/ios/Flutter/Release.xcconfig index 399e9340e6f6..88c29144c836 100644 --- a/packages/camera/camera/example/ios/Flutter/Release.xcconfig +++ b/packages/camera/camera/example/ios/Flutter/Release.xcconfig @@ -1,2 +1,3 @@ +#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig" #include "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig" #include "Generated.xcconfig" diff --git a/packages/camera/camera/example/ios/Runner.xcodeproj/project.pbxproj b/packages/camera/camera/example/ios/Runner.xcodeproj/project.pbxproj index d51240a02c14..3f71bb69d6b6 100644 --- a/packages/camera/camera/example/ios/Runner.xcodeproj/project.pbxproj +++ b/packages/camera/camera/example/ios/Runner.xcodeproj/project.pbxproj @@ -147,7 +147,6 @@ 97C146EC1CF9000F007C117D /* Resources */, 9705A1C41CF9048500538489 /* Embed Frameworks */, 3B06AD1E1E4923F5004D2608 /* Thin Binary */, - FE224661708E6DA2A0F8B952 /* [CP] Embed Pods Frameworks */, ); buildRules = ( ); @@ -252,24 +251,6 @@ shellPath = /bin/sh; shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build"; }; - FE224661708E6DA2A0F8B952 /* [CP] Embed Pods Frameworks */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh", - "${PODS_ROOT}/../Flutter/Flutter.framework", - ); - name = "[CP] Embed Pods Frameworks"; - outputPaths = ( - "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Flutter.framework", - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n"; - showEnvVarsInLog = 0; - }; /* End PBXShellScriptBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ diff --git a/packages/camera/camera/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/packages/camera/camera/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata index 1d526a16ed0f..919434a6254f 100644 --- a/packages/camera/camera/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata +++ b/packages/camera/camera/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -2,6 +2,6 @@ + location = "self:"> diff --git a/packages/camera/camera/pubspec.yaml b/packages/camera/camera/pubspec.yaml index 807ffdfaa465..ab298eb5f9f6 100644 --- a/packages/camera/camera/pubspec.yaml +++ b/packages/camera/camera/pubspec.yaml @@ -6,7 +6,7 @@ version: 0.8.0-nullsafety homepage: https://github.com/flutter/plugins/tree/master/packages/camera/camera # TODO(mvanbeusekom): Contains temporary path reference so should not be publishable. Remove once -# PR 3497 has been merged and published. +# PR 3530 has been merged and published. publish_to: none dependencies: @@ -14,7 +14,7 @@ dependencies: sdk: flutter # TODO(mvanbeusekom): Temporary reference via path to continue NNDB development. Remove once - # PR 3497 has been merged and published. + # PR 3530 has been merged and published. camera_platform_interface: path: ../camera_platform_interface @@ -40,5 +40,5 @@ flutter: pluginClass: CameraPlugin environment: - sdk: '>=2.12.0-133.7.beta <3.0.0' - flutter: ">=1.12.13+hotfix.5" + sdk: '>=2.12.0-0 <3.0.0' + flutter: ">=1.22.0" diff --git a/packages/camera/camera/test/camera_test.dart b/packages/camera/camera/test/camera_test.dart index 68c1b38fbc44..b37b7701a14f 100644 --- a/packages/camera/camera/test/camera_test.dart +++ b/packages/camera/camera/test/camera_test.dart @@ -1315,12 +1315,16 @@ class MockCameraPlatform extends Mock .noSuchMethod(Invocation.method(#unlockCaptureOrientation, [cameraId])); @override - Future getMaxZoomLevel(int? cameraId) async => - super.noSuchMethod(Invocation.method(#getMaxZoomLevel, [cameraId]), 1.0); + Future getMaxZoomLevel(int? cameraId) async => super.noSuchMethod( + Invocation.method(#getMaxZoomLevel, [cameraId]), + returnValue: 1.0, + ); @override - Future getMinZoomLevel(int? cameraId) async => - super.noSuchMethod(Invocation.method(#getMinZoomLevel, [cameraId]), 0.0); + Future getMinZoomLevel(int? cameraId) async => super.noSuchMethod( + Invocation.method(#getMinZoomLevel, [cameraId]), + returnValue: 0.0, + ); @override Future setZoomLevel(int? cameraId, double? zoom) async => @@ -1340,22 +1344,32 @@ class MockCameraPlatform extends Mock Invocation.method(#setExposurePoint, [cameraId, point])); @override - Future getMinExposureOffset(int? cameraId) async => super - .noSuchMethod(Invocation.method(#getMinExposureOffset, [cameraId]), 0.0); + Future getMinExposureOffset(int? cameraId) async => + super.noSuchMethod( + Invocation.method(#getMinExposureOffset, [cameraId]), + returnValue: 0.0, + ); @override - Future getMaxExposureOffset(int? cameraId) async => super - .noSuchMethod(Invocation.method(#getMaxExposureOffset, [cameraId]), 1.0); + Future getMaxExposureOffset(int? cameraId) async => + super.noSuchMethod( + Invocation.method(#getMaxExposureOffset, [cameraId]), + returnValue: 1.0, + ); @override Future getExposureOffsetStepSize(int? cameraId) async => super.noSuchMethod( - Invocation.method(#getExposureOffsetStepSize, [cameraId]), 1.0); + Invocation.method(#getExposureOffsetStepSize, [cameraId]), + returnValue: 1.0, + ); @override Future setExposureOffset(int? cameraId, double? offset) async => super.noSuchMethod( - Invocation.method(#setExposureOffset, [cameraId, offset]), 1.0); + Invocation.method(#setExposureOffset, [cameraId, offset]), + returnValue: 1.0, + ); } class MockCameraDescription extends CameraDescription { From 0963416a306aa0c34335c7070ae472af303d3453 Mon Sep 17 00:00:00 2001 From: Maurits van Beusekom Date: Wed, 10 Feb 2021 17:48:00 +0100 Subject: [PATCH 07/12] Fix type --- 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 0eebcec75a0b..010541ebd643 100644 --- a/packages/camera/camera/lib/src/camera_controller.dart +++ b/packages/camera/camera/lib/src/camera_controller.dart @@ -88,7 +88,7 @@ class CameraValue { /// The size of the preview in pixels. /// - /// Is `null` until [isInitialized] is `true`. + /// Is `null` until [isInitialized] is `true`. final Size? previewSize; /// Convenience getter for `previewSize.width / previewSize.height`. From 7ad589a3856646709218bf9c389a3bb5c5812efd Mon Sep 17 00:00:00 2001 From: Maurits van Beusekom Date: Thu, 11 Feb 2021 08:49:52 +0100 Subject: [PATCH 08/12] Make exposureMode and focusMode non-nullable --- packages/camera/camera/lib/src/camera_controller.dart | 10 ++++++---- packages/camera/camera/test/camera_value_test.dart | 7 +++++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/packages/camera/camera/lib/src/camera_controller.dart b/packages/camera/camera/lib/src/camera_controller.dart index 010541ebd643..bb976d1c85fe 100644 --- a/packages/camera/camera/lib/src/camera_controller.dart +++ b/packages/camera/camera/lib/src/camera_controller.dart @@ -40,8 +40,8 @@ class CameraValue { required this.isStreamingImages, required bool isRecordingPaused, required this.flashMode, - this.exposureMode, - this.focusMode, + required this.exposureMode, + required this.focusMode, required this.exposurePointSupported, required this.focusPointSupported, required this.deviceOrientation, @@ -58,7 +58,9 @@ class CameraValue { isStreamingImages: false, isRecordingPaused: false, flashMode: FlashMode.auto, + exposureMode: ExposureMode.auto, exposurePointSupported: false, + focusMode: FocusMode.auto, focusPointSupported: false, deviceOrientation: DeviceOrientation.portraitUp, ); @@ -105,10 +107,10 @@ class CameraValue { final FlashMode flashMode; /// The exposure mode the camera is currently set to. - final ExposureMode? exposureMode; + final ExposureMode exposureMode; /// The focus mode the camera is currently set to. - final FocusMode? focusMode; + final FocusMode focusMode; /// Whether setting the exposure point is supported. final bool exposurePointSupported; diff --git a/packages/camera/camera/test/camera_value_test.dart b/packages/camera/camera/test/camera_value_test.dart index 8610962655ac..de7971d963c0 100644 --- a/packages/camera/camera/test/camera_value_test.dart +++ b/packages/camera/camera/test/camera_value_test.dart @@ -24,6 +24,7 @@ void main() { flashMode: FlashMode.auto, exposureMode: ExposureMode.auto, exposurePointSupported: true, + focusMode: FocusMode.auto, deviceOrientation: DeviceOrientation.portraitUp, lockedCaptureOrientation: DeviceOrientation.portraitUp, recordingOrientation: DeviceOrientation.portraitUp, @@ -59,8 +60,9 @@ void main() { expect(cameraValue.isTakingPicture, isFalse); expect(cameraValue.isStreamingImages, isFalse); expect(cameraValue.flashMode, FlashMode.auto); - expect(cameraValue.exposureMode, null); + expect(cameraValue.exposureMode, ExposureMode.auto); expect(cameraValue.exposurePointSupported, false); + expect(cameraValue.focusMode, FocusMode.auto); expect(cameraValue.deviceOrientation, DeviceOrientation.portraitUp); expect(cameraValue.lockedCaptureOrientation, null); expect(cameraValue.recordingOrientation, null); @@ -79,7 +81,8 @@ void main() { expect(cameraValue.isTakingPicture, isFalse); expect(cameraValue.isStreamingImages, isFalse); expect(cameraValue.flashMode, FlashMode.auto); - expect(cameraValue.exposureMode, null); + expect(cameraValue.focusMode, FocusMode.auto); + expect(cameraValue.exposureMode, ExposureMode.auto); expect(cameraValue.exposurePointSupported, false); expect(cameraValue.deviceOrientation, DeviceOrientation.portraitUp); expect(cameraValue.lockedCaptureOrientation, null); From 1d217d7b6aadb2f14ad606ebf708bb051353f75d Mon Sep 17 00:00:00 2001 From: Maurits van Beusekom Date: Thu, 11 Feb 2021 08:51:25 +0100 Subject: [PATCH 09/12] Mark google_maps_flutter as non-NNBD --- script/nnbd_plugins.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/script/nnbd_plugins.sh b/script/nnbd_plugins.sh index 6061bd36752a..b506fc158caa 100644 --- a/script/nnbd_plugins.sh +++ b/script/nnbd_plugins.sh @@ -38,8 +38,9 @@ readonly NNBD_PLUGINS_LIST=( # building the all plugins app. This list should be kept empty. readonly NON_NNBD_PLUGINS_LIST=( - "camera" - "google_maps_flutter" # half migrated + # "android_alarm_manager" + # "camera" + "google_maps_flutter" # "image_picker" # "in_app_purchase" # "quick_actions" From cdb93264a4b6d48aac145262273e220bceb0966c Mon Sep 17 00:00:00 2001 From: Maurits van Beusekom Date: Fri, 12 Feb 2021 11:50:06 +0100 Subject: [PATCH 10/12] Update dependencies --- packages/camera/camera/pubspec.yaml | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/packages/camera/camera/pubspec.yaml b/packages/camera/camera/pubspec.yaml index ab298eb5f9f6..7ed08d892de8 100644 --- a/packages/camera/camera/pubspec.yaml +++ b/packages/camera/camera/pubspec.yaml @@ -5,20 +5,13 @@ description: A Flutter plugin for getting information about and controlling the version: 0.8.0-nullsafety homepage: https://github.com/flutter/plugins/tree/master/packages/camera/camera -# TODO(mvanbeusekom): Contains temporary path reference so should not be publishable. Remove once -# PR 3530 has been merged and published. -publish_to: none - dependencies: flutter: sdk: flutter - # TODO(mvanbeusekom): Temporary reference via path to continue NNDB development. Remove once - # PR 3530 has been merged and published. - camera_platform_interface: - path: ../camera_platform_interface + camera_platform_interface: ^2.0.0-nullsafety - pedantic: ^1.10.0-nullsafety.3 + pedantic: ^1.10.0 quiver: ^3.0.0-nullsafety.3 dev_dependencies: From c5685d6e51fde1a7a014ecd1c6339b7f56b02933 Mon Sep 17 00:00:00 2001 From: Maurits van Beusekom Date: Fri, 12 Feb 2021 16:13:00 +0100 Subject: [PATCH 11/12] Added missing entry to CHANGELOG.md --- packages/camera/camera/CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/camera/camera/CHANGELOG.md b/packages/camera/camera/CHANGELOG.md index e365e76cbafd..aee3774087ba 100644 --- a/packages/camera/camera/CHANGELOG.md +++ b/packages/camera/camera/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.8.0-nullsafety + +* Migrated to null safety. + ## 0.7.0+4 * Fix crash when taking picture with orientation lock From 4c86dc0ba6a3c7eb264e0fee9053bfb987c0e929 Mon Sep 17 00:00:00 2001 From: Maurits van Beusekom Date: Mon, 15 Feb 2021 09:06:39 +0100 Subject: [PATCH 12/12] Rebased on master --- script/nnbd_plugins.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/script/nnbd_plugins.sh b/script/nnbd_plugins.sh index b506fc158caa..9a8f771352ad 100644 --- a/script/nnbd_plugins.sh +++ b/script/nnbd_plugins.sh @@ -8,6 +8,7 @@ readonly NNBD_PLUGINS_LIST=( "android_alarm_manager" "android_intent" "battery" + "camera" "camera_platform_interface" "connectivity" "cross_file" @@ -38,8 +39,7 @@ readonly NNBD_PLUGINS_LIST=( # building the all plugins app. This list should be kept empty. readonly NON_NNBD_PLUGINS_LIST=( - # "android_alarm_manager" - # "camera" + #"camera" "google_maps_flutter" # "image_picker" # "in_app_purchase"