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 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/lib/src/camera_controller.dart b/packages/camera/camera/lib/src/camera_controller.dart index 80e83c867954..bb976d1c85fe 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, - this.exposureMode, - this.focusMode, - this.exposurePointSupported, - this.focusPointSupported, - this.deviceOrientation, + required this.isRecordingVideo, + required this.isTakingPicture, + required this.isStreamingImages, + required bool isRecordingPaused, + required this.flashMode, + required this.exposureMode, + required this.focusMode, + required this.exposurePointSupported, + required this.focusPointSupported, + required this.deviceOrientation, this.lockedCaptureOrientation, this.recordingOrientation, }) : _isRecordingPaused = isRecordingPaused; @@ -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, ); @@ -84,17 +86,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; + /// Is `null` until [isInitialized] is `true`. + 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. /// @@ -120,34 +122,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 +227,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 +284,7 @@ class CameraController extends ValueNotifier { await CameraPlatform.instance.initializeCamera( _cameraId, - imageFormatGroup: imageFormatGroup, + imageFormatGroup: imageFormatGroup ?? ImageFormatGroup.unknown, ); value = value.copyWith( @@ -422,7 +428,7 @@ class CameraController extends ValueNotifier { throw CameraException(e.code, e.message); } - await _imageStreamSubscription.cancel(); + await _imageStreamSubscription?.cancel(); _imageStreamSubscription = null; } @@ -583,12 +589,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 +692,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 +725,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..7ed08d892de8 100644 --- a/packages/camera/camera/pubspec.yaml +++ b/packages/camera/camera/pubspec.yaml @@ -2,25 +2,26 @@ 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 dependencies: flutter: sdk: flutter - camera_platform_interface: ^1.5.0 - pedantic: ^1.8.0 - quiver: ^2.1.5 + + camera_platform_interface: ^2.0.0-nullsafety + + pedantic: ^1.10.0 + 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 +33,5 @@ flutter: pluginClass: CameraPlugin environment: - sdk: ">=2.7.0 <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 d0b09fae1304..b37b7701a14f 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,92 @@ 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]), + returnValue: 1.0, + ); + + @override + Future getMinZoomLevel(int? cameraId) async => super.noSuchMethod( + Invocation.method(#getMinZoomLevel, [cameraId]), + returnValue: 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]), + returnValue: 0.0, + ); + + @override + 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]), + returnValue: 1.0, + ); + + @override + Future setExposureOffset(int? cameraId, double? offset) async => + super.noSuchMethod( + Invocation.method(#setExposureOffset, [cameraId, offset]), + returnValue: 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..de7971d963c0 100644 --- a/packages/camera/camera/test/camera_value_test.dart +++ b/packages/camera/camera/test/camera_value_test.dart @@ -24,9 +24,11 @@ void main() { flashMode: FlashMode.auto, exposureMode: ExposureMode.auto, exposurePointSupported: true, + focusMode: FocusMode.auto, deviceOrientation: DeviceOrientation.portraitUp, lockedCaptureOrientation: DeviceOrientation.portraitUp, recordingOrientation: DeviceOrientation.portraitUp, + focusPointSupported: true, ); expect(cameraValue, isA()); @@ -58,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); @@ -78,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); 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); } diff --git a/script/nnbd_plugins.sh b/script/nnbd_plugins.sh index a2c22c67948a..9a8f771352ad 100644 --- a/script/nnbd_plugins.sh +++ b/script/nnbd_plugins.sh @@ -9,6 +9,7 @@ readonly NNBD_PLUGINS_LIST=( "android_intent" "battery" "camera" + "camera_platform_interface" "connectivity" "cross_file" "device_info" @@ -38,8 +39,8 @@ 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 + #"camera" + "google_maps_flutter" # "image_picker" # "in_app_purchase" # "quick_actions"