native library
Native build of package:flutter_litert.
This barrel resolves the whole API against the native (dart:ffi)
implementation unconditionally. The portable flutter_litert.dart barrel
resolves to the WASM-safe web surface by default (so the package stays
WASM-compatible), which means symbols whose signatures use native-only types
(Isolate, SendPort, File, the native Interpreter, ...) cannot be
reached through it during static analysis.
Import this from code that only runs on native platforms (Android, iOS,
macOS, Windows, Linux) and needs that API, e.g. IsolateWorkerBase,
IsolateRpcClient, InterpreterPool, ModelCheckpoint, or
TensorFloat32Views. Do not import it together with flutter_litert.dart
in the same library: both define Interpreter and friends, which would be
an ambiguous import.
Classes
- AsyncLock
- A lightweight sequential async lock that serializes tasks through a future chain, preventing concurrent access to shared mutable state that is not thread-safe (e.g. a CompiledModel slot or interpreter input/output buffers).
- BoundingBox
- An axis-aligned or rotated bounding box defined by four corner points.
- ByteConversionUtils
- Utilities for converting between Dart objects and raw tensor byte buffers.
- CameraFrame
- A camera frame packaged for off-thread colour conversion and inference.
- CameraFrameDecodePlan
- Backend-neutral instructions for decoding a CameraFrame.
- CompiledModel
- LiteRT Next CompiledModel inference API.
- CompiledModelPool
- A round-robin pool of CompiledModel instances for the LiteRT Next engine.
- CoreMlDelegate
- CoreMl Delegate
- CoreMlDelegateOptions
- CoreMlDelegate Options
- CoverFitTransform
- A precomputed cover-fit mapping from source-image pixel coordinates to viewport coordinates, with optional horizontal mirroring for a front-camera preview.
- Delegate
- Abstract base class for LiteRT hardware delegates.
- Detection
- A single object detection result from a detection model.
- FlexDelegate
-
Flex delegate for running models that use
SELECT_TF_OPS. - FpsCounter
- A simple 1-second rolling FPS counter for camera-preview apps.
- FrameThrottle
- A single-slot gate for camera-frame processing that drops frames arriving while a previous frame is still being processed.
- GpuDelegate
- Metal Delegate for iOS and macOS
- GpuDelegateOptions
- Metal Delegate options
- GpuDelegateOptionsV2
- GPU delegate options for Android
- GpuDelegateV2
- GPU delegate for Android
- Interpreter
- LiteRT interpreter for running inference on a model.
- InterpreterFactory
- Factory for creating interpreter options with the package's platform delegate mapping.
- InterpreterOptions
- LiteRT interpreter options.
- InterpreterPool
- A round-robin pool of Interpreter instances with per-slot serialization locks.
- IsolateInterpreter
- Allows running LiteRT inference in a separate isolate.
- IsolateRpcClient
- RPC client that sends requests to and receives responses from an isolate.
- IsolateWorkerBase
- Base class for isolate-backed worker objects.
- LetterboxParams
- Parameters for aspect-preserving resize with centered padding.
- ModelCheckpoint
- Dart-side weight persistence for on-device training models.
- OneEuroFilter
- One Euro filter for low-latency smoothing of a noisy 1D signal sampled at an irregular rate.
- PackedImageLayout
- A tightly packed source-buffer layout for image backend reconstruction.
- PackedYuv
- A contiguous YUV buffer produced by packYuv420, ready to hand to a native colour-conversion routine.
- PerformanceConfig
- Configuration for interpreter hardware acceleration and threading.
- Point
- A point with x, y, and optional z coordinates.
- QuantizationParams
- Quantization parameters for a tensor.
-
RoundRobinPool<
T> - A generic round-robin pool with per-slot future-chain serialization locks.
- SignatureRunner
- A runner for a specific model signature, enabling named tensor access.
- SSDAnchorOptions
- SSD anchor configuration options for SSD-style detection models.
- Tensor
- LiteRT tensor.
- TensorFloat32Views
- Cached Float32List views of an Interpreter's input and output tensors.
- TFLGpuDelegateWaitType
- TfLiteCoreMlDelegateEnabledDevices
- TfLiteGpuExperimentalFlags
- Used to toggle experimental flags used in the delegate. Note that this is a bitmask, so the values should be 1, 2, 4, 8, ...etc.
- TfLiteGpuInferencePriority
- TfLiteGpuInferenceUsage
- Encapsulated compilation/runtime tradeoffs.
- TfLiteType
- Types supported by tensor LINT.IfChange
- TransposeConvBiasOp
- Loads and provides access to the Convolution2DTransposeBias custom op.
- XNNPackDelegate
- XNNPack Delegate
- XNNPackDelegateOptions
- XNNPackDelegate Options
Enums
- Accelerator
- Hardware accelerator requested for LiteRT Next compilation.
- CameraFrameConversion
-
The colour conversion a CameraFrame's bytes need before being used as a
3-channel BGR image. Detector packages map this to an opencv
COLOR_*code at the point of decode, inside their existing detection isolate. - CameraFrameDecodeOrder
- Operation ordering for a backend-specific CameraFrame decoder.
- CameraFrameRotation
-
Optional rotation applied after colour conversion. Detector packages map
this to an opencv
ROTATE_*code. - IsolateInterpreterState
- State of an IsolateInterpreter lifecycle.
- PackedImageFormat
- Backend-neutral packed image formats used by camera frame decode plans.
- PerformanceMode
- Hardware acceleration mode for LiteRT inference.
- Precision
- GPU precision mode for LiteRT Next compilation.
- TensorBufferMode
- Tensor buffer allocation mode for CompiledModel I/O.
- TensorType
- Data type of a LiteRT tensor.
- YuvLayout
- Memory layout of a packed YUV buffer produced by packYuv420.
Mixins
- LandmarkMixin
- Mixin providing normalized coordinate utilities for landmarks with x/y pixel coordinates.
Constants
- decodeFailurePrefix → const String
- Wire-prefix marking an isolate error as an undecodable-image failure, so the main side can map it to a FormatException. Paired with throwDecodeFailure (isolate side) and rethrowOrFormatException (main side).
- kInt32ByteSize → const int
- Size of int32 in bytes (avoids dart:ffi dependency for web compatibility).
Functions
-
allocTensorShape(
List< int> shape) → Object -
Allocates a nested list structure matching the given tensor
shape. -
argSortDesc(
List< double> a) → List<int> -
Returns indices that sort
ain descending order. -
barQuarterTurns(
DeviceOrientation orientation) → int -
Quarter-turns (clockwise) to rotate a top-bar widget so it reads upright
when the device is in landscape. Use with
RotatedBox(quarterTurns: ...). -
bgrBytesToRgbFloat32(
{required Uint8List bytes, required int totalPixels, Float32List? buffer}) → Float32List -
Converts BGR bytes to a flat Float32List with
0.0..1.0normalization. -
bgrBytesToSignedFloat32(
{required Uint8List bytes, required int totalPixels, Float32List? buffer}) → Float32List -
Converts BGR bytes to a flat Float32List with
-1.0..1.0normalization. -
cameraFrameFromRpcMessage(
Map message, Uint8List bytes) → CameraFrame -
Reconstructs a CameraFrame from an isolate-request
messagebuilt by cameraFrameRpcFields and the already-materializedbytes. -
cameraFrameRpcFields(
CameraFrame frame, [Map< String, dynamic> extra = const {}]) → Map<String, dynamic> -
Builds the isolate-request field map for a CameraFrame payload, merged with
any
extraper-op fields (e.g.maxDim,mode,outputFormat). -
clamp01(
double v) → double -
Clamps
vto the range0.0..1.0. Returns 0.0 for NaN inputs. -
clip(
double v, double lo, double hi) → double -
Clamps
vto the rangelo..hi. -
compiledFloatCount(
int byteSize, {String label = 'tensor'}) → int - Helpers for deriving tensor geometry from a CompiledModel.
-
compiledOutputFloatCounts(
CompiledModel model, {String label = 'model'}) → List< int> -
Float counts for every output tensor of
model, in order. -
compiledSquareInputSide(
CompiledModel model, {int channels = 3, String label = 'model'}) → int -
The square input side (e.g. 192 or 224) of a single-input
model, derived from its input byte size. -
computeLetterboxParams(
{required int srcWidth, required int srcHeight, required int targetWidth, required int targetHeight, bool roundDimensions = true}) → LetterboxParams -
Computes letterbox parameters for resizing
srcWidthxsrcHeightto fit withintargetWidthxtargetHeightwhile preserving aspect ratio. -
concat0(
List< List< parts) → List<List< >double> >List< double> > - Concatenates a list of 2D matrices along axis 0.
-
coverFitScaleOffset(
int sourceW, int sourceH, double viewW, double viewH) → ({double offsetX, double offsetY, double scale}) -
Cover-fit scale + offset for rendering a source region of size
(
sourceW,sourceH) into a viewport of size (viewW,viewH). -
createNHWCTensor4D(
int height, int width) → List< List< List< >List< >double> > -
Creates a pre-allocated
[1][height][width][3]tensor structure. -
createOutputBuffers(
List< List< shapes) → Map<int> >int, Object> -
Creates output buffers matching the given output tensor
shapes. -
decodeAndSplitOutputs(
List outputs) → List< Map< String, dynamic> > - Decodes raw detection model outputs and splits each row into xywh, rest, and C.
-
decodeDetectionOutputs(
List outputs) → List< List< double> > -
Decodes raw detection model outputs into a standardized 2D matrix.
Handles both
[1, numBoxes, 5 + classes]and[1, 5 + classes, numBoxes]formats. -
detectionSize(
{required int width, required int height, required CameraFrameRotation? rotation, required int maxDim}) → Size - Compute the final detection-image size used by overlay painters to map detector coordinates back onto the widget coord space.
-
drawBoundingBoxOutline(
{required Canvas canvas, required BoundingBox bbox, required double scaleX, required double scaleY, required double offsetX, required double offsetY, required Paint paint}) → void - Draw the axis-aligned outline of a BoundingBox transformed by a linear scale + offset. Use a stroked Paint for an outline, or a filled one to tint the interior.
-
drawLandmarkMarker(
Canvas canvas, double x, double y, {double glowRadius = 8, double pointRadius = 5, double centerRadius = 2, Paint? glowPaint, Paint? pointPaint, Paint? centerPaint}) → void -
Draw a standard "glow + point + center dot" triple-circle landmark marker
at (
x,y) in canvas coordinates. -
drawSkeletonConnections(
{required Canvas canvas, required List< Offset> scaledPoints, required List<(int, int)> connections, required Paint paint}) → void - Draw straight-line connections between pre-scaled landmark points.
-
ensure2D(
List raw) → List< List< double> > -
Ensures a dynamic list is a proper 2D
List<List<double>>. -
fillNHWC4D(
Float32List flat, List< List< cache, int inH, int inW) → voidList< >List< >double> > - Fills an NHWC 4D tensor cache from a flat Float32List.
-
fillNHWC4DFromBgrBytes(
{required Uint8List bytes, required List< List< tensor, required int width, required int height, double scale = 1.0 / 255.0, double offset = 0.0}) → voidList< >List< >double> > - Fills a 4D NHWC tensor in-place from raw BGR bytes with a BGR-to-RGB channel swap.
-
flattenDynamicTensor(
Object? out) → Float32List - Flattens an arbitrarily nested tensor to a flat Float32List.
-
float16ToFloat32(
int value) → double - Converts a float16 (as int) to float32.
-
float32ToFloat16(
double value) → int - Converts a float32 to float16 representation (as int).
-
generateAnchors(
SSDAnchorOptions options) → List< List< double> > - Generates SSD anchors based on the given options.
-
indexWhereFloatCount(
List< int> floatCounts, bool test(int floats)) → int -
Index of the first entry in
floatCountsfor whichtestreturns true, or-1if none match. -
initializeWeb(
{String? tfJsScriptUrl, List< String> ? tfBackendScriptUrls, String? tfliteScriptUrl}) → Future<void> - No-op on native platforms. TFLite uses FFI directly.
-
median(
List< double> a) → double - Returns the median of a non-empty list.
-
nms(
List< List< boxes, List<double> >double> scores, {double iouThres = 0.45, int maxDet = 100}) → List<int> - Non-Maximum Suppression over XYXY-format bounding boxes.
-
normalizeRadians(
double angle) → double -
Normalizes an angle in radians to the range
-pi..pi. -
packYuv420(
{required int width, required int height, required YuvPlane y, required YuvPlane u, YuvPlane? v, Uint8List? into}) → PackedYuv? -
Packs a YUV420 camera frame into a single contiguous buffer suitable for
native colour conversion (e.g. opencv's
cvtColorwith aCOLOR_YUV2BGR_NV21/COLOR_YUV2BGR_NV12/COLOR_YUV2BGR_I420code). -
postProcessDetections(
{required List outputs, required int inputWidth, required int inputHeight, required double r, required int dw, required int dh, required int imageWidth, required int imageHeight, required double confThres, required double iouThres, required int topkPreNms, required int maxDet, int? filterClassId}) → List< Detection> - Post-processes detection model outputs into Detection results.
-
postProcessDetectionsFlat(
Float32List out, {required int channels, required int anchors, required bool channelMajor, required int inputWidth, required int inputHeight, required double r, required int dw, required int dh, required int imageWidth, required int imageHeight, required double confThres, required double iouThres, required int maxDet, int? filterClassId, bool useFastSingleClass = false}) → List< Detection> -
Decodes a YOLOv8 detection head directly from the flat
outFloat32 buffer. -
prepareCameraFrame(
{required int width, required int height, required List< CameraPlane> planes, CameraFrameRotation? rotation, bool isBgra = true}) → CameraFrame? -
Prepare a CameraFrame descriptor from raw camera planes, for use with a
detector package's
detectFromCameraFrame(...)method. -
prepareCameraFrameFromImage(
Object cameraImage, {CameraFrameRotation? rotation, bool? isBgra}) → CameraFrame? -
Convenience wrapper around prepareCameraFrame that accepts any object
duck-typed to
package:camera'sCameraImage(i.e. exposingwidth,height, and aplanesiterable of objects withbytes,bytesPerRow, andbytesPerPixelgetters). -
rethrowOrFormatException(
Object error, [Uint8List? source]) → Never -
Main-side: if
erroris a decode-failure signal (a StateError whose message starts with decodeFailurePrefix, as produced by throwDecodeFailure in the isolate and re-wrapped byIsolateRpcClient), throw a FormatException carrying the detail and optionalsourcebytes; otherwise rethrowerrorunchanged. -
rgbaToRgbFloat32(
Uint8List rgbaData, Float32List output) → void - Converts RGBA pixel data to a normalized RGB Float32List tensor in-place.
-
rgbaToSignedRgbFloat32(
Uint8List rgbaData, Float32List output) → void - Converts RGBA pixel data to a signed RGB Float32List tensor in-place.
-
rotationForFrame(
{required int width, required int height, required int sensorOrientation, required bool isFrontCamera, required DeviceOrientation deviceOrientation}) → CameraFrameRotation? - Compute the rotation needed to present a camera frame upright to an on-device detection model, given the camera's sensor orientation and the device's current physical orientation.
-
scaleFromLetterbox(
List< double> xyxy, double ratio, int dw, int dh) → List<double> - Transforms bounding box coordinates from letterbox space back to original image space.
-
serveIsolateRpc(
{required Object mainSendPort, required Object receivePort, required Map< String, IsolateRpcHandler> handlers, String disposeOp = 'dispose', Future<void> onDispose()?}) → void -
Web stub: isolate RPC serving requires
dart:isolate, which is unavailable on web/WASM (detectors run on the main isolate). Present only so the symbol resolves on the web build; calling it throws. -
setupIsolateHandshake(
{required ReceivePort receivePort, required void onResponse(dynamic), required Duration timeout, required String timeoutMessage}) → Future< SendPort> - Performs the initial SendPort handshake with a newly spawned isolate.
-
sigmoid(
double x) → double - Sigmoid activation function.
-
sigmoidClipped(
double x, {double limit = 80.0}) → double - Sigmoid with input clipping to prevent overflow.
-
squareSideFromFloats(
int floats, {int channels = 3, String label = 'input'}) → int -
The side length
Sof a square[1, S, S, channels]tensor that holdsfloatsfloat32 values. -
throwDecodeFailure(
[String detail = 'Image bytes could not be decoded.']) → Never - Isolate-side: signal that image bytes could not be decoded.
-
transpose2D(
List< List< a) → List<double> >List< double> > - Transposes a 2D list (swaps rows and columns).
-
weightedNms(
List< List< boxes, List<double> >double> scores, {double iouThres = 0.45, int maxDet = 100}) → List<({List< double> box, int index, double score})> - Weighted Non-Maximum Suppression over XYXY-format bounding boxes.
-
xywhToXyxy(
List< double> xywh) → List<double> - Converts XYWH bounding box format to XYXY format.
-
zeroOutputBuffers(
Map< int, Object> outputs, List<List< shapes) → voidint> > - Zeros all values in pre-allocated output buffers.
Typedefs
- CameraPlane = ({Uint8List bytes, int pixelStride, int rowStride})
- A single camera frame plane exposed by a camera plugin.
-
InterpreterCreator
= Future<
Interpreter> Function(InterpreterOptions options, Delegate? delegate) - Factory function to create and configure an Interpreter for one pool slot.
-
IsolateRpcHandler
= Future<
Object?> Function(Map message) - Handler for a single RPC operation running inside the isolate.
- YuvPlane = ({Uint8List bytes, int pixelStride, int rowStride})
-
A single YUV plane exposed by a camera plugin, decoupled from any specific
Flutter plugin's type (e.g.
CameraImage.Plane).
Exceptions / Errors
- ByteConversionError
- Error thrown when an input value cannot be converted to the expected tensor type.
- IsolateRpcExactError
-
Thrown by an isolate RPC handler to send an EXACT error string to the
client, bypassing serveIsolateRpc's default
'$e\n$st'stringification.