Camera class Null safety

The Camera class is used to set image capture settings, start/stop preview, snap pictures, and retrieve frames for encoding for video.

This uses the Camera API and is deprecated for Android versions 21+.

This class is a client for the Camera service, which manages the actual camera hardware.

To access the device camera, you must declare the Manifest.permission.CAMERA permission in your Android Manifest. Also be sure to include the <uses-feature> manifest element to declare camera features used by your application. For example, if you use the camera and auto-focus feature, your Manifest should include the following:

<uses-permission android:name="android.permission.CAMERA" />
 <uses-feature android:name="" />
 <uses-feature android:name="" />

To take pictures with this class, use the following steps:

  1. Obtain an instance of Camera from open.
  2. Get existing (default) settings with getParameters.
  3. If necessary, modify the returned CameraParameters object and call setParameters.
  4. Call setDisplayOrientation to ensure correct orientation of preview.
  5. Attach preview frames to a Flutter texture with attachPreviewTexture.
  6. Important: Call startPreview to start updating the preview surface. Preview must be started before you can take a picture.
  7. When you want, call takePicture to capture a photo. Wait for the callbacks to provide the actual image data.
  8. After taking a picture, preview display will have stopped. To take more photos, call startPreview again first.
  9. Call stopPreview to stop updating the preview surface.
  10. Important: Call release to release the camera for use by other applications. Applications should release the camera immediately with AppLifecycleState.paused (and re-open() it in AppLifecycleState.resumed)

To quickly switch to video recording mode, use these steps:

  1. Obtain and initialize a Camera and start preview as described above.
  2. Call unlock to allow the media process to access the camera.
  3. Pass the camera to MediaRecorder.setCamera. See MediaRecorder information about video recording.
  4. When finished recording, call reconnect to re-acquire and re-lock the camera.
  5. If desired, restart preview and take more photos or videos.
  6. Call stopPreview and release as described above.

Caution: Different Android-powered devices may have different hardware specifications, such as megapixel ratings and auto-focus capabilities. In order for your application to be compatible with more devices, you should not make assumptions about the device camera specifications.

  • @Reference('android_hardware/camera/Camera')


Construct a Camera.


hashCode int
The hash code for this object.
runtimeType Type
A representation of the runtime type of the object.


attachPreviewTexture() Future<int>
Attach preview frames to a Flutter Texture.
autoFocus(AutoFocusCallback callback) Future<void>
Starts camera auto-focus and registers a callback function to run when the camera is focused.
cancelAutoFocus() Future<void>
Cancels any auto-focus function in progress.
enableShutterSound({required bool enabled}) Future<bool>
Enable or disable the default shutter sound when taking a picture.
getParameters() Future<CameraParameters>
Returns the current settings for this Camera service.
lock() Future<void>
Re-locks the camera to prevent other processes from accessing it.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed.
reconnect() Future<void>
Reconnects to the camera service after another process used it.
release() Future<void>
Disconnects and releases the Camera object resources.
releasePreviewTexture() Future<void>
Release the Flutter Texture receiving preview frames.
setAutoFocusMoveCallback(AutoFocusMoveCallback callback) Future<void>
Sets camera auto-focus move callback.
setDisplayOrientation(int degrees) Future<void>
Set the clockwise rotation of preview display in degrees.
setErrorCallback(ErrorCallback callback) Future<void>
Registers a callback to be invoked when an error occurs.
setOneShotPreviewCallback(PreviewCallback callback) Future<void>
Installs a callback to be invoked for the next preview frame in addition to displaying it on the screen.
setParameters(CameraParameters parameters) Future<void>
Changes the settings for this Camera service.
setPreviewCallback(PreviewCallback? callback) Future<void>
Installs a callback to be invoked for every preview frame in addition to displaying them on the screen.
setZoomChangeListener(OnZoomChangeListener listener) Future<void>
Registers a listener to be notified when the zoom value is updated by the camera driver during smooth zoom.
startPreview() Future<void>
Starts capturing and drawing preview frames to the screen.
startSmoothZoom(int value) Future<void>
Zooms to the requested value smoothly.
stopPreview() Future<void>
Stops capturing and drawing preview frames to the surface.
stopSmoothZoom() Future<void>
Stops the smooth zoom.
takePicture({ShutterCallback? shutter, PictureCallback? raw, PictureCallback? postView, PictureCallback? jpeg}) Future<void>
Triggers an asynchronous image capture.
toString() String
A string representation of this object.
unlock() Future<void>
Unlocks the camera to allow another process to access it.


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

Static Methods

getAllCameraInfo() Future<List<CameraInfo>>
Returns the information about each available camera.
open(int cameraId) Future<Camera>
Creates a new Camera object to access a particular hardware camera.


errorEvicted → const int
Camera was disconnected due to use by higher priority user.
errorServerDied → const int
Media server died.
errorUnknown → const int
Unspecified camera error.