Open Source

Flutter package

camera_extended

Flutter's camera plugin, forked to add native aspect-ratio capture — 16:9, 4:3 and 1:1 at the sensor level on Android and iOS.

v1.2.522.7k / month16 likesBSD-3-ClauseAndroid · iOS16:9 · 4:3 · 1:1

API reference

CameraController with the aspectRatio parameter, takePictureAsBytes, the CameraPreview widget, MediaSettings and the CameraAspectRatio enum.

source: packages/camera/README.md

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/.

dart
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.

Constructordart
CameraController(
  CameraDescription description,
  ResolutionPreset resolutionPreset, {
  bool enableAudio = true,
  int? fps,
  int? videoBitrate,
  int? audioBitrate,
  CameraAspectRatio aspectRatio = CameraAspectRatio.ratioDefault,
  ImageFormatGroup? imageFormatGroup,
})
ParameterTypeRequiredDefaultMeaning
descriptionCameraDescriptionYes (positional)The camera device to control, from availableCameras().
resolutionPresetResolutionPresetYes (positional)Target quality for capture and recording. Not guaranteed on every device; a lower preset is used when unavailable.
enableAudioboolNotrueWhether recorded video includes audio.
fpsint?NonullFrame rate for recording. Overrides the preset when set.
videoBitrateint?NonullVideo encoding bit rate. Overrides the preset when set.
audioBitrateint?NonullAudio encoding bit rate. Overrides the preset when set.
aspectRatioCameraAspectRatioNoratioDefaultNew. Sensor-level aspect ratio for preview and capture.
imageFormatGroupImageFormatGroup?NonullOutput format for streamed frames; falls back to the platform default.

Two getters expose the aspect-ratio configuration after construction:

Added gettersdart
// 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.

dart
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
}
ValueNumeric ratioLabelPlatform behaviour
ratio16x916 / 916:9Native on Android and iOS
ratio4x34 / 34:3Native on Android and iOS
ratio1x11.01:1Native on Android (1088×1088, 720×720); falls back to 4:3 on iOS
ratioDefault4 / 3DefaultNative 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:

CameraAspectRatioExtensiondart
// 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.

Signaturedart
Future<Uint8List> takePictureAsBytes();
dart
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.

VideoStabilizationModedart
enum VideoStabilizationMode {
  off,     // stabilization disabled
  level1,  // least stabilized, least latency
  level2,  // more stabilized, more latency
  level3,  // most stabilized, most latency
}
CameraController methodsdart
// 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.

Constructordart
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.

dart
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:

MethodReturnsDescription
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:

Top-level functiondart
Future<List<CameraDescription>> availableCameras();
SymbolKind
availableCameras()Function
CameraDescriptionClass
CameraExceptionClass
XFileClass
CameraLensDirectionEnum
CameraLensTypeEnum
ResolutionPresetEnum
FlashModeEnum
ExposureModeEnum
FocusModeEnum
ImageFormatGroupEnum

Let's make something together.

If you have any questions about a new project or other inquiries, feel free to contact us. We will get back to you as soon as possible.

Codigee
We are using cookies. Learn more