NitroCamera class abstract

The main NitroCamera hybrid module.

Use NitroCamera.instance directly, or prefer the higher-level CameraController + CameraPreview Dart API for widget integration.

Implementers
Available extensions
Annotations
  • @NitroModule.new(ios: NativeImpl.swift, android: NativeImpl.kotlin)

Constructors

NitroCamera()

Properties

asAnyNativeObject → AnyNativeObject

Available on NitroCamera, provided by the NitroCameraNativeRef extension

no setter
depthStream → Stream<DepthFrame>
Depth maps from every session with setDepthOutput on.
no setter
eventStream → Stream<CameraEvent>
Stream of session lifecycle / error / interruption events across all open camera sessions. Buffered (oldest dropped) so events are never lost to a briefly-slow listener.
no setter
frameStream → Stream<CameraFrame>
Stream of raw camera frames for custom image processing pipelines. Only active for sessions where enableFrameProcessing was called with 1.
no setter
hashCode → int
The hash code for this object.
no setterinherited
isDisposed → bool
Whether dispose has been called on this object.
no setterinherited
resizedStream → Stream<ResizedFrame>
GPU-resized tensors from every session with setResizer on.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
syncedStream → Stream<SyncedFrame>
Frame + depth pairs from every session with setSynchronizedOutput on.
no setter

Methods

cancelRecording(int textureId) → void
Cancels the current recording and deletes the temporary file.
checkDisposed() → void
Throws StateError if dispose has already been called. Called automatically at the start of every generated method and getter.
inherited
closeCamera(int textureId) → Future<void>
configure(int textureId, CameraConfig config) → Future<ResolvedConfig>
Applies a batch of live settings to the open session textureId in one pass and returns what was actually applied. The declarative analogue of the individual setters above — does NOT reopen the session (device/format/fps changes must go through openCamera).
dispose() → void
Releases all native resources held by this object.
inherited
enableDeviceAvailabilityEvents(int enabled) → void
Starts emitting CameraEventType.deviceConnected / CameraEventType.deviceDisconnected hot-plug events (e.g. USB cameras). enabled: 1 = on, 0 = off.
enableFrameProcessing(int textureId, int enabled) → void
Enables or disables raw frame delivery to frameStream. enabled: 1 = on, 0 = off.
enableOrientationEvents(int enabled) → void
Starts emitting CameraEventType.orientationChanged events for physical device rotation (via the native orientation sensor listener — works even when the UI orientation is locked). enabled: 1 = on, 0 = off.
focusAt(int textureId, double x, double y, int locked) → Future<int>
Focuses (and meters exposure) at the normalised point (x, y) in 0..1, (0,0) = top-left of the upright preview, and completes when the focus scan ends: 1 = focused, 0 = the scan ended without sharp focus. locked 1 keeps focus there afterwards (vision-camera's adaptiveness: 'locked'); 0 lets continuous AF resume. Throws INVALID_ARGUMENT: for a point outside 0..1 and FOCUS_UNSUPPORTED: on a fixed-focus camera.
getAvailableCameraDevices() → List<CameraDevice>
Returns a list of all available camera devices.
getAvailableCameraDevicesJson() → Future<String>
getCameraPermissionStatus() → int
Returns the current camera permission status without prompting.
getConcurrentCameraIdsJson() → String
Returns the camera-ID combinations that can stream CONCURRENTLY (multi-cam), as a JSON array of arrays (e.g. [["0","1"]]). Empty when unsupported (API < 30 or no combinations).
getDevice(int index) → CameraDevice
getDeviceCount() → int
getEncodedOutputStats(int textureId) → EncodedOutputStats
Counters of the encoder output (all zero / -1 when none is running).
getMicrophonePermissionStatus() → int
Returns the current microphone permission status without prompting.
getPreviewTransform(int textureId) → PreviewTransform
How to frame the Texture right now (see PreviewTransform). Changes on device rotation (CameraEventType.orientationChanged) and when the session switches direct <-> GL (CameraEventType.previewTransformChanged).
getSessionStateJson(int textureId) → String
Returns the live session state (running, fps, resolution, pixelFormat) as a JSON object. Useful for diagnostics and UI read-back.
lockExposure(int textureId, int locked) → void
Locks or unlocks auto-exposure at its current value. locked: 1 = locked.
lockFocus(int textureId, int locked) → void
Locks or unlocks focus at its current position. locked: 1 = locked.
lockWhiteBalance(int textureId, int locked) → void
Locks or unlocks white balance at its current gains. locked: 1 = locked.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
onDestroy() → void
Called once when dispose is first invoked. Override to perform cleanup (close file handles, cancel work, etc.).
inherited
onMemoryTrim() → void
Android low-memory signal. Override to release caches or non-critical data.
inherited
openCamera(String deviceId, int width, int height, int fps, int enableAudio, int frameWidth, int frameHeight, int enablePhoto, int directPreview) → Future<int>
Opens the camera identified by deviceId and starts streaming frames into a Flutter Texture. Returns the Flutter texture ID.
pauseRecording(int textureId) → void
Pauses an active video recording without finalising the file.
releaseNativeBuffer(int handle) → void
Returns a held CameraFrame.nativeBuffer to the camera. Unknown or already-released handles are ignored.
requestCameraPermission() → Future<int>
Requests camera permission from the OS. Returns a PermissionStatus value.
requestMicrophonePermission() → Future<int>
Requests microphone permission from the OS. Returns a PermissionStatus value.
reset() → void
Resets the native camera metadata caches and releases overall hardware locks. Call this to recover from serious CAMERA_ERROR or when hardware configuration changes (e.g. plugging in a USB camera).
resumeRecording(int textureId) → void
Resumes a paused video recording.
setAutoFocus(int textureId, int mode) → void
Sets the auto-focus mode. Pass an AutoFocusMode value.
setCameraExtension(int textureId, String name) → Future<void>
Turns a vendor camera extension on (name = auto, face-retouch, bokeh, hdr, night) or off (empty) — Android CameraExtensionSession. While one is on, only preview and stills work. Throws EXTENSION_UNSUPPORTED: (always on iOS), SESSION_BUSY: while recording.
setDepthOutput(int textureId, int enabled) → Future<void>
Starts / stops the depth stream (depthStream) for the session. Android: a DEPTH16 stream on cameras with the DEPTH_OUTPUT capability (reopens the session); iOS: AVCaptureDepthDataOutput (TrueDepth / dual / LiDAR cameras). Throws DEPTH_UNSUPPORTED: when the device has no depth (CameraFormat.supportsDepthCapture). enabled: 1 = on, 0 = off.
setDistortionCorrection(int textureId, int enabled) → void
Enables or disables lens distortion correction on the capture pipeline (Camera2 DISTORTION_CORRECTION_MODE, API 28+). No-op when the device doesn't support it. enabled: 1 = on (HIGH_QUALITY), 0 = off.
setExposure(int textureId, double value) → void
Sets exposure compensation. value is -1.0 (darkest) to 1.0 (brightest).
setFilterShader(int textureId, String shaderSource) → void
Updates the GPU-accelerated filter shader on the camera preview. Pass a valid GLSL Fragment Shader source. The shader should expect:
setFlash(int textureId, int mode) → void
Sets the flash mode for photo capture. Pass a FlashMode value.
setFocusDistance(int textureId, double distance) → void
Manual focus distance: distance 0.0 (far / infinity) → 1.0 (nearest), or a negative value to restore continuous auto-focus. Fixed-focus lenses and devices without custom-lens-position support ignore it.
setFocusPoint(int textureId, double x, double y) → void
Locks focus at the normalised point (x, y) where (0,0) is top-left.
setFrameFormat(int textureId, int format) → void
Sets the pixel format for the frameStream. format: 0 = YUV_420_888 (Planar), 1 = BGRA_8888 (Interleaved RGB).
setHdr(int textureId, int enabled) → void
Enables or disables HDR capture. enabled: 1 = on.
setKeepScreenOn(int enabled) → void
Keeps the screen awake while the camera UI is up — Android sets FLAG_KEEP_SCREEN_ON on the activity window, iOS sets isIdleTimerDisabled. enabled: 1 = on, 0 = off. (An FFI spec method, so no extra plugin / method channel is needed.)
setLowLightBoost(int textureId, int enabled) → void
Enables or disables low-light boost (night mode). enabled: 1 = on.
setManualExposure(int textureId, double iso, double exposureNanos) → void
Manual exposure: fixes ISO (iso, e.g. 100..3200) and shutter time (exposureNanos, in nanoseconds, e.g. 1/50s = 20_000_000). Both are clamped to the device's supported range. Pass iso <= 0 to restore automatic exposure (and re-enable exposure-compensation bias).
setMultiCamEnabled(int enabled) → void
1 = cameras opened from now on run SIMULTANEOUSLY in one shared iOS AVCaptureMultiCamSession (vision-camera's requiresMultiCam); 0 = each camera gets its own session again (iOS then runs one at a time). Affects sessions opened afterwards. Android runs concurrent cameras natively, so this is a no-op there.
setNativeBuffers(int textureId, int enabled) → void
Attaches the native buffer to frames (CameraFrame.nativeBuffer) — vision-camera's frame.getNativeBuffer(), for handing the camera's own buffer to GPU / ML code without a copy. One buffer is held at a time, so the camera pool never starves. Throws NATIVE_BUFFER_UNSUPPORTED: below Android 9. enabled: 1 = on, 0 = off (releases a held buffer).
setNativeDetector(int textureId, String detector) → void
Runs a NATIVE detector on the session's frames, emitting CameraEventType.detection events with a JSON payload per hit. detector: a registered detector name, or "" to stop. The built-ins are "barcode" / "face" (ML Kit on Android — the host app adds the artifact; the built-in Vision framework on iOS). Host apps register their own native detector plugins by name via NitraDetectors.register(...) (Kotlin/Swift) and select them here. An unknown name emits a descriptive error event.
setResizer(int textureId, ResizerOptions options) → Future<void>
Starts / stops / reconfigures the GPU resizer that streams ML-ready tensors of every frame on resizedStream (vision-camera-resizer).
setSamplingRate(int textureId, int samplingRate) → void
Configures how many frames to skip before delivering to frameStream. samplingRate: 1 = every frame, 2 = every 2nd frame, etc.
setSynchronizedOutput(int textureId, int enabled) → Future<void>
Pairs each video frame with the depth map captured with it and streams the pairs on syncedStream (vision-camera's CameraOutputSynchronizer). Turns depth output on as needed; throws DEPTH_UNSUPPORTED: like setDepthOutput. enabled: 1 = on, 0 = off.
setTargetOrientation(int textureId, int degrees) → void
Sets the target output orientation in degrees (0 / 90 / 180 / 270).
setTorch(int textureId, int enabled) → void
Enables or disables the torch (continuous flashlight). enabled: 1 = on.
setTorchLevel(int textureId, double level) → void
Sets the torch brightness in 0.0..1.0 (1.0 = max). Values > 0 imply torch on.
setVideoStabilization(int textureId, int mode) → void
Sets the video stabilization mode. Pass a VideoStabilizationMode value.
setWhiteBalance(int textureId, int temperature) → void
Sets the white-balance colour temperature in Kelvin. Pass 0 to restore automatic white balance.
setZoom(int textureId, double zoom) → void
Sets the zoom level. Must be within CameraDevice.minZoom .. CameraDevice.maxZoom.
startEncodedOutput(int textureId, int width, int height, int bitRate) → void
Attaches a hardware H.264 encoder (MediaCodec / VideoToolbox) to the session through the native NitroCameraOutputs hook — the path an RTMP / WebRTC publisher plugin takes. Upright, un-mirrored on Android, camera timestamps; the preview keeps running (Android moves a direct preview onto the GL renderer). width/height apply on Android; iOS encodes at the session's frame size. Replaces a running encoder output.
startHighSpeedRecording(int textureId, String path, int fps) → Future<int>
Starts a high-frame-rate (slow-mo) recording at fps (e.g. 120 / 240) to path. Uses a dedicated high-speed capture session (Android) / high-fps format (iOS), separate from the normal preview session. Returns 1 on success, 0 when the device advertises no high-speed config for fps. Photo capture and frame processing are unavailable while active.
startPreview(int textureId) → void
Resumes the camera preview after stopPreview.
startVideoRecording(int textureId, String outputPath, RecordingOptions options) → Future<void>
stopEncodedOutput(int textureId) → void
Detaches and releases the encoder output. No-op when none is running.
stopHighSpeedRecording(int textureId) → Future<RecordingResult>
Stops a high-speed recording started with startHighSpeedRecording and restores the normal preview session. Returns the recorded file metadata.
stopPreview(int textureId) → void
Pauses the camera preview without closing the session.
stopVideoRecording(int textureId) → Future<RecordingResult>
takePhoto(int textureId) → Future<PhotoResult>
takePhotoWithOptions(int textureId, PhotoOptions options) → Future<PhotoResult>
Captures a photo using explicit options (flash, quality, shutter sound).
takeSnapshot(int textureId) → Future<PhotoResult>
Captures the current preview frame as a fast JPEG snapshot (no full still-capture round-trip).
toString() → String
A string representation of this object.
inherited
updateOverlay(int textureId, Uint8List overlayData) → void
Draws a persistent shape or text vector onto the camera overlay. Renders directly on the GPU using the custom pipeline. overlayData is a serialized binary Buffer of draw commands.

Operators

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

Static Properties

instance → NitroCamera
final