API reference
The library
A single import exposes the whole surface. camera_extended re-exports the official plugin's types and adds the aspect-ratio, takePictureAsBytes() and video-stabilization APIs documented below. Everything on this page is taken verbatim from the package source in lib/.
import 'package:camera_extended/camera_extended.dart';Source of truth
Where the package README and the bundled doc/api.mddiffer from the code, this reference follows the code. In particular the real VideoStabilizationMode values are off, level1, level2, level3, and getSupportedVideoStabilizationModes() returns an Iterable, not a List.
What's added
CameraController
The constructor keeps the official signature and adds the optional aspectRatio parameter. It bundles all recording options into a MediaSettings instance and starts uninitialized — call initialize() before use.
CameraController(
CameraDescription description,
ResolutionPreset resolutionPreset, {
bool enableAudio = true,
int? fps,
int? videoBitrate,
int? audioBitrate,
CameraAspectRatio aspectRatio = CameraAspectRatio.ratioDefault,
ImageFormatGroup? imageFormatGroup,
})| Parameter | Type | Required | Default | Meaning |
|---|---|---|---|---|
description | CameraDescription | Yes (positional) | — | The camera device to control, from availableCameras(). |
resolutionPreset | ResolutionPreset | Yes (positional) | — | Target quality for capture and recording. Not guaranteed on every device; a lower preset is used when unavailable. |
enableAudio | bool | No | true | Whether recorded video includes audio. |
fps | int? | No | null | Frame rate for recording. Overrides the preset when set. |
videoBitrate | int? | No | null | Video encoding bit rate. Overrides the preset when set. |
audioBitrate | int? | No | null | Audio encoding bit rate. Overrides the preset when set. |
aspectRatio | CameraAspectRatio | No | ratioDefault | New. Sensor-level aspect ratio for preview and capture. |
imageFormatGroup | ImageFormatGroup? | No | null | Output format for streamed frames; falls back to the platform default. |
Two getters expose the aspect-ratio configuration after construction:
// The aspect ratio this controller targets at the sensor level.
CameraAspectRatio get targetAspectRatio; // => mediaSettings.aspectRatio
// The full media settings (resolution, fps, bitrates, audio, aspectRatio).
final MediaSettings mediaSettings;Enum
CameraAspectRatio
Selects the aspect ratio at the native sensor level. This is the core addition over the stock plugin.
enum CameraAspectRatio {
ratio16x9, // 16:9 widescreen — standard for HD video
ratio4x3, // 4:3 standard — more vertical field of view
ratio1x1, // 1:1 square — widest horizontal field of view on most sensors
ratioDefault, // camera's default ratio — typically 4:3 on mobile
}| Value | Numeric ratio | Label | Platform behaviour |
|---|---|---|---|
ratio16x9 | 16 / 9 | 16:9 | Native on Android and iOS |
ratio4x3 | 4 / 3 | 4:3 | Native on Android and iOS |
ratio1x1 | 1.0 | 1:1 | Native on Android (1088×1088, 720×720); falls back to 4:3 on iOS |
ratioDefault | 4 / 3 | Default | Native on Android and iOS (camera's native ratio) |
The platform-interface package ships an extension with helpers for the numeric value, a display label and platform-channel serialization:
// Defined in camera_extended_platform_interface.
extension CameraAspectRatioExtension on CameraAspectRatio {
double get value; // 16/9, 4/3, 1.0, 4/3 (for ratioDefault)
String get label; // '16:9', '4:3', '1:1', 'Default'
bool get isSquare; // true only for ratio1x1
String serialize(); // 'ratio16x9' | 'ratio4x3' | 'ratio1x1' | 'ratioDefault'
static CameraAspectRatio deserialize(String value);
}Capture
takePictureAsBytes()
Captures an image and returns the raw JPEG-encoded bytes as a Uint8List without writing to disk — useful for ML/image processing pipelines or direct uploads. Throws a CameraException if the controller is uninitialized, disposed, or a previous capture has not returned yet.
Future<Uint8List> takePictureAsBytes();final Uint8List bytes = await controller.takePictureAsBytes();
// Use the JPEG-encoded bytes directly — no file I/O.
await api.uploadImage(bytes);Enum + methods
Video stabilization
Query and set video stabilization at the hardware level. Availability is per-device, so always check the supported modes first.
enum VideoStabilizationMode {
off, // stabilization disabled
level1, // least stabilized, least latency
level2, // more stabilized, more latency
level3, // most stabilized, most latency
}// Query the modes this device actually supports.
// The list may be empty when the platform has no support.
Future<Iterable<VideoStabilizationMode>>
getSupportedVideoStabilizationModes();
// Apply a mode. When [allowFallback] is true (default) and [mode] is
// unsupported, the controller walks down to a lower supported level;
// with allowFallback: false it throws an ArgumentError instead.
Future<void> setVideoStabilizationMode(
VideoStabilizationMode mode, {
bool allowFallback = true,
});Fallback
When the requested mode is unsupported and allowFallback is true, the controller walks down the fallback chain and applies the nearest supported level; if none is supported it is a no-op. With allowFallback: false an unsupported mode throws an ArgumentError. The current mode is exposed on controller.value.videoStabilizationMode (defaults to off).
Class
MediaSettings
The recording configuration the controller passes to the platform. You rarely construct it directly — the CameraController constructor builds one for you — but it is the object that carries aspectRatio down to the native layer.
const MediaSettings({
ResolutionPreset? resolutionPreset,
int? fps, // must be null or > 0
int? videoBitrate, // must be null or > 0
int? audioBitrate, // must be null or > 0
bool enableAudio = false,
CameraAspectRatio aspectRatio = CameraAspectRatio.ratioDefault,
})enableAudio default
MediaSettings defaults enableAudio to false, while the CameraController constructor defaults it to true and forwards your value. fps, videoBitrate and audioBitrate must each be null or greater than zero.
Widget
CameraPreview
A StatelessWidget that renders the live preview for an initialized controller, sized to the controller's current aspect ratio. Pass an optional child to overlay UI on top.
class CameraPreview extends StatelessWidget {
const CameraPreview(this.controller, {super.key, this.child});
final CameraController controller; // an initialized controller
final Widget? child; // optional overlay on top of the preview
}From the camera plugin
Inherited controller surface
Everything the official CameraController exposes is available unchanged. The lifecycle and capture essentials:
| Method | Returns | Description |
|---|---|---|
initialize() | Future<void> | Initialize the camera. Must complete before use. |
dispose() | Future<void> | Release camera resources. |
takePicture() | Future<XFile> | Capture a still image and save it to a file. |
startVideoRecording({onAvailable, enablePersistentRecording = true}) | Future<void> | Begin recording video, optionally streaming frames. |
stopVideoRecording() | Future<XFile> | Stop recording and return the saved file. |
pauseVideoRecording() / resumeVideoRecording() | Future<void> | Pause and resume an active recording (iOS, Android SDK 24+). |
pausePreview() / resumePreview() | Future<void> | Pause and resume the live preview. |
startImageStream(onAvailable) / stopImageStream() | Future<void> | Stream camera frames (where supportsImageStreaming() is true). |
setFlashMode(FlashMode) | Future<void> | Set the flash mode. |
setExposureMode(ExposureMode) / setFocusMode(FocusMode) | Future<void> | Set exposure and focus modes. |
getMinZoomLevel() / getMaxZoomLevel() / setZoomLevel(double) | Future<double> / Future<void> | Query the zoom range and set the zoom level. |
lockCaptureOrientation([DeviceOrientation]) / unlockCaptureOrientation() | Future<void> | Lock or release the capture orientation. |
Controller state lives on controller.value (a CameraValue): isInitialized, isTakingPicture, isRecordingVideo, previewSize, the aspectRatio getter (preview width ÷ height) and videoStabilizationMode.
Re-exported
Types you can import
The single camera_extended.dart import re-exports the common types from the platform interface, so you do not depend on it directly:
Future<List<CameraDescription>> availableCameras();| Symbol | Kind |
|---|---|
availableCameras() | Function |
CameraDescription | Class |
CameraException | Class |
XFile | Class |
CameraLensDirection | Enum |
CameraLensType | Enum |
ResolutionPreset | Enum |
FlashMode | Enum |
ExposureMode | Enum |
FocusMode | Enum |
ImageFormatGroup | Enum |
