From 7c4e187f12ed9b0ce14a55fdaaeb79e65f77f3d3 Mon Sep 17 00:00:00 2001 From: Maurits van Beusekom Date: Tue, 2 Feb 2021 14:56:49 +0100 Subject: [PATCH 01/19] Migrate camera_platform_interface to null safety --- .../camera_platform_interface/CHANGELOG.md | 4 + .../lib/src/events/camera_event.dart | 4 +- .../method_channel/method_channel_camera.dart | 156 ++++++++++++------ .../platform_interface/camera_platform.dart | 22 ++- .../lib/src/types/camera_description.dart | 6 +- .../lib/src/types/camera_exception.dart | 2 +- .../lib/src/types/exposure_mode.dart | 2 - .../lib/src/types/focus_mode.dart | 2 - .../camera_platform_interface/pubspec.yaml | 18 +- .../test/camera_platform_interface_test.dart | 23 ++- .../method_channel_camera_test.dart | 113 ++++++++----- .../test/utils/method_channel_mock.dart | 6 +- 12 files changed, 226 insertions(+), 132 deletions(-) diff --git a/packages/camera/camera_platform_interface/CHANGELOG.md b/packages/camera/camera_platform_interface/CHANGELOG.md index ff739918c53b..47799c68a14c 100644 --- a/packages/camera/camera_platform_interface/CHANGELOG.md +++ b/packages/camera/camera_platform_interface/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.0.0-nullsafety.0 + +- Migrate to null safety. + ## 1.6.0 - Added VideoRecordedEvent to support ending a video recording in the native implementation. diff --git a/packages/camera/camera_platform_interface/lib/src/events/camera_event.dart b/packages/camera/camera_platform_interface/lib/src/events/camera_event.dart index ad9958381143..4fddf6f448a2 100644 --- a/packages/camera/camera_platform_interface/lib/src/events/camera_event.dart +++ b/packages/camera/camera_platform_interface/lib/src/events/camera_event.dart @@ -71,9 +71,9 @@ class CameraInitializedEvent extends CameraEvent { int cameraId, this.previewWidth, this.previewHeight, [ - this.exposureMode, + this.exposureMode = ExposureMode.auto, this.exposurePointSupported = false, - this.focusMode, + this.focusMode = FocusMode.auto, this.focusPointSupported = false, ]) : super(cameraId); diff --git a/packages/camera/camera_platform_interface/lib/src/method_channel/method_channel_camera.dart b/packages/camera/camera_platform_interface/lib/src/method_channel/method_channel_camera.dart index 36a2c92645f2..8006a6c89be2 100644 --- a/packages/camera/camera_platform_interface/lib/src/method_channel/method_channel_camera.dart +++ b/packages/camera/camera_platform_interface/lib/src/method_channel/method_channel_camera.dart @@ -11,6 +11,7 @@ import 'package:camera_platform_interface/src/types/focus_mode.dart'; import 'package:camera_platform_interface/src/types/image_format_group.dart'; import 'package:camera_platform_interface/src/utils/utils.dart'; import 'package:cross_file/cross_file.dart'; +import 'package:flutter/foundation.dart'; import 'package:flutter/services.dart'; import 'package:flutter/widgets.dart'; import 'package:meta/meta.dart'; @@ -58,8 +59,13 @@ class MethodChannelCamera extends CameraPlatform { @override Future> availableCameras() async { try { - final List> cameras = await _channel + final cameras = await _channel .invokeListMethod>('availableCameras'); + + if (cameras == null) { + return []; + } + return cameras.map((Map camera) { return CameraDescription( name: camera['name'], @@ -75,30 +81,30 @@ class MethodChannelCamera extends CameraPlatform { @override Future createCamera( CameraDescription cameraDescription, - ResolutionPreset resolutionPreset, { - bool enableAudio, + ResolutionPreset? resolutionPreset, { + bool enableAudio = true, }) async { try { - final Map reply = - await _channel.invokeMapMethod( - 'create', - { - 'cameraName': cameraDescription.name, - 'resolutionPreset': resolutionPreset != null - ? _serializeResolutionPreset(resolutionPreset) - : null, - 'enableAudio': enableAudio, - }, - ); - return reply['cameraId']; + final reply = await _channel + .invokeMapMethod('create', { + 'cameraName': cameraDescription.name, + 'resolutionPreset': resolutionPreset != null + ? _serializeResolutionPreset(resolutionPreset) + : null, + 'enableAudio': enableAudio, + }); + + return reply!['cameraId']; } on PlatformException catch (e) { throw CameraException(e.code, e.message); } } @override - Future initializeCamera(int cameraId, - {ImageFormatGroup imageFormatGroup}) { + Future initializeCamera( + int cameraId, { + ImageFormatGroup imageFormatGroup = ImageFormatGroup.unknown, + }) { _channels.putIfAbsent(cameraId, () { final channel = MethodChannel('flutter.io/cameraPlugin/camera$cameraId'); channel.setMethodCallHandler( @@ -131,7 +137,7 @@ class MethodChannelCamera extends CameraPlatform { ); if (_channels.containsKey(cameraId)) { - _channels[cameraId].setMethodCallHandler(null); + _channels[cameraId]!.setMethodCallHandler(null); _channels.remove(cameraId); } } @@ -169,7 +175,9 @@ class MethodChannelCamera extends CameraPlatform { @override Future lockCaptureOrientation( - int cameraId, DeviceOrientation orientation) async { + int cameraId, + DeviceOrientation orientation, + ) async { await _channel.invokeMethod( 'lockCaptureOrientation', { @@ -189,10 +197,18 @@ class MethodChannelCamera extends CameraPlatform { @override Future takePicture(int cameraId) async { - String path = await _channel.invokeMethod( + final path = await _channel.invokeMethod( 'takePicture', {'cameraId': cameraId}, ); + + if (path == null) { + throw CameraException( + 'INVALID_PATH', + 'The platform "$defaultTargetPlatform" did not return a path while reporting success. The platform should always return a valid path or report an error.', + ); + } + return XFile(path); } @@ -202,7 +218,7 @@ class MethodChannelCamera extends CameraPlatform { @override Future startVideoRecording(int cameraId, - {Duration maxVideoDuration}) async { + {Duration? maxVideoDuration}) async { await _channel.invokeMethod( 'startVideoRecording', { @@ -214,10 +230,18 @@ class MethodChannelCamera extends CameraPlatform { @override Future stopVideoRecording(int cameraId) async { - String path = await _channel.invokeMethod( + final path = await _channel.invokeMethod( 'stopVideoRecording', {'cameraId': cameraId}, ); + + if (path == null) { + throw CameraException( + 'INVALID_PATH', + 'The platform "$defaultTargetPlatform" did not return a path while reporting success. The platform should always return a valid path or report an error.', + ); + } + return XFile(path); } @@ -255,9 +279,10 @@ class MethodChannelCamera extends CameraPlatform { ); @override - Future setExposurePoint(int cameraId, Point point) { + Future setExposurePoint(int cameraId, Point? point) { assert(point == null || point.x >= 0 && point.x <= 1); assert(point == null || point.y >= 0 && point.y <= 1); + return _channel.invokeMethod( 'setExposurePoint', { @@ -270,35 +295,47 @@ class MethodChannelCamera extends CameraPlatform { } @override - Future getMinExposureOffset(int cameraId) => - _channel.invokeMethod( - 'getMinExposureOffset', - {'cameraId': cameraId}, - ); + Future getMinExposureOffset(int cameraId) async { + final minExposureOffset = await _channel.invokeMethod( + 'getMinExposureOffset', + {'cameraId': cameraId}, + ); + + return minExposureOffset!; + } @override - Future getMaxExposureOffset(int cameraId) => - _channel.invokeMethod( - 'getMaxExposureOffset', - {'cameraId': cameraId}, - ); + Future getMaxExposureOffset(int cameraId) async { + final maxExposureOffset = await _channel.invokeMethod( + 'getMaxExposureOffset', + {'cameraId': cameraId}, + ); + + return maxExposureOffset!; + } @override - Future getExposureOffsetStepSize(int cameraId) => - _channel.invokeMethod( - 'getExposureOffsetStepSize', - {'cameraId': cameraId}, - ); + Future getExposureOffsetStepSize(int cameraId) async { + final stepSize = await _channel.invokeMethod( + 'getExposureOffsetStepSize', + {'cameraId': cameraId}, + ); + + return stepSize!; + } @override - Future setExposureOffset(int cameraId, double offset) => - _channel.invokeMethod( - 'setExposureOffset', - { - 'cameraId': cameraId, - 'offset': offset, - }, - ); + Future setExposureOffset(int cameraId, double offset) async { + final appliedOffset = await _channel.invokeMethod( + 'setExposureOffset', + { + 'cameraId': cameraId, + 'offset': offset, + }, + ); + + return appliedOffset!; + } @override Future setFocusMode(int cameraId, FocusMode mode) => @@ -311,9 +348,10 @@ class MethodChannelCamera extends CameraPlatform { ); @override - Future setFocusPoint(int cameraId, Point point) { + Future setFocusPoint(int cameraId, Point? point) { assert(point == null || point.x >= 0 && point.x <= 1); assert(point == null || point.y >= 0 && point.y <= 1); + return _channel.invokeMethod( 'setFocusPoint', { @@ -326,16 +364,24 @@ class MethodChannelCamera extends CameraPlatform { } @override - Future getMaxZoomLevel(int cameraId) => _channel.invokeMethod( - 'getMaxZoomLevel', - {'cameraId': cameraId}, - ); + Future getMaxZoomLevel(int cameraId) async { + final maxZoomLevel = await _channel.invokeMethod( + 'getMaxZoomLevel', + {'cameraId': cameraId}, + ); + + return maxZoomLevel!; + } @override - Future getMinZoomLevel(int cameraId) => _channel.invokeMethod( - 'getMinZoomLevel', - {'cameraId': cameraId}, - ); + Future getMinZoomLevel(int cameraId) async { + final minZoomLevel = await _channel.invokeMethod( + 'getMinZoomLevel', + {'cameraId': cameraId}, + ); + + return minZoomLevel!; + } @override Future setZoomLevel(int cameraId, double zoom) async { diff --git a/packages/camera/camera_platform_interface/lib/src/platform_interface/camera_platform.dart b/packages/camera/camera_platform_interface/lib/src/platform_interface/camera_platform.dart index e1faecf374cd..916922ff29fa 100644 --- a/packages/camera/camera_platform_interface/lib/src/platform_interface/camera_platform.dart +++ b/packages/camera/camera_platform_interface/lib/src/platform_interface/camera_platform.dart @@ -51,8 +51,8 @@ abstract class CameraPlatform extends PlatformInterface { /// Creates an uninitialized camera instance and returns the cameraId. Future createCamera( CameraDescription cameraDescription, - ResolutionPreset resolutionPreset, { - bool enableAudio, + ResolutionPreset? resolutionPreset, { + bool enableAudio = true, }) { throw UnimplementedError('createCamera() is not implemented.'); } @@ -62,8 +62,10 @@ abstract class CameraPlatform extends PlatformInterface { /// [imageFormatGroup] is used to specify the image formatting used. /// On Android this defaults to ImageFormat.YUV_420_888 and applies only to the imageStream. /// On iOS this defaults to kCVPixelFormatType_32BGRA. - Future initializeCamera(int cameraId, - {ImageFormatGroup imageFormatGroup}) { + Future initializeCamera( + int cameraId, { + ImageFormatGroup imageFormatGroup = ImageFormatGroup.unknown, + }) { throw UnimplementedError('initializeCamera() is not implemented.'); } @@ -130,7 +132,7 @@ abstract class CameraPlatform extends PlatformInterface { /// meaning the recording will continue until manually stopped. /// With [maxVideoDuration] set the video is returned in a [VideoRecordedEvent] /// through the [onVideoRecordedEvent] stream when the set duration is reached. - Future startVideoRecording(int cameraId, {Duration maxVideoDuration}) { + Future startVideoRecording(int cameraId, {Duration? maxVideoDuration}) { throw UnimplementedError('startVideoRecording() is not implemented.'); } @@ -160,7 +162,10 @@ abstract class CameraPlatform extends PlatformInterface { } /// Sets the exposure point for automatically determining the exposure values. - Future setExposurePoint(int cameraId, Point point) { + /// + /// Supplying `null` for the [point] argument will result in resetting to the + /// original exposure point value. + Future setExposurePoint(int cameraId, Point? point) { throw UnimplementedError('setExposurePoint() is not implemented.'); } @@ -202,7 +207,10 @@ abstract class CameraPlatform extends PlatformInterface { } /// Sets the focus point for automatically determining the focus values. - Future setFocusPoint(int cameraId, Point point) { + /// + /// Supplying `null` for the [point] argument will result in resetting to the + /// original focus point value. + Future setFocusPoint(int cameraId, Point? point) { throw UnimplementedError('setFocusPoint() is not implemented.'); } diff --git a/packages/camera/camera_platform_interface/lib/src/types/camera_description.dart b/packages/camera/camera_platform_interface/lib/src/types/camera_description.dart index c19af1f50d1c..9707bd34d0d2 100644 --- a/packages/camera/camera_platform_interface/lib/src/types/camera_description.dart +++ b/packages/camera/camera_platform_interface/lib/src/types/camera_description.dart @@ -17,7 +17,11 @@ enum CameraLensDirection { /// Properties of a camera device. class CameraDescription { /// Creates a new camera description with the given properties. - CameraDescription({this.name, this.lensDirection, this.sensorOrientation}); + CameraDescription({ + required this.name, + required this.lensDirection, + required this.sensorOrientation, + }); /// The name of the camera device. final String name; diff --git a/packages/camera/camera_platform_interface/lib/src/types/camera_exception.dart b/packages/camera/camera_platform_interface/lib/src/types/camera_exception.dart index 3da659f7021d..59f3e4e6647e 100644 --- a/packages/camera/camera_platform_interface/lib/src/types/camera_exception.dart +++ b/packages/camera/camera_platform_interface/lib/src/types/camera_exception.dart @@ -13,7 +13,7 @@ class CameraException implements Exception { String code; /// Textual description of the error. - String description; + String? description; @override String toString() => 'CameraException($code, $description)'; diff --git a/packages/camera/camera_platform_interface/lib/src/types/exposure_mode.dart b/packages/camera/camera_platform_interface/lib/src/types/exposure_mode.dart index 7fbfbaf5f4a9..836f53826479 100644 --- a/packages/camera/camera_platform_interface/lib/src/types/exposure_mode.dart +++ b/packages/camera/camera_platform_interface/lib/src/types/exposure_mode.dart @@ -13,7 +13,6 @@ enum ExposureMode { /// Returns the exposure mode as a String. String serializeExposureMode(ExposureMode exposureMode) { - if (exposureMode == null) return null; switch (exposureMode) { case ExposureMode.locked: return 'locked'; @@ -26,7 +25,6 @@ String serializeExposureMode(ExposureMode exposureMode) { /// Returns the exposure mode for a given String. ExposureMode deserializeExposureMode(String str) { - if (str == null) return null; switch (str) { case "locked": return ExposureMode.locked; diff --git a/packages/camera/camera_platform_interface/lib/src/types/focus_mode.dart b/packages/camera/camera_platform_interface/lib/src/types/focus_mode.dart index ad5e9a2d46f1..8da2a90fa858 100644 --- a/packages/camera/camera_platform_interface/lib/src/types/focus_mode.dart +++ b/packages/camera/camera_platform_interface/lib/src/types/focus_mode.dart @@ -13,7 +13,6 @@ enum FocusMode { /// Returns the focus mode as a String. String serializeFocusMode(FocusMode focusMode) { - if (focusMode == null) return null; switch (focusMode) { case FocusMode.locked: return 'locked'; @@ -26,7 +25,6 @@ String serializeFocusMode(FocusMode focusMode) { /// Returns the focus mode for a given String. FocusMode deserializeFocusMode(String str) { - if (str == null) return null; switch (str) { case "locked": return FocusMode.locked; diff --git a/packages/camera/camera_platform_interface/pubspec.yaml b/packages/camera/camera_platform_interface/pubspec.yaml index c7ec7209c838..a92aeae45336 100644 --- a/packages/camera/camera_platform_interface/pubspec.yaml +++ b/packages/camera/camera_platform_interface/pubspec.yaml @@ -3,23 +3,23 @@ description: A common platform interface for the camera plugin. homepage: https://github.com/flutter/plugins/tree/master/packages/camera/camera_platform_interface # NOTE: We strongly prefer non-breaking changes, even at the expense of a # less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes -version: 1.6.0 +version: 2.0.0-nullsafety.0 dependencies: flutter: sdk: flutter - meta: ^1.0.5 - plugin_platform_interface: ^1.0.1 - cross_file: ^0.1.0 - stream_transform: ^1.2.0 + meta: ^1.3.0-nullsafety.6 + plugin_platform_interface: ^1.1.0-nullsafety.2 + cross_file: ^0.3.0-nullsafety + stream_transform: ^2.0.0-nullsafety.0 dev_dependencies: flutter_test: sdk: flutter - async: ^2.4.2 - mockito: ^4.1.1 - pedantic: ^1.8.0 + async: ^2.5.0-nullsafety.3 + mockito: ^5.0.0-nullsafety.5 + pedantic: ^1.10.0-nullsafety.3 environment: - sdk: ">=2.7.0 <3.0.0" + sdk: '>=2.12.0-133.7.beta <3.0.0' flutter: ">=1.22.0" diff --git a/packages/camera/camera_platform_interface/test/camera_platform_interface_test.dart b/packages/camera/camera_platform_interface/test/camera_platform_interface_test.dart index 8baf5da34159..a96df845844a 100644 --- a/packages/camera/camera_platform_interface/test/camera_platform_interface_test.dart +++ b/packages/camera/camera_platform_interface/test/camera_platform_interface_test.dart @@ -4,6 +4,7 @@ import 'package:camera_platform_interface/camera_platform_interface.dart'; import 'package:camera_platform_interface/src/method_channel/method_channel_camera.dart'; +import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:mockito/mockito.dart'; import 'package:plugin_platform_interface/plugin_platform_interface.dart'; @@ -117,7 +118,8 @@ void main() { // Act & Assert expect( - () => cameraPlatform.lockCaptureOrientation(1, null), + () => cameraPlatform.lockCaptureOrientation( + 1, DeviceOrientation.portraitUp), throwsUnimplementedError, ); }); @@ -155,7 +157,14 @@ void main() { // Act & Assert expect( - () => cameraPlatform.createCamera(null, null), + () => cameraPlatform.createCamera( + CameraDescription( + name: 'back', + lensDirection: CameraLensDirection.back, + sensorOrientation: 0, + ), + ResolutionPreset.high, + ), throwsUnimplementedError, ); }); @@ -168,7 +177,7 @@ void main() { // Act & Assert expect( - () => cameraPlatform.initializeCamera(null), + () => cameraPlatform.initializeCamera(1), throwsUnimplementedError, ); }); @@ -220,7 +229,7 @@ void main() { // Act & Assert expect( - () => cameraPlatform.setFlashMode(1, null), + () => cameraPlatform.setFlashMode(1, FlashMode.auto), throwsUnimplementedError, ); }); @@ -233,7 +242,7 @@ void main() { // Act & Assert expect( - () => cameraPlatform.setExposureMode(1, null), + () => cameraPlatform.setExposureMode(1, ExposureMode.auto), throwsUnimplementedError, ); }); @@ -298,7 +307,7 @@ void main() { // Act & Assert expect( - () => cameraPlatform.setExposureOffset(1, null), + () => cameraPlatform.setExposureOffset(1, 2.0), throwsUnimplementedError, ); }); @@ -311,7 +320,7 @@ void main() { // Act & Assert expect( - () => cameraPlatform.setFocusMode(1, null), + () => cameraPlatform.setFocusMode(1, FocusMode.auto), throwsUnimplementedError, ); }); 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 7e9146344206..f511cef28099 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 @@ -37,7 +37,10 @@ void main() { // Act final cameraId = await camera.createCamera( - CameraDescription(name: 'Test'), + CameraDescription( + name: 'Test', + lensDirection: CameraLensDirection.back, + sensorOrientation: 0), ResolutionPreset.high, ); @@ -48,7 +51,7 @@ void main() { arguments: { 'cameraName': 'Test', 'resolutionPreset': 'high', - 'enableAudio': null + 'enableAudio': true }, ), ]); @@ -70,7 +73,11 @@ void main() { // Act expect( () => camera.createCamera( - CameraDescription(name: 'Test'), + CameraDescription( + name: 'Test', + lensDirection: CameraLensDirection.back, + sensorOrientation: 0, + ), ResolutionPreset.high, ), throwsA( @@ -97,7 +104,11 @@ void main() { // Act expect( () => camera.createCamera( - CameraDescription(name: 'Test'), + CameraDescription( + name: 'Test', + lensDirection: CameraLensDirection.back, + sensorOrientation: 0, + ), ResolutionPreset.high, ), throwsA( @@ -122,7 +133,11 @@ void main() { }); final camera = MethodChannelCamera(); final cameraId = await camera.createCamera( - CameraDescription(name: 'Test'), + CameraDescription( + name: 'Test', + lensDirection: CameraLensDirection.back, + sensorOrientation: 0, + ), ResolutionPreset.high, ); @@ -165,7 +180,11 @@ void main() { final camera = MethodChannelCamera(); final cameraId = await camera.createCamera( - CameraDescription(name: 'Test'), + CameraDescription( + name: 'Test', + lensDirection: CameraLensDirection.back, + sensorOrientation: 0, + ), ResolutionPreset.high, ); Future initializeFuture = camera.initializeCamera(cameraId); @@ -197,8 +216,8 @@ void main() { }); group('Event Tests', () { - MethodChannelCamera camera; - int cameraId; + late MethodChannelCamera camera; + late int cameraId; setUp(() async { MethodChannelMock( channelName: 'plugins.flutter.io/camera', @@ -209,7 +228,11 @@ void main() { ); camera = MethodChannelCamera(); cameraId = await camera.createCamera( - CameraDescription(name: 'Test'), + CameraDescription( + name: 'Test', + lensDirection: CameraLensDirection.back, + sensorOrientation: 0, + ), ResolutionPreset.high, ); Future initializeFuture = camera.initializeCamera(cameraId); @@ -352,8 +375,8 @@ void main() { }); group('Function Tests', () { - MethodChannelCamera camera; - int cameraId; + late MethodChannelCamera camera; + int? cameraId; setUp(() async { MethodChannelMock( channelName: 'plugins.flutter.io/camera', @@ -364,13 +387,17 @@ void main() { ); camera = MethodChannelCamera(); cameraId = await camera.createCamera( - CameraDescription(name: 'Test'), + CameraDescription( + name: 'Test', + lensDirection: CameraLensDirection.back, + sensorOrientation: 0, + ), ResolutionPreset.high, ); - Future initializeFuture = camera.initializeCamera(cameraId); + Future initializeFuture = camera.initializeCamera(cameraId!); camera.cameraEventStreamController.add( CameraInitializedEvent( - cameraId, + cameraId!, 1920, 1080, ExposureMode.auto, @@ -443,7 +470,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, [ @@ -478,7 +505,7 @@ void main() { ); // Act - await camera.startVideoRecording(cameraId); + await camera.startVideoRecording(cameraId!); // Assert expect(channel.log, [ @@ -499,7 +526,7 @@ void main() { // Act await camera.startVideoRecording( - cameraId, + cameraId!, maxVideoDuration: Duration(seconds: 10), ); @@ -518,7 +545,7 @@ void main() { ); // Act - XFile file = await camera.stopVideoRecording(cameraId); + XFile file = await camera.stopVideoRecording(cameraId!); // Assert expect(channel.log, [ @@ -537,7 +564,7 @@ void main() { ); // Act - await camera.pauseVideoRecording(cameraId); + await camera.pauseVideoRecording(cameraId!); // Assert expect(channel.log, [ @@ -555,7 +582,7 @@ void main() { ); // Act - await camera.resumeVideoRecording(cameraId); + await camera.resumeVideoRecording(cameraId!); // Assert expect(channel.log, [ @@ -573,10 +600,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, [ @@ -599,8 +626,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, [ @@ -619,8 +646,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, [ @@ -647,7 +674,7 @@ void main() { ); // Act - final minExposureOffset = await camera.getMinExposureOffset(cameraId); + final minExposureOffset = await camera.getMinExposureOffset(cameraId!); // Assert expect(minExposureOffset, 2.0); @@ -666,7 +693,7 @@ void main() { ); // Act - final maxExposureOffset = await camera.getMaxExposureOffset(cameraId); + final maxExposureOffset = await camera.getMaxExposureOffset(cameraId!); // Assert expect(maxExposureOffset, 2.0); @@ -685,7 +712,7 @@ void main() { ); // Act - final stepSize = await camera.getExposureOffsetStepSize(cameraId); + final stepSize = await camera.getExposureOffsetStepSize(cameraId!); // Assert expect(stepSize, 0.25); @@ -704,7 +731,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); @@ -724,8 +751,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, [ @@ -744,8 +771,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, [ @@ -766,7 +793,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); @@ -791,7 +818,7 @@ void main() { ); // Act - final maxZoomLevel = await camera.getMaxZoomLevel(cameraId); + final maxZoomLevel = await camera.getMaxZoomLevel(cameraId!); // Assert expect(maxZoomLevel, 10.0); @@ -810,7 +837,7 @@ void main() { ); // Act - final maxZoomLevel = await camera.getMinZoomLevel(cameraId); + final maxZoomLevel = await camera.getMinZoomLevel(cameraId!); // Assert expect(maxZoomLevel, 1.0); @@ -829,7 +856,7 @@ void main() { ); // Act - await camera.setZoomLevel(cameraId, 2.0); + await camera.setZoomLevel(cameraId!, 2.0); // Assert expect(channel.log, [ @@ -854,7 +881,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', @@ -870,7 +897,7 @@ void main() { // Act await camera.lockCaptureOrientation( - cameraId, DeviceOrientation.portraitUp); + cameraId!, DeviceOrientation.portraitUp); // Assert expect(channel.log, [ @@ -887,7 +914,7 @@ void main() { ); // Act - await camera.unlockCaptureOrientation(cameraId); + await camera.unlockCaptureOrientation(cameraId!); // Assert expect(channel.log, [ diff --git a/packages/camera/camera_platform_interface/test/utils/method_channel_mock.dart b/packages/camera/camera_platform_interface/test/utils/method_channel_mock.dart index cdf393f82b5f..fdbd9a18f29c 100644 --- a/packages/camera/camera_platform_interface/test/utils/method_channel_mock.dart +++ b/packages/camera/camera_platform_interface/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 bf94a5d814460659e443acb2d5208c0fe00607e4 Mon Sep 17 00:00:00 2001 From: Maurits van Beusekom Date: Tue, 2 Feb 2021 15:37:26 +0100 Subject: [PATCH 02/19] Added camera to the NNBD plugin list --- script/build_all_plugins_app.sh | 1 + script/nnbd_plugins.sh | 1 + 2 files changed, 2 insertions(+) diff --git a/script/build_all_plugins_app.sh b/script/build_all_plugins_app.sh index 7807e6a98bce..d3aa18a29894 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" "connectivity_macos" "connectivity_platform_interface" "connectivity_web" diff --git a/script/nnbd_plugins.sh b/script/nnbd_plugins.sh index 1e57db96a648..81ec693af41e 100644 --- a/script/nnbd_plugins.sh +++ b/script/nnbd_plugins.sh @@ -7,6 +7,7 @@ readonly NNBD_PLUGINS_LIST=( "android_intent" "battery" + "camera" "connectivity" "cross_file" "device_info" From c56c8c2cf298761317d6158bf38af6fc0e0f9843 Mon Sep 17 00:00:00 2001 From: Maurits van Beusekom Date: Wed, 3 Feb 2021 08:42:51 +0100 Subject: [PATCH 03/19] Correct version number --- packages/camera/camera_platform_interface/CHANGELOG.md | 2 +- packages/camera/camera_platform_interface/pubspec.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/camera/camera_platform_interface/CHANGELOG.md b/packages/camera/camera_platform_interface/CHANGELOG.md index 47799c68a14c..ab3d559bf2fb 100644 --- a/packages/camera/camera_platform_interface/CHANGELOG.md +++ b/packages/camera/camera_platform_interface/CHANGELOG.md @@ -1,4 +1,4 @@ -## 2.0.0-nullsafety.0 +## 2.0.0-nullsafety - Migrate to null safety. diff --git a/packages/camera/camera_platform_interface/pubspec.yaml b/packages/camera/camera_platform_interface/pubspec.yaml index a92aeae45336..0bc9c86a509d 100644 --- a/packages/camera/camera_platform_interface/pubspec.yaml +++ b/packages/camera/camera_platform_interface/pubspec.yaml @@ -3,7 +3,7 @@ description: A common platform interface for the camera plugin. homepage: https://github.com/flutter/plugins/tree/master/packages/camera/camera_platform_interface # NOTE: We strongly prefer non-breaking changes, even at the expense of a # less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes -version: 2.0.0-nullsafety.0 +version: 2.0.0-nullsafety dependencies: flutter: From 4fbbfd054730b584ab1514452dc769561877a70b Mon Sep 17 00:00:00 2001 From: Maurits van Beusekom Date: Wed, 3 Feb 2021 08:45:43 +0100 Subject: [PATCH 04/19] Convert optional parameters to required for CameraInitializationEvent --- .../lib/src/events/camera_event.dart | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/camera/camera_platform_interface/lib/src/events/camera_event.dart b/packages/camera/camera_platform_interface/lib/src/events/camera_event.dart index 4fddf6f448a2..a83c183ad7a0 100644 --- a/packages/camera/camera_platform_interface/lib/src/events/camera_event.dart +++ b/packages/camera/camera_platform_interface/lib/src/events/camera_event.dart @@ -70,12 +70,12 @@ class CameraInitializedEvent extends CameraEvent { CameraInitializedEvent( int cameraId, this.previewWidth, - this.previewHeight, [ - this.exposureMode = ExposureMode.auto, - this.exposurePointSupported = false, - this.focusMode = FocusMode.auto, - this.focusPointSupported = false, - ]) : super(cameraId); + this.previewHeight, + this.exposureMode, + this.exposurePointSupported, + this.focusMode, + this.focusPointSupported, + ) : super(cameraId); /// Converts the supplied [Map] to an instance of the [CameraInitializedEvent] /// class. From d3e86f1bb2a09f8694e44f220e3be6bdf0ebdcb3 Mon Sep 17 00:00:00 2001 From: Maurits van Beusekom Date: Wed, 3 Feb 2021 08:51:50 +0100 Subject: [PATCH 05/19] Convert CameraId in test to non-nullable --- .../method_channel_camera_test.dart | 65 ++++++++++--------- 1 file changed, 33 insertions(+), 32 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 f511cef28099..7633de8626a6 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 @@ -376,7 +376,8 @@ void main() { group('Function Tests', () { late MethodChannelCamera camera; - int? cameraId; + late int cameraId; + setUp(() async { MethodChannelMock( channelName: 'plugins.flutter.io/camera', @@ -394,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, @@ -470,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, [ @@ -505,7 +506,7 @@ void main() { ); // Act - await camera.startVideoRecording(cameraId!); + await camera.startVideoRecording(cameraId); // Assert expect(channel.log, [ @@ -526,7 +527,7 @@ void main() { // Act await camera.startVideoRecording( - cameraId!, + cameraId, maxVideoDuration: Duration(seconds: 10), ); @@ -545,7 +546,7 @@ void main() { ); // Act - XFile file = await camera.stopVideoRecording(cameraId!); + XFile file = await camera.stopVideoRecording(cameraId); // Assert expect(channel.log, [ @@ -564,7 +565,7 @@ void main() { ); // Act - await camera.pauseVideoRecording(cameraId!); + await camera.pauseVideoRecording(cameraId); // Assert expect(channel.log, [ @@ -582,7 +583,7 @@ void main() { ); // Act - await camera.resumeVideoRecording(cameraId!); + await camera.resumeVideoRecording(cameraId); // Assert expect(channel.log, [ @@ -600,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, [ @@ -626,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, [ @@ -646,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, [ @@ -674,7 +675,7 @@ void main() { ); // Act - final minExposureOffset = await camera.getMinExposureOffset(cameraId!); + final minExposureOffset = await camera.getMinExposureOffset(cameraId); // Assert expect(minExposureOffset, 2.0); @@ -693,7 +694,7 @@ void main() { ); // Act - final maxExposureOffset = await camera.getMaxExposureOffset(cameraId!); + final maxExposureOffset = await camera.getMaxExposureOffset(cameraId); // Assert expect(maxExposureOffset, 2.0); @@ -712,7 +713,7 @@ void main() { ); // Act - final stepSize = await camera.getExposureOffsetStepSize(cameraId!); + final stepSize = await camera.getExposureOffsetStepSize(cameraId); // Assert expect(stepSize, 0.25); @@ -731,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); @@ -751,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, [ @@ -771,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, [ @@ -793,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); @@ -818,7 +819,7 @@ void main() { ); // Act - final maxZoomLevel = await camera.getMaxZoomLevel(cameraId!); + final maxZoomLevel = await camera.getMaxZoomLevel(cameraId); // Assert expect(maxZoomLevel, 10.0); @@ -837,7 +838,7 @@ void main() { ); // Act - final maxZoomLevel = await camera.getMinZoomLevel(cameraId!); + final maxZoomLevel = await camera.getMinZoomLevel(cameraId); // Assert expect(maxZoomLevel, 1.0); @@ -856,7 +857,7 @@ void main() { ); // Act - await camera.setZoomLevel(cameraId!, 2.0); + await camera.setZoomLevel(cameraId, 2.0); // Assert expect(channel.log, [ @@ -881,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', @@ -897,7 +898,7 @@ void main() { // Act await camera.lockCaptureOrientation( - cameraId!, DeviceOrientation.portraitUp); + cameraId, DeviceOrientation.portraitUp); // Assert expect(channel.log, [ @@ -914,7 +915,7 @@ void main() { ); // Act - await camera.unlockCaptureOrientation(cameraId!); + await camera.unlockCaptureOrientation(cameraId); // Assert expect(channel.log, [ From 025bc8dcc56ea323f97e6516ba341d4b49aab47e Mon Sep 17 00:00:00 2001 From: Maurits van Beusekom Date: Thu, 4 Feb 2021 20:20:21 +0100 Subject: [PATCH 06/19] Test for null instead of enforcing non-null --- .../lib/src/method_channel/method_channel_camera.dart | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/camera/camera_platform_interface/lib/src/method_channel/method_channel_camera.dart b/packages/camera/camera_platform_interface/lib/src/method_channel/method_channel_camera.dart index 8006a6c89be2..3537a5ca40a9 100644 --- a/packages/camera/camera_platform_interface/lib/src/method_channel/method_channel_camera.dart +++ b/packages/camera/camera_platform_interface/lib/src/method_channel/method_channel_camera.dart @@ -131,15 +131,16 @@ class MethodChannelCamera extends CameraPlatform { @override Future dispose(int cameraId) async { + if (_channels.containsKey(cameraId)) { + final cameraChannel = _channels[cameraId]; + cameraChannel?.setMethodCallHandler(null); + _channels.remove(cameraId); + } + await _channel.invokeMethod( 'dispose', {'cameraId': cameraId}, ); - - if (_channels.containsKey(cameraId)) { - _channels[cameraId]!.setMethodCallHandler(null); - _channels.remove(cameraId); - } } @override From 7f3db23f13f1e39aba8610e9ae3d32e84f0391ed Mon Sep 17 00:00:00 2001 From: Maurits van Beusekom Date: Fri, 5 Feb 2021 18:22:26 +0100 Subject: [PATCH 07/19] Attempt to fix dependency problem building all plugins --- script/nnbd_plugins.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script/nnbd_plugins.sh b/script/nnbd_plugins.sh index 81ec693af41e..68eb589c0422 100644 --- a/script/nnbd_plugins.sh +++ b/script/nnbd_plugins.sh @@ -7,7 +7,7 @@ readonly NNBD_PLUGINS_LIST=( "android_intent" "battery" - "camera" + "camera_platform_interface" "connectivity" "cross_file" "device_info" From a8d251f16e5599734e7d95d5d0d871402812b42f Mon Sep 17 00:00:00 2001 From: Maurits van Beusekom Date: Fri, 5 Feb 2021 21:38:50 +0100 Subject: [PATCH 08/19] Mark google_maps_flutter as NNBD --- script/nnbd_plugins.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script/nnbd_plugins.sh b/script/nnbd_plugins.sh index 68eb589c0422..3742a18768e3 100644 --- a/script/nnbd_plugins.sh +++ b/script/nnbd_plugins.sh @@ -34,7 +34,7 @@ readonly NNBD_PLUGINS_LIST=( readonly NON_NNBD_PLUGINS_LIST=( # "android_alarm_manager" "camera" - # "google_maps_flutter" + "google_maps_flutter" # "image_picker" # "in_app_purchase" # "quick_actions" From cb539d59fabbe862a116a5f1dbbf3810dc99a02d Mon Sep 17 00:00:00 2001 From: Maurits van Beusekom Date: Sat, 6 Feb 2021 09:17:35 +0100 Subject: [PATCH 09/19] Depend on correct Dart SDK version --- packages/camera/camera_platform_interface/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/camera/camera_platform_interface/pubspec.yaml b/packages/camera/camera_platform_interface/pubspec.yaml index 0bc9c86a509d..a063765af63b 100644 --- a/packages/camera/camera_platform_interface/pubspec.yaml +++ b/packages/camera/camera_platform_interface/pubspec.yaml @@ -21,5 +21,5 @@ dev_dependencies: pedantic: ^1.10.0-nullsafety.3 environment: - sdk: '>=2.12.0-133.7.beta <3.0.0' + sdk: '>=2.12.0-0 <3.0.0' flutter: ">=1.22.0" From d9d32713313109b4f0691113a3a468d3ee51d842 Mon Sep 17 00:00:00 2001 From: Maurits van Beusekom Date: Sat, 6 Feb 2021 09:24:41 +0100 Subject: [PATCH 10/19] Attempt to fix dependency problem building all plugins --- script/build_all_plugins_app.sh | 5 +++++ script/nnbd_plugins.sh | 3 +-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/script/build_all_plugins_app.sh b/script/build_all_plugins_app.sh index d3aa18a29894..7fa264960462 100755 --- a/script/build_all_plugins_app.sh +++ b/script/build_all_plugins_app.sh @@ -19,7 +19,12 @@ source "$SCRIPT_DIR/nnbd_plugins.sh" check_changed_packages > /dev/null readonly EXCLUDED_PLUGINS_LIST=( +<<<<<<< HEAD "camera_platform_interface" +||||||| constructed merge base +======= + "camera_platform_interface", +>>>>>>> Attempt to fix dependency problem building all plugins "connectivity_macos" "connectivity_platform_interface" "connectivity_web" diff --git a/script/nnbd_plugins.sh b/script/nnbd_plugins.sh index 3742a18768e3..1e57db96a648 100644 --- a/script/nnbd_plugins.sh +++ b/script/nnbd_plugins.sh @@ -7,7 +7,6 @@ readonly NNBD_PLUGINS_LIST=( "android_intent" "battery" - "camera_platform_interface" "connectivity" "cross_file" "device_info" @@ -34,7 +33,7 @@ readonly NNBD_PLUGINS_LIST=( readonly NON_NNBD_PLUGINS_LIST=( # "android_alarm_manager" "camera" - "google_maps_flutter" + # "google_maps_flutter" # "image_picker" # "in_app_purchase" # "quick_actions" From e6e29b5775924e6c2243aaede9649660f84d4754 Mon Sep 17 00:00:00 2001 From: Maurits van Beusekom Date: Sat, 6 Feb 2021 09:35:10 +0100 Subject: [PATCH 11/19] Attempt to fix dependency problem building all plugins --- script/build_all_plugins_app.sh | 5 ----- 1 file changed, 5 deletions(-) diff --git a/script/build_all_plugins_app.sh b/script/build_all_plugins_app.sh index 7fa264960462..d3aa18a29894 100755 --- a/script/build_all_plugins_app.sh +++ b/script/build_all_plugins_app.sh @@ -19,12 +19,7 @@ source "$SCRIPT_DIR/nnbd_plugins.sh" check_changed_packages > /dev/null readonly EXCLUDED_PLUGINS_LIST=( -<<<<<<< HEAD "camera_platform_interface" -||||||| constructed merge base -======= - "camera_platform_interface", ->>>>>>> Attempt to fix dependency problem building all plugins "connectivity_macos" "connectivity_platform_interface" "connectivity_web" From 5e1f2715150d6e00a5008554925eb7c0225bf5c2 Mon Sep 17 00:00:00 2001 From: Maurits van Beusekom Date: Sat, 6 Feb 2021 09:56:17 +0100 Subject: [PATCH 12/19] Attempt to fix dependency problem building all plugins --- .../camera_platform_interface/lib/src/events/camera_event.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/camera/camera_platform_interface/lib/src/events/camera_event.dart b/packages/camera/camera_platform_interface/lib/src/events/camera_event.dart index a83c183ad7a0..20aa41c5ce40 100644 --- a/packages/camera/camera_platform_interface/lib/src/events/camera_event.dart +++ b/packages/camera/camera_platform_interface/lib/src/events/camera_event.dart @@ -242,7 +242,7 @@ class VideoRecordedEvent extends CameraEvent { final XFile file; /// Maximum duration of the recorded video. - final Duration maxVideoDuration; + final Duration? maxVideoDuration; /// Build a VideoRecordedEvent triggered from the camera with the `cameraId`. /// From b4157dd07cbb85b58d7ea53e8c83cfafcb904a30 Mon Sep 17 00:00:00 2001 From: Maurits van Beusekom Date: Sat, 6 Feb 2021 11:18:42 +0100 Subject: [PATCH 13/19] Attempt to fix dependency problem building all plugins --- script/build_all_plugins_app.sh | 1 - script/nnbd_plugins.sh | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/script/build_all_plugins_app.sh b/script/build_all_plugins_app.sh index d3aa18a29894..7807e6a98bce 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" "connectivity_macos" "connectivity_platform_interface" "connectivity_web" diff --git a/script/nnbd_plugins.sh b/script/nnbd_plugins.sh index 1e57db96a648..68eb589c0422 100644 --- a/script/nnbd_plugins.sh +++ b/script/nnbd_plugins.sh @@ -7,6 +7,7 @@ readonly NNBD_PLUGINS_LIST=( "android_intent" "battery" + "camera_platform_interface" "connectivity" "cross_file" "device_info" From 119c9cb45f0c32ff293c6417c5467a378faff6a8 Mon Sep 17 00:00:00 2001 From: Maurits van Beusekom Date: Mon, 8 Feb 2021 17:32:26 +0100 Subject: [PATCH 14/19] Add camera_platform_interface to exclude list --- 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 7807e6a98bce..d3aa18a29894 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" "connectivity_macos" "connectivity_platform_interface" "connectivity_web" From 051b6a04cb0c4e699dd145d567d719993649730f Mon Sep 17 00:00:00 2001 From: Maurits van Beusekom Date: Mon, 8 Feb 2021 20:09:43 +0100 Subject: [PATCH 15/19] Exclude camera from nnbd and non-nnbd --- 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 d3aa18a29894..7807e6a98bce 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" "connectivity_macos" "connectivity_platform_interface" "connectivity_web" diff --git a/script/nnbd_plugins.sh b/script/nnbd_plugins.sh index 68eb589c0422..81ec693af41e 100644 --- a/script/nnbd_plugins.sh +++ b/script/nnbd_plugins.sh @@ -7,7 +7,7 @@ readonly NNBD_PLUGINS_LIST=( "android_intent" "battery" - "camera_platform_interface" + "camera" "connectivity" "cross_file" "device_info" From 17b872ccb0727186715106c3d98c2309c4deef10 Mon Sep 17 00:00:00 2001 From: Maurits van Beusekom Date: Tue, 9 Feb 2021 10:16:13 +0100 Subject: [PATCH 16/19] Remove mockito dependency --- .../camera/camera_platform_interface/pubspec.yaml | 1 - .../test/camera_platform_interface_test.dart | 13 ------------- 2 files changed, 14 deletions(-) diff --git a/packages/camera/camera_platform_interface/pubspec.yaml b/packages/camera/camera_platform_interface/pubspec.yaml index a063765af63b..5817ce5c3fb0 100644 --- a/packages/camera/camera_platform_interface/pubspec.yaml +++ b/packages/camera/camera_platform_interface/pubspec.yaml @@ -17,7 +17,6 @@ dev_dependencies: flutter_test: sdk: flutter async: ^2.5.0-nullsafety.3 - mockito: ^5.0.0-nullsafety.5 pedantic: ^1.10.0-nullsafety.3 environment: diff --git a/packages/camera/camera_platform_interface/test/camera_platform_interface_test.dart b/packages/camera/camera_platform_interface/test/camera_platform_interface_test.dart index a96df845844a..49de9375fdfb 100644 --- a/packages/camera/camera_platform_interface/test/camera_platform_interface_test.dart +++ b/packages/camera/camera_platform_interface/test/camera_platform_interface_test.dart @@ -6,7 +6,6 @@ import 'package:camera_platform_interface/camera_platform_interface.dart'; import 'package:camera_platform_interface/src/method_channel/method_channel_camera.dart'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'package:mockito/mockito.dart'; import 'package:plugin_platform_interface/plugin_platform_interface.dart'; void main() { @@ -27,11 +26,6 @@ void main() { CameraPlatform.instance = ExtendsCameraPlatform(); }); - test('Can be mocked with `implements`', () { - final mock = MockCameraPlatform(); - CameraPlatform.instance = mock; - }); - test( 'Default implementation of availableCameras() should throw unimplemented error', () { @@ -423,11 +417,4 @@ class ImplementsCameraPlatform implements CameraPlatform { dynamic noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); } -class MockCameraPlatform extends Mock - with - // ignore: prefer_mixin - MockPlatformInterfaceMixin - implements - CameraPlatform {} - class ExtendsCameraPlatform extends CameraPlatform {} From ffeb696d79a9c538b2e6ff8dfcbaff52b54832b2 Mon Sep 17 00:00:00 2001 From: Maurits van Beusekom Date: Tue, 9 Feb 2021 11:54:19 +0100 Subject: [PATCH 17/19] Make sure enableAudio is default false --- .../lib/src/method_channel/method_channel_camera.dart | 2 +- .../lib/src/platform_interface/camera_platform.dart | 2 +- .../test/method_channel/method_channel_camera_test.dart | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/camera/camera_platform_interface/lib/src/method_channel/method_channel_camera.dart b/packages/camera/camera_platform_interface/lib/src/method_channel/method_channel_camera.dart index 3537a5ca40a9..340c2d75614f 100644 --- a/packages/camera/camera_platform_interface/lib/src/method_channel/method_channel_camera.dart +++ b/packages/camera/camera_platform_interface/lib/src/method_channel/method_channel_camera.dart @@ -82,7 +82,7 @@ class MethodChannelCamera extends CameraPlatform { Future createCamera( CameraDescription cameraDescription, ResolutionPreset? resolutionPreset, { - bool enableAudio = true, + bool enableAudio = false, }) async { try { final reply = await _channel diff --git a/packages/camera/camera_platform_interface/lib/src/platform_interface/camera_platform.dart b/packages/camera/camera_platform_interface/lib/src/platform_interface/camera_platform.dart index 916922ff29fa..fd7da7ffa0f8 100644 --- a/packages/camera/camera_platform_interface/lib/src/platform_interface/camera_platform.dart +++ b/packages/camera/camera_platform_interface/lib/src/platform_interface/camera_platform.dart @@ -52,7 +52,7 @@ abstract class CameraPlatform extends PlatformInterface { Future createCamera( CameraDescription cameraDescription, ResolutionPreset? resolutionPreset, { - bool enableAudio = true, + bool enableAudio = false, }) { throw UnimplementedError('createCamera() is not implemented.'); } 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 7633de8626a6..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 @@ -51,7 +51,7 @@ void main() { arguments: { 'cameraName': 'Test', 'resolutionPreset': 'high', - 'enableAudio': true + 'enableAudio': false }, ), ]); From 31bdc4e931486a777af898727e00662bfa2fafe7 Mon Sep 17 00:00:00 2001 From: Maurits van Beusekom Date: Tue, 9 Feb 2021 11:58:28 +0100 Subject: [PATCH 18/19] Include left-hand type definition --- .../lib/src/method_channel/method_channel_camera.dart | 2 +- .../lib/src/platform_interface/camera_platform.dart | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/camera/camera_platform_interface/lib/src/method_channel/method_channel_camera.dart b/packages/camera/camera_platform_interface/lib/src/method_channel/method_channel_camera.dart index 340c2d75614f..9f7f723bcd79 100644 --- a/packages/camera/camera_platform_interface/lib/src/method_channel/method_channel_camera.dart +++ b/packages/camera/camera_platform_interface/lib/src/method_channel/method_channel_camera.dart @@ -59,7 +59,7 @@ class MethodChannelCamera extends CameraPlatform { @override Future> availableCameras() async { try { - final cameras = await _channel + final List>? cameras = await _channel .invokeListMethod>('availableCameras'); if (cameras == null) { diff --git a/packages/camera/camera_platform_interface/lib/src/platform_interface/camera_platform.dart b/packages/camera/camera_platform_interface/lib/src/platform_interface/camera_platform.dart index fd7da7ffa0f8..39a17e43dc0f 100644 --- a/packages/camera/camera_platform_interface/lib/src/platform_interface/camera_platform.dart +++ b/packages/camera/camera_platform_interface/lib/src/platform_interface/camera_platform.dart @@ -44,6 +44,8 @@ abstract class CameraPlatform extends PlatformInterface { } /// Completes with a list of available cameras. + /// + /// This method returns an empty list when no cameras are available. Future> availableCameras() { throw UnimplementedError('availableCameras() is not implemented.'); } From ff6eaa0b08de1df916268b4b32ea9f980e371ec8 Mon Sep 17 00:00:00 2001 From: Maurits van Beusekom Date: Tue, 9 Feb 2021 20:39:23 +0100 Subject: [PATCH 19/19] Removed unused import statement --- .../test/camera_platform_interface_test.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/camera/camera_platform_interface/test/camera_platform_interface_test.dart b/packages/camera/camera_platform_interface/test/camera_platform_interface_test.dart index 49de9375fdfb..f663db9776d1 100644 --- a/packages/camera/camera_platform_interface/test/camera_platform_interface_test.dart +++ b/packages/camera/camera_platform_interface/test/camera_platform_interface_test.dart @@ -6,7 +6,6 @@ import 'package:camera_platform_interface/camera_platform_interface.dart'; import 'package:camera_platform_interface/src/method_channel/method_channel_camera.dart'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'package:plugin_platform_interface/plugin_platform_interface.dart'; void main() { TestWidgetsFlutterBinding.ensureInitialized();