diff --git a/packages/camera/camera/CHANGELOG.md b/packages/camera/camera/CHANGELOG.md index 5e923b81d2c5..d0d58be6ca92 100644 --- a/packages/camera/camera/CHANGELOG.md +++ b/packages/camera/camera/CHANGELOG.md @@ -1,6 +1,7 @@ -## NEXT +## 0.11.1 -* Updates minimum supported SDK version to Flutter 3.22/Dart 3.4. +* Adds API support query for image streaming. +* Updates minimum supported SDK version to Flutter 3.27/Dart 3.6. * Updates example to dispose animation controllers and curved animations. ## 0.11.0+2 diff --git a/packages/camera/camera/lib/src/camera_controller.dart b/packages/camera/camera/lib/src/camera_controller.dart index 5f90a0a740a9..3f39d3202b8f 100644 --- a/packages/camera/camera/lib/src/camera_controller.dart +++ b/packages/camera/camera/lib/src/camera_controller.dart @@ -480,13 +480,12 @@ class CameraController extends ValueNotifier { /// Throws a [CameraException] if image streaming or video recording has /// already started. /// - /// The `startImageStream` method is only available on Android and iOS (other - /// platforms won't be supported in current setup). + /// The `startImageStream` method is only available on platforms that + /// report support for image streaming via [supportsImageStreaming]. /// // TODO(bmparr): Add settings for resolution and fps. Future startImageStream(onLatestImageAvailable onAvailable) async { - assert(defaultTargetPlatform == TargetPlatform.android || - defaultTargetPlatform == TargetPlatform.iOS); + assert(supportsImageStreaming()); _throwIfNotInitialized('startImageStream'); if (value.isRecordingVideo) { throw CameraException( @@ -518,11 +517,10 @@ class CameraController extends ValueNotifier { /// Throws a [CameraException] if image streaming was not started or video /// recording was started. /// - /// The `stopImageStream` method is only available on Android and iOS (other - /// platforms won't be supported in current setup). + /// The `stopImageStream` method is only available on platforms that + /// report support for image streaming via [supportsImageStreaming]. Future stopImageStream() async { - assert(defaultTargetPlatform == TargetPlatform.android || - defaultTargetPlatform == TargetPlatform.iOS); + assert(supportsImageStreaming()); _throwIfNotInitialized('stopImageStream'); if (!value.isStreamingImages) { throw CameraException( @@ -871,6 +869,10 @@ class CameraController extends ValueNotifier { } } + /// Check whether the camera platform supports image streaming. + bool supportsImageStreaming() => + CameraPlatform.instance.supportsImageStreaming(); + /// Releases the resources of this camera. @override Future dispose() async { diff --git a/packages/camera/camera/pubspec.yaml b/packages/camera/camera/pubspec.yaml index d8144150bccd..09899dfa5796 100644 --- a/packages/camera/camera/pubspec.yaml +++ b/packages/camera/camera/pubspec.yaml @@ -4,11 +4,11 @@ description: A Flutter plugin for controlling the camera. Supports previewing Dart. repository: https://github.com/flutter/packages/tree/main/packages/camera/camera issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22 -version: 0.11.0+2 +version: 0.11.1 environment: - sdk: ^3.4.0 - flutter: ">=3.22.0" + sdk: ^3.6.0 + flutter: ">=3.27.0" flutter: plugin: @@ -21,9 +21,9 @@ flutter: default_package: camera_web dependencies: - camera_android_camerax: ^0.6.5 - camera_avfoundation: ^0.9.15 - camera_platform_interface: ^2.6.0 + camera_android_camerax: ^0.6.13 + camera_avfoundation: ^0.9.18 + camera_platform_interface: ^2.9.0 camera_web: ^0.3.3 flutter: sdk: flutter diff --git a/packages/camera/camera/test/camera_image_stream_test.dart b/packages/camera/camera/test/camera_image_stream_test.dart index c89e4acaa726..fd17694e246b 100644 --- a/packages/camera/camera/test/camera_image_stream_test.dart +++ b/packages/camera/camera/test/camera_image_stream_test.dart @@ -100,8 +100,11 @@ void main() { await cameraController.startImageStream((CameraImage image) {}); - expect(mockPlatform.streamCallLog, - ['onStreamedFrameAvailable', 'listen']); + expect(mockPlatform.streamCallLog, [ + 'supportsImageStreaming', + 'onStreamedFrameAvailable', + 'listen' + ]); }); test('stopImageStream() throws $CameraException when uninitialized', () { @@ -160,8 +163,13 @@ void main() { await cameraController.startImageStream((CameraImage image) {}); await cameraController.stopImageStream(); - expect(mockPlatform.streamCallLog, - ['onStreamedFrameAvailable', 'listen', 'cancel']); + expect(mockPlatform.streamCallLog, [ + 'supportsImageStreaming', + 'onStreamedFrameAvailable', + 'listen', + 'supportsImageStreaming', + 'cancel' + ]); }); test('startVideoRecording() can stream images', () async { @@ -235,6 +243,12 @@ class MockStreamingCameraPlatform extends MockCameraPlatform { streamCallLog.add('listen'); } + @override + bool supportsImageStreaming() { + streamCallLog.add('supportsImageStreaming'); + return true; + } + FutureOr _onFrameStreamCancel() async { streamCallLog.add('cancel'); _streamController = null; diff --git a/packages/camera/camera/test/camera_preview_test.dart b/packages/camera/camera/test/camera_preview_test.dart index d76ac7ea02ec..bcec28fe5b9d 100644 --- a/packages/camera/camera/test/camera_preview_test.dart +++ b/packages/camera/camera/test/camera_preview_test.dart @@ -132,6 +132,9 @@ class FakeController extends ValueNotifier @override CameraDescription get description => value.description; + + @override + bool supportsImageStreaming() => true; } void main() {