onnxruntime_plus 1.4.3
onnxruntime_plus: ^1.4.3 copied to clipboard
Flutter FFI plugin for ONNX Runtime with iOS Swift Package Manager support and cross-platform Dart bindings.

onnxruntime_plus #
Fork Status #
This package is a fork of the original onnxruntime Flutter plugin.
It is kept mainly to ship Apple packaging fixes, especially iOS Swift Package Manager support,
and related compatibility updates that are not available in the older package.
Maintenance is best-effort and focused on keeping the package usable for current projects, not on broad feature development.
Overview #
Flutter plugin for ONNX Runtime via dart:ffi with iOS Swift Package Manager support and cross-platform Dart bindings.
| Platform | Android | iOS | Linux | macOS | Windows |
|---|---|---|---|---|---|
| Compatibility | API level 21+ | * | * | * | * |
| Architecture | arm32/arm64 | * | * | * | * |
Key Features #
- Multi-platform Support for Android, iOS, Linux, macOS, Windows, and Web(Coming soon).
- Flexibility to use any Onnx Model.
- Acceleration using multi-threading.
- Similar structure as OnnxRuntime Java and C# API.
- Inference speed is not slower than native Android/iOS Apps built using the Java/Objective-C API.
- Run inference in different isolates to prevent jank in UI thread.
Getting Started #
In your flutter project add the dependency:
dependencies:
...
onnxruntime_plus: x.y.z
Usage example #
Import #
import 'package:onnxruntime_plus/onnxruntime_plus.dart';
Initializing environment #
OrtEnv.instance.init();
Creating the Session #
final sessionOptions = OrtSessionOptions();
const assetFileName = 'assets/models/test.onnx';
final rawAssetFile = await rootBundle.load(assetFileName);
final bytes = rawAssetFile.buffer.asUint8List();
final session = OrtSession.fromBuffer(bytes, sessionOptions!);
Performing inference #
final shape = [1, 2, 3];
final inputOrt = OrtValueTensor.createTensorWithDataList(data, shape);
final inputs = {'input': inputOrt};
final runOptions = OrtRunOptions();
final outputs = await _session?.runAsync(runOptions, inputs);
inputOrt.release();
runOptions.release();
outputs?.forEach((element) {
element?.release();
});
Releasing environment #
OrtEnv.instance.release();
Apple packaging #
For iOS, this package supports both CocoaPods fallback and Swift Package Manager integration. The Swift package uses the official ONNX Runtime iOS binary archive published by Microsoft. This fork also keeps Apple package metadata in sync for newer Flutter package-manager expectations.