nitro_camera library

nitro_camera — a high-performance, vision-camera-style Flutter camera plugin built on the Nitro FFI bridge.

Layered architecture (see lib/src/):

  • nitro_camera.native.dart + generated/ — the FFI/native boundary (nitro spec + generated Kotlin/Swift/C++ bridges; do not move — the native build systems reference these paths).
  • models/ — pure data types (devices, formats, resolved config, session state, events).
  • configuration/ — declarative config + constraint-based format negotiation.
  • controller/ — the imperative + declarative session controller.
  • processing/ — isolate-based frame processing.
  • widgets/ — declarative CameraView + CameraPreview.

Classes

AnyResolution
AutoFocusConstraint
Prefer a format whose auto-focus system matches system.
CameraConfiguration
Immutable, declarative description of a desired camera session state.
CameraConfigurationDiff
The set of fields that changed between two CameraConfigurations.
CameraConstraint
A single prioritised capture constraint.
CameraController
High-level controller that mirrors the vision_camera API surface.
CameraDeviceFormat
A capture format available on a CameraDeviceInfo.
CameraDeviceInfo
Vision-camera-compatible camera device info, parsed from the native JSON.
CameraDevicesObserver
Watches camera hot-plug events (e.g. USB cameras) and re-enumerates the device list — the analogue of vision-camera's addOnCameraDevicesChangedListener / useCameraDevices.
CameraEvent
A lifecycle / error event emitted by a camera session on NitroCamera.eventStream.
CameraFrame
A raw camera frame emitted by the frame-processing stream. pixels is a zero-copy view into the native camera buffer (BGRA / RGBA). Process the frame synchronously inside the stream listener; do NOT hold a reference past that point.
CameraFrameProcessor<R>
Runs a FrameHandler on a dedicated background Isolate, keeping heavy per-frame work off the UI isolate.
CameraOverlay
Shapes and text drawn INTO the camera output — the preview and recorded video show them, burned in — the role vision-camera's Skia frame processors play for overlays (bounding boxes, labels, guides).
CameraPreview
Renders the live camera preview using Flutter's GPU-accelerated Texture widget or a native Platform View.
CameraSessionEvent
A typed camera lifecycle / error / interruption event, parsed from the FFI CameraEvent record delivered on NitroCamera.eventStream.
CameraView
Declarative camera widget — the Flutter analogue of vision-camera's <Camera>.
ClosestResolution
CodeResult
A decoded code.
CodeScanner
Scans camera frames for barcodes / QR codes of a selectable kind.
ConcurrentCameraSet
A set of cameras that can stream SIMULTANEOUSLY (multi-cam — Android API 30+ concurrent cameras / iOS AVCaptureMultiCamSession). Produced from the raw ID combinations by CameraController.resolveConcurrentSets / CameraController.getConcurrentCameraSets, so an app can select a pairing (e.g. back + front) by device rather than cross-referencing ID strings.
DepthFrame
One depth map from NitroCamera.depthStream: data holds height rows of width little-endian float32 distances in METRES (bytesPerRow apart; 0 / NaN = no measurement). Zero-copy: read it inside the listener only.
DetectedBarcode
A detected barcode/QR (native ML Kit barcode detector).
DetectedFace
A detected face (native ML Kit face detector).
DetectionBounds
An axis-aligned bounding box in frame pixel coordinates (origin top-left of the detector's input frame, before display rotation/mirror). Use normalized against the frame size for a resolution-independent box.
DetectionResult
One frame's worth of native-detector results.
EncodedOutputStats
Counters of a hardware H.264 encoder output — see NitroCamera.startEncodedOutput. Timestamps are the camera's, in µs.
FormatResolver
Negotiates a concrete CameraDeviceFormat from a device's available formats and a prioritised list of CameraConstraints.
FormatStats
Aggregate statistics across the candidate formats, used to normalise resolution penalties (so max/min can be scored relative to the field).
FpsConstraint
Prefer a format supporting fps. Penalty grows with distance from the format's [minFps, maxFps] range.
FrameData
A camera frame handed to a CameraFrameProcessor handler. The bytes are a copy owned by the worker isolate (the native zero-copy view cannot cross an isolate boundary), so the handler may keep or transform them freely.
FrameProcessorPlugin
A per-frame processor instantiated ON THE WORKER ISOLATE with the options passed to FrameProcessorPlugins.init. Mirrors vision-camera's FrameProcessorPlugin (Android FrameProcessorPlugin(options) / callback(frame, params)).
FrameProcessorPluginRunner
A running (or startable) instance of a named plugin: a persistent worker isolate executing the plugin on every frame, with drop-latest backpressure and zero-copy frame hand-off (see CameraFrameProcessor).
FrameProcessorPlugins
Global name → factory registry (main isolate). The static API mirrors vision-camera's FrameProcessorPluginRegistry.addFrameProcessorPlugin / initFrameProcessorPlugin.
FrameProcessStats
Per-frame processing statistics, emitted for EVERY processed frame (successful or not) — the basis for scan benchmarking UIs.
MaxResolution
MinResolution
OrientationManager
Streams the physical device orientation (0/90/180/270, sensor-derived) and optionally drives a CameraController's target output orientation.
PhotoCaptureOptions
Type-safe options for a single photo capture (CameraController.takePhoto).
PhotoHdrConstraint
Require photo-HDR support (penalty 1 if the format can't do it).
PhotoResult
Result returned after a photo is captured.
PinchToZoomDetector
A pinch-to-zoom wrapper that drives controller.setZoom.
PreviewTransform
How the Flutter Texture must be framed. In direct mode (Android, texture preview, nothing needing the GL renderer) the camera writes raw sensor- orientation buffers straight into the texture, so Dart rotates, mirrors and crops them; otherwise the native side already did (identity transform). Returned by NitroCamera.getPreviewTransform.
RawDecode
A raw engine decode: text + symbology (no frame metadata yet).
RecordingOptions
Per-recording options for NitroCamera.startVideoRecording.
RecordingResult
Result returned after a video recording is stopped.
ResizedFrame
A camera frame scaled on the GPU into an ML-ready tensor, from NitroCamera.resizedStream (vision-camera-resizer): data holds height rows of width interleaved pixels of channels values each — uint8 (0..255) or float32 (0..1, little-endian) per dataType. Upright, un-mirrored. Zero-copy: read it inside the listener only.
ResizerOptions
GPU resizer settings for NitroCamera.setResizer.
ResolutionConstraint
Prefer a resolution according to target for the given stream.
ResolvedCameraConfig
The concrete configuration that negotiation actually selected.
ScanCodesPlugin
Scans frames for codes of the kind named by options['kind'] (a CodeScanKind name, default 'all'). Emits a map per hit: {text, format, isGs1, points}.
ScanConfirmer
Confirms detections across consecutive frames and de-duplicates emissions — pure logic, unit-testable without a camera.
SessionState
A typed snapshot of the live native camera session — the parsed form of NitroCamera.getSessionStateJson. Prefer this over hand-parsing JSON.
SyncedFrame
One video frame and the depth map captured WITH it, from NitroCamera.syncedStream (vision-camera's CameraOutputSynchronizer): pixels is laid out like CameraFrame.pixels, depth like DepthFrame.data (float32 metres). Both are zero-copy borrows — read them inside the listener only.
TapToFocusDetector
A GestureDetector wrapper that translates tap positions to normalised camera coordinates (0.0–1.0) and focuses there.
TargetResolution
How to negotiate capture resolution against a device's available formats.
VideoHdrConstraint
Require video-HDR support (penalty 1 if the format can't do it).
VideoStabilizationConstraint
Prefer a format that supports the given video-stabilization mode. Penalty 1 if unsupported.

Enums

AutoFocusMode
Auto-focus behaviour.
AutoFocusSystem
The auto-focus system of a capture format.
CameraEventType
Kind of CameraEvent delivered on NitroCamera.eventStream.
CameraExtension
Vendor camera extensions (Android CameraExtensionCharacteristics, API 31+; always absent on iOS). Turn one on with CameraController.setExtension.
CameraLensType
The optical lens type of the camera.
CameraPosition
Which physical side of the device the camera faces.
CodeFormat
Barcode / code symbologies the scanner can detect.
CodeScanKind
Which family of codes to look for in a frame.
ColorRange
YCbCr value range of the frame stream (vision-camera's full / video range): full = 0..255, video = 16..235 luma / 16..240 chroma.
FlashMode
Flash / torch mode.
FocusAdaptiveness
What the lens does after CameraController.focusAt (vision-camera's focus(point, { adaptiveness })).
FrameDropReason
Why the pipeline dropped a frame — the typed form of a CameraEventType.frameDropped event's message (vision-camera's onFrameDropped reason).
HardwareLevel
Camera2 INFO_SUPPORTED_HARDWARE_LEVEL tiers (always full on iOS).
InterruptionReason
Why the camera session was interrupted (mirrors AVFoundation reasons).
NativeDetector
Which native ML detector to run. Wire values match the native side.
OutputOrientationMode
How captured output (photos/videos and the locked preview) should be oriented. Mirrors vision-camera's OrientationSource.
PermissionStatus
Camera permission status.
PhotoOutputFormat
The photo file container written by a capture.
PhysicalDeviceType
The physical lens types backing a (possibly logical) camera device. Wire values match vision-camera's PhysicalCameraDeviceType.
PixelFormat
The pixel format of the raw frame-processing stream.
PreviewMode
Defines how the camera preview is rendered.
PreviewResizeMode
How the preview fills its box (vision-camera's resizeMode).
QualityPrioritization
Photo capture speed-vs-quality tradeoff.
RecordingFinishedReason
Why a video recording finished.
ResizeFit
How a frame is fitted into the tensor size.
ScanMode
How a CodeScanner delivers results.
StreamType
Which capture stream a resolution constraint targets.
TensorDataType
Value type of a GPU-resizer tensor.
TensorLayout
Channel layout of a GPU-resizer tensor (CameraController.startResizer).
ThermalState
Device thermal pressure — the normalized form of a CameraEventType.thermalStateChanged event's level. Apps should shed load (lower fps / resolution, stop HDR) as this climbs. Mirrors iOS ProcessInfo.ThermalState; Android PowerManager thermal statuses are mapped onto the same four levels.
VideoCodec
Video compression codec for recording.
VideoFileType
Container/file type for recorded video.
VideoStabilizationMode
Video stabilization mode applied to the capture pipeline.

Extensions

CameraDeviceSelection on List<CameraDeviceInfo>
Fluent selection sugar over a device list.
DepthFrameMetres on DepthFrame
Typed view of a DepthFrame's float32 metres.
FormatNegotiation on CameraDeviceInfo
Convenience negotiation helpers on a device, mirroring vision-camera's getCameraFormat(device, constraints).
FrameResize on FrameData
CPU frame resizing for a FrameData — the vision-camera-resizer analogue.
PhotoResultFormat on PhotoResult
The container and RAW-ness of a captured PhotoResult — vision-camera's PhotoFile.containerFormat / isRawPhoto (v5.2.4 #4170). Read from the file both platforms write: .dng for RAW captures, .jpg otherwise.
RecordingResultMetadata on RecordingResult
ResizedFrameTensor on ResizedFrame
Typed views of a ResizedFrame tensor.
SyncedFrameMetres on SyncedFrame
Typed view of a SyncedFrame's depth map (float32 metres, like DepthFrameMetres).

Constants

kScannerWindowFraction → const double
Fraction of the frame's short side scanned by the streaming CodeScanner — matches the centered viewfinder window in the UI. Cropping before decoding is the main speed lever: the binarizer + readers touch ~half the pixels, and the user aims the code inside the window anyway. The center square is rotation- and cover-crop-invariant, so no orientation math is needed to map the UI window into the frame.

Functions

createScanCodesPlugin(Map<String, Object?> options) → FrameProcessorPlugin
Factory for ScanCodesPlugin (top-level, isolate-sendable).
decodeCodeFrame(FrameData f, CodeScanKind kind, {double windowCropFraction = 1.0}) → CodeResult?
Decodes one frame's luma plane, looking only for kind's formats.
mapDecodedPointsToWindow(List<double> points, int w, int h, bool rotated, {int frameOrientation = 0, bool mirrored = false}) → List<double>
Maps points from decoded-bitmap pixel space back to the scan window's normalized (0..1) space as displayed — ready to paint over the on-screen viewfinder.
nativeBufferReleaser(int handle) → void
The default BufferReleaser: NitroCamera.releaseNativeBuffer.
nativeFrameSource() → Stream<CameraFrame>
The default FrameSource: the native frame stream, opened by the worker's own NitroCamera handle (same native object as the UI isolate's).
registerBuiltInFrameProcessorPlugins() → void
Registers all plugins shipped with nitro_camera (currently scanCodes). Call once, e.g. from main().
scanFrameAdaptive(FrameData f, CodeScanKind kind, {Set<CodeFormat>? formats}) → CodeResult?
Streaming decode with the adaptive ladder + last-hit cache. Used by the CodeScanner worker handlers; call decodeCodeFrame for stateless one-shot decodes. formats narrows kind's set, e.g. to the formats a custom handler's own engine doesn't cover.
scannerWindowOf(FrameData f) → ({int left, int side, int top})
The streaming scan window (the viewfinder square, full-frame pixels) for f, as configured by scannerWorkerInit. Custom CodeScanner.handlers crop to it and map their points into it with mapDecodedPointsToWindow.
scannerWorkerInit(Object? arg) → void
Worker bootstrap: applies the ROI fraction sent as the frame processor's workerInitArg. Top-level so it is isolate-sendable.
selectCameraDevice(List<CameraDeviceInfo> devices, {CameraPosition? position, List<PhysicalDeviceType>? physicalDevices}) → CameraDeviceInfo?
Picks the best CameraDeviceInfo from devices, mirroring vision-camera's getCameraDevice ranking:

Typedefs

BufferReleaser = void Function(int handle)
Returns a CameraFrame.nativeBuffer to the camera. Runs on whichever isolate saw the frame, so it must be top-level/static.
FrameHandler<R> = R Function(FrameData frame)
A frame-processing function. It runs on a background isolate, so it must be a top-level or static function (a closure capturing state cannot be sent to an isolate). Its return type R must be sendable across isolates (primitives, List/Map of sendables, TransferableTypedData, etc.).
FrameProcessorPluginFactory = FrameProcessorPlugin Function(Map<String, Object?> options)
Creates a FrameProcessorPlugin from init options. Must be a top-level or static function — it crosses the isolate boundary.
FrameSource = Stream<CameraFrame> Function()
Where a worker attached with CameraFrameProcessor.attachDirect reads frames from. Runs on the worker isolate, so it must be top-level/static.
WorkerInitializer = void Function(Object? initArg)
Runs ONCE on the worker isolate before any frame is handled — the hook for setting up worker-side state (e.g. instantiating a frame-processor plugin into an isolate global). Must be a top-level or static function; initArg must be sendable.

Exceptions / Errors

CameraException
Base type for every error surfaced by nitro_camera.
CaptureException
A photo capture failed.
DeviceException
The camera device could not be opened or disappeared.
PermissionException
Camera / microphone permission is missing or was denied.
RecorderException
A video recording failed.
SessionException
The session is in the wrong state for the requested operation, or native session configuration failed.