CameraController class abstract

Controls a device's camera and provides access to camera features.

This class takes a device and a list of CameraOutputs. After instantiation, initialize should be AWAITED before any other method.

After initialize, calling start begins the flow of data from device to the outputs. Each output should contain additional methods that provide a preview widget, take a picture, or record a video.

dispose should be called when camera resources are no longer needed. No other methods can be called after a controller is disposed. Also, consider calling dispose when a user leaves the app.

Example usage to add an ImageCaptureOutput and take a photo:

final List<CameraDevice> devices =
    await CameraController.getAllCameraDevices();
final CameraDevice device = devices.firstWhere(
  (CameraDevice device) => device.position == CameraPosition.back,
);

final ImageCaptureOutput imageOutput = ImageCaptureOutput();
final CameraController controller =
CameraController(device: device, outputs: <CameraOutput>[PreviewOutput(), imageOutput]);
// This should be awaited before calling any other methods.
await controller.initialize();
controller.start();

imageOutput.takePicture((Uint8List data) {
  print(data.length);
});

controller.stop();
controller.dispose();

See: PreviewOutput ImageCaptureOutput VideoCaptureOutput

Implementers

Constructors

CameraController({required CameraDevice device, required List<CameraOutput> outputs})
Construct a CameraController.
factory

Properties

device CameraDevice
The camera device controlled by this controller.
no setter
hashCode int
The hash code for this object.
no setterinherited
outputs List<CameraOutput>
The ouptuts frame data is streamed to from device.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

dispose() Future<void>
Release all resources held by device and detach all outputs.
initialize() Future<void>
Initializes this controller and attaches the outputs.
maxZoom() Future<double>
The maximum zoom value of a device.
minZoom() Future<double>
The minimum zoom value of a device.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
setControllerPreset(CameraControllerPreset preset) Future<void>
Set a preset configuration for a CameraController.
setExposureMode(ExposureMode mode) Future<void>
Set the exposure mode for a device.
setFocusMode(FocusMode mode) Future<void>
Set the focus mode of the device.
setTorchMode(TorchMode mode) Future<void>
Set the torch mode for a device.
setZoom(double value) Future<void>
Set a zoom value for a device.
smoothZoomSupported() Future<bool>
Whether a device can start a smooth zoom.
smoothZoomTo(double value) Future<void>
Smoothly transition the zoom value for a device.
start() Future<void>
Start the flow of data from device to outputs.
stop() Future<void>
Stop the flow of data from device to outputs.
supportedExposureModes() Future<List<ExposureMode>>
Retrieve all supported exposure modes for a device.
supportedFocusModes() Future<List<FocusMode>>
Retrieve all supported focus modes for a device.
supportedTorchModes() Future<List<TorchMode>>
Retrieve all supported torch modes for a device.
toString() String
A string representation of this object.
inherited
zoomSupported() Future<bool>
Whether a zoom value can be set.

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

getAllCameraDevices() Future<List<CameraDevice>>
Retrieve information for available CameraDevices.