Skip to content

Commit c254eca

Browse files
authored
[Camera] Add lens type information (iOS) (#8723)
This PR adds lens type information. The goal is to identify whether the lens type is wide, ultra-wide, telephoto, etc., as discussed in flutter/flutter#119908. The iOS implementation is complete, so lens data will now be populated on iOS. - Introduces a new CameraLensType enum to provide lens type information about the camera (e.g.: ultra-wide, telephoto, ...) - Adds lensType in the PlatformCameraDescription and CameraDescription classes - Implements utility functions to convert between PlatformCameraLensType and CameraLensType. - Updates auto-generated code (using Pigeon) to reflect these changes. **Current CameraDescription for iPhone 11** ``` [ CameraDescription( com.apple.avfoundation.avcapturedevice.built-in_video:0, CameraLensDirection.back, 90 ), CameraDescription( com.apple.avfoundation.avcapturedevice.built-in_video:1, CameraLensDirection.front, 90 ), CameraDescription( com.apple.avfoundation.avcapturedevice.built-in_video:5, CameraLensDirection.back, 90 ) ] ``` **New CameraDescription for iPhone 11** ``` [ CameraDescription( com.apple.avfoundation.avcapturedevice.built-in_video:0, CameraLensDirection.back, 90, CameraLensType.wide ), CameraDescription( com.apple.avfoundation.avcapturedevice.built-in_video:1, CameraLensDirection.front, 90, CameraLensType.wide ), CameraDescription( com.apple.avfoundation.avcapturedevice.built-in_video:5, CameraLensDirection.back, 90, CameraLensType.ultraWide ) ] ```
1 parent 1977932 commit c254eca

4 files changed

Lines changed: 58 additions & 6 deletions

File tree

packages/camera/camera_platform_interface/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 2.10.0
2+
3+
* Introduces a new `CameraLensType` enum to provide lens type information about
4+
the camera (e.g., ultra-wide, telephoto, ...).
5+
16
## 2.9.0
27

38
* Updates minimum supported SDK version to Flutter 3.22/Dart 3.4.

packages/camera/camera_platform_interface/lib/src/types/camera_description.dart

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,23 @@ enum CameraLensDirection {
1616
external,
1717
}
1818

19+
/// Represents various built-in camera lens types available on a device.
20+
///
21+
/// Each lens type offers different focal lengths and capabilities for capturing images.
22+
enum CameraLensType {
23+
/// A built-in wide-angle camera device type.
24+
wide,
25+
26+
/// A built-in camera device type with a longer focal length than a wide-angle camera.
27+
telephoto,
28+
29+
/// A built-in camera device type with a shorter focal length than a wide-angle camera.
30+
ultraWide,
31+
32+
/// Unknown camera device type.
33+
unknown,
34+
}
35+
1936
/// Properties of a camera device.
2037
@immutable
2138
class CameraDescription {
@@ -24,6 +41,7 @@ class CameraDescription {
2441
required this.name,
2542
required this.lensDirection,
2643
required this.sensorOrientation,
44+
this.lensType = CameraLensType.unknown,
2745
});
2846

2947
/// The name of the camera device.
@@ -41,20 +59,24 @@ class CameraDescription {
4159
/// is from top to bottom in the sensor's coordinate system.
4260
final int sensorOrientation;
4361

62+
/// The type of lens the camera has.
63+
final CameraLensType lensType;
64+
4465
@override
4566
bool operator ==(Object other) =>
4667
identical(this, other) ||
4768
other is CameraDescription &&
4869
runtimeType == other.runtimeType &&
4970
name == other.name &&
50-
lensDirection == other.lensDirection;
71+
lensDirection == other.lensDirection &&
72+
lensType == other.lensType;
5173

5274
@override
53-
int get hashCode => Object.hash(name, lensDirection);
75+
int get hashCode => Object.hash(name, lensDirection, lensType);
5476

5577
@override
5678
String toString() {
5779
return '${objectRuntimeType(this, 'CameraDescription')}('
58-
'$name, $lensDirection, $sensorOrientation)';
80+
'$name, $lensDirection, $sensorOrientation, $lensType)';
5981
}
6082
}

packages/camera/camera_platform_interface/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ repository: https://github.com/flutter/packages/tree/main/packages/camera/camera
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22
55
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
66
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
7-
version: 2.9.0
7+
version: 2.10.0
88

99
environment:
1010
sdk: ^3.4.0

packages/camera/camera_platform_interface/test/types/camera_description_test.dart

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,27 @@ void main() {
3030
name: 'Test',
3131
lensDirection: CameraLensDirection.front,
3232
sensorOrientation: 90,
33+
lensType: CameraLensType.ultraWide,
3334
);
3435

3536
expect(description.name, 'Test');
3637
expect(description.lensDirection, CameraLensDirection.front);
3738
expect(description.sensorOrientation, 90);
39+
expect(description.lensType, CameraLensType.ultraWide);
3840
});
3941

4042
test('equals should return true if objects are the same', () {
4143
const CameraDescription firstDescription = CameraDescription(
4244
name: 'Test',
4345
lensDirection: CameraLensDirection.front,
4446
sensorOrientation: 90,
47+
lensType: CameraLensType.ultraWide,
4548
);
4649
const CameraDescription secondDescription = CameraDescription(
4750
name: 'Test',
4851
lensDirection: CameraLensDirection.front,
4952
sensorOrientation: 90,
53+
lensType: CameraLensType.ultraWide,
5054
);
5155

5256
expect(firstDescription == secondDescription, true);
@@ -57,11 +61,13 @@ void main() {
5761
name: 'Test',
5862
lensDirection: CameraLensDirection.front,
5963
sensorOrientation: 90,
64+
lensType: CameraLensType.ultraWide,
6065
);
6166
const CameraDescription secondDescription = CameraDescription(
6267
name: 'Testing',
6368
lensDirection: CameraLensDirection.front,
6469
sensorOrientation: 90,
70+
lensType: CameraLensType.ultraWide,
6571
);
6672

6773
expect(firstDescription == secondDescription, false);
@@ -72,11 +78,13 @@ void main() {
7278
name: 'Test',
7379
lensDirection: CameraLensDirection.front,
7480
sensorOrientation: 90,
81+
lensType: CameraLensType.ultraWide,
7582
);
7683
const CameraDescription secondDescription = CameraDescription(
7784
name: 'Test',
7885
lensDirection: CameraLensDirection.back,
7986
sensorOrientation: 90,
87+
lensType: CameraLensType.ultraWide,
8088
);
8189

8290
expect(firstDescription == secondDescription, false);
@@ -87,11 +95,13 @@ void main() {
8795
name: 'Test',
8896
lensDirection: CameraLensDirection.front,
8997
sensorOrientation: 0,
98+
lensType: CameraLensType.ultraWide,
9099
);
91100
const CameraDescription secondDescription = CameraDescription(
92101
name: 'Test',
93102
lensDirection: CameraLensDirection.front,
94103
sensorOrientation: 90,
104+
lensType: CameraLensType.ultraWide,
95105
);
96106

97107
expect(firstDescription == secondDescription, true);
@@ -103,11 +113,26 @@ void main() {
103113
name: 'Test',
104114
lensDirection: CameraLensDirection.front,
105115
sensorOrientation: 0,
116+
lensType: CameraLensType.ultraWide,
106117
);
107-
final int expectedHashCode =
108-
Object.hash(description.name, description.lensDirection);
118+
final int expectedHashCode = Object.hash(
119+
description.name, description.lensDirection, description.lensType);
109120

110121
expect(description.hashCode, expectedHashCode);
111122
});
123+
124+
test('toString should return correct string representation', () {
125+
const CameraDescription description = CameraDescription(
126+
name: 'Test',
127+
lensDirection: CameraLensDirection.front,
128+
sensorOrientation: 90,
129+
lensType: CameraLensType.ultraWide,
130+
);
131+
132+
expect(
133+
description.toString(),
134+
'CameraDescription(Test, CameraLensDirection.front, 90, CameraLensType.ultraWide)',
135+
);
136+
});
112137
});
113138
}

0 commit comments

Comments
 (0)