Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/camera/camera_platform_interface/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## NEXT
## 2.13.1

* Changes the default implementation of `setJpegImageQuality` to a no-op so that
platforms that do not support it ignore the setting instead of throwing.
* Updates minimum supported SDK version to Flutter 3.38/Dart 3.10.

## 2.13.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,12 @@ abstract class CameraPlatform extends PlatformInterface {
///
/// This only applies to images captured in JPEG format.
/// The [quality] must be between 1 (lowest) and 100 (highest).
Future<void> setJpegImageQuality(int cameraId, int quality) {
throw UnimplementedError('setJpegImageQuality() is not implemented.');
///
/// This is a best-effort setting; platforms that do not support controlling
/// the JPEG quality ignore it. The default implementation is a no-op so that
/// calling it is always safe.
Future<void> setJpegImageQuality(int cameraId, int quality) async {
// No-op by default. Platforms that support setting the JPEG quality
// override this method.
}
Comment on lines +344 to 347

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The documentation states that quality must be between 1 and 100. Adding an assertion to enforce this contract in the default implementation ensures consistent behavior across all platforms during development, preventing silent bugs when testing on platforms that do not support JPEG quality control.

Additionally, since this is a synchronous no-op, we can return Future<void>.value() directly and avoid the async keyword overhead.

Suggested change
Future<void> setJpegImageQuality(int cameraId, int quality) async {
// No-op by default. Platforms that support setting the JPEG quality
// override this method.
}
Future<void> setJpegImageQuality(int cameraId, int quality) {
assert(quality >= 1 && quality <= 100);
return Future<void>.value();
}

}
2 changes: 1 addition & 1 deletion packages/camera/camera_platform_interface/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ 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
# 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.13.0
version: 2.13.1

environment:
sdk: ^3.10.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,12 +353,12 @@ void main() {
expect(() => cameraPlatform.resumePreview(1), throwsUnimplementedError);
});

test('Default implementation of setJpegImageQuality() should throw unimplemented error', () {
test('Default implementation of setJpegImageQuality() is a no-op', () {
// Arrange
final cameraPlatform = ExtendsCameraPlatform();

// Act & Assert
expect(() => cameraPlatform.setJpegImageQuality(1, 50), throwsUnimplementedError);
expect(cameraPlatform.setJpegImageQuality(1, 50), completes);
});
Comment on lines +356 to 362

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Update the test to verify that the default implementation completes successfully for valid quality values, and asserts on invalid quality values (e.g., < 1 or > 100).

    test('Default implementation of setJpegImageQuality() is a no-op and asserts on invalid quality', () {
      // Arrange
      final cameraPlatform = ExtendsCameraPlatform();

      // Act & Assert
      expect(cameraPlatform.setJpegImageQuality(1, 50), completes);
      expect(() => cameraPlatform.setJpegImageQuality(1, 0), throwsAssertionError);
      expect(() => cameraPlatform.setJpegImageQuality(1, 101), throwsAssertionError);
    });


test('Default implementation of supportsImageStreaming() should return false', () {
Expand Down