flutter_native_ml 1.2.0
flutter_native_ml: ^1.2.0 copied to clipboard
Direct access to on-device ML accelerators (Apple Neural Engine / Core ML on iOS, LiteRT GPU delegate, NNAPI and XNNPACK on Android) for fast native inference.
1.2.0 #
Added #
- Zero-copy camera input.
model.startCamera()opens the device camera natively (CameraX on Android, AVFoundation on iOS), resizes every frame into the model's input on the model's own thread and streams only the results to Dart. Includes a live preview texture (NativeCameraPreview), lens and resolution selection,cover/fill/containresizing, mean / std normalisation presets, frame-rate throttling, pause / resume and automatic stale-frame dropping. FlutterNativeML.checkCameraPermission()/requestCameraPermission().InferenceResult.framewith the source frame size, rotation and timestamp.DeviceCapabilities.raw['cameraAvailable'].
Changed #
- Android
minSdkis now 23 (required by CameraX 1.5); the plugin declares theCAMERApermission, which apps that never use the camera can strip withtools:node="remove". - iOS apps using the camera must declare
NSCameraUsageDescription; the plugin reportsMISSING_USAGE_DESCRIPTIONinstead of crashing when it is absent.
1.1.0 #
Fixed #
- Android did not compile. The Kotlin plugin imported
com.google.ai.edge.litert.*classes that no Maven artifact provides. The plugin now depends on LiteRT (com.google.ai.edge.litert:litert/litert-gpu) and uses itsorg.tensorflow.liteInterpreter API. - Android returned the tensor type under
dtypewhile Dart expecteddataType, which crashedgetSignature(). - Android ran model loading and inference on the UI thread.
- Inference with the GPU delegate now always happens on the thread that created the delegate (a LiteRT requirement); every model has its own worker thread.
- iOS mutated shared state from a concurrent queue and returned some results off the main thread.
- iOS ignored the model's declared input shape and always built 1-D arrays.
- iOS/Android accepted only
List<double>inputs; integer lists, typed lists and mixednumlists now work. startStream/stopStreamwere not implemented on Android and only emitted timestamps on iOS.dart run flutter_native_ml:ml_builderdid not work (the CLI lived in a separate package). It now ships asbin/ml_builder.dart.- Manifest
packageattribute removed (deprecated with AGP 8).
Added #
ComputeUnit.cpuAndGpuandComputeUnit.cpuAndNeuralEngine(NNAPI on Android), with automatic CPU fallback. The compute unit actually used is reported inNativeMLModel.acceleratorUsedandInferenceResult.acceleratorUsed.loadModel(filePath: ...)for models stored on the device,numThreadsandallowFp16options.- iOS:
.mlmodel/.mlpackageassets are compiled on device and cached, so a single-file asset is enough (compiled.mlmodelcbundles are directories that Flutter does not bundle as one asset). - iOS: image inputs/outputs (
ImageInput, raw or PNG/JPEG), string, int64, double, dictionary and sequence features; float16 arrays. - Android: all LiteRT tensor types (float32, int8/uint8/int16/int32/int64,
bool, string), quantization parameters in the signature, SignatureDef
aliases, dynamic shapes via
TensorData(data, shape: [...]), native inference timing. - Streaming API:
model.startStream(),model.pushStreamInput(),model.stopStream()with a bounded native queue that drops stale frames. FlutterNativeML.getDeviceCapabilities(),getPlatformVersion(),disposeAll().NativeMLExceptionwith stable error codes instead of rawPlatformExceptions.- Typed-list outputs (
Float32List,Int32List, ...) plusInferenceResult.doubles(),ints(),argmax()andoutputShapes. - Swift Package Manager support alongside CocoaPods; privacy manifest bundled.
- Kotlin DSL build script compatible with Flutter's built-in Kotlin support.
Changed #
- Minimum iOS version is 13.0; Android plugin targets Java 17 (as Flutter requires).
ModelSignature/TensorInfogainedtype,elementCount,hasDynamicShape,isOptional, quantization fields andmetadata.- The static
FlutterNativeML.startStream/stopStreamhelpers are deprecated in favour of theNativeMLModelmethods.
1.0.1 #
- Fixed bugs on android.
1.0.0 #
- Initial release.