A Flutter plugin to get the camera's field of view (FOV) on iOS and Android.
- Get horizontal and vertical field of view angles from the back camera
- No camera permissions required
- Strongly-typed API using Pigeon
- Supports iOS and Android
Add this to your package's pubspec.yaml file:
dependencies:
field_of_view: ^0.0.1import 'package:field_of_view/field_of_view.dart';
final fov = FieldOfView();
try {
final response = await fov.getFieldOfView();
print('Horizontal FOV: ${response.horizontalFov}°');
print('Vertical FOV: ${response.verticalFov}°');
} on PlatformException catch (e) {
print('Error: ${e.message}');
}The FieldOfViewResponse contains:
| Property | Type | Description |
|---|---|---|
horizontalFov |
double |
Horizontal field of view in degrees |
verticalFov |
double |
Vertical field of view in degrees |
Note: The FOV values represent the camera sensor's native orientation (landscape), so horizontal FOV will typically be larger than vertical FOV, regardless of device orientation.
The plugin throws PlatformException with the following error codes:
| Code | Description |
|---|---|
CAMERA_UNAVAILABLE |
No back camera found on the device |
SENSOR_UNAVAILABLE |
Could not retrieve sensor size information |
FOCAL_LENGTH_UNAVAILABLE |
Could not retrieve focal length information |
-
iOS: Uses
AVCaptureDevice.Format.geometricDistortionCorrectedVideoFieldOfViewfor horizontal FOV (corrected for lens distortion) and calculates vertical FOV from the aspect ratio. Requires iOS 13.0+. -
Android: Uses Camera2 API to read
SENSOR_INFO_PHYSICAL_SIZEandLENS_INFO_AVAILABLE_FOCAL_LENGTHSfromCameraCharacteristics, then calculates FOV using the pinhole camera model:
FOV = 2 × atan(sensorSize / (2 × focalLength))