Flutter integration for tract: cross-platform neural network
inference with no system dependencies for users or devs to install.
This package builds the shared tract_ffi Rust crate automatically (via
cargokit) and bundles it with your app,
then re-exports the full tract API.
import 'package:tract_flutter/tract_flutter.dart';
await TractFlutter.ensureInitialized();
final model = await TractFlutter.loadOnnxAsset('assets/mobilenet.onnx',
inputShape: [1, 3, 224, 224]);
final outputs = model.run([Tensor.float32(pixels, [1, 3, 224, 224])]);
model.dispose();The native crate wraps the Rust tract engine,
which is pure Rust, so it cross-compiles to Android, iOS, macOS, Windows and
Linux without extra toolchains. Web is not supported (no dart:ffi).
Building requires Rust (rustup). To remove even that for consumers, the repo
is set up for cargokit precompiled binaries:
native/tract_ffi/cargokit.yamlholds the public signing key and the release URL prefix..github/workflows/precompile.ymlbuilds and uploads signed binaries toprecompiled_<crate-hash>releases on tag pushes. It needs aCARGOKIT_PRIVATE_KEYrepository secret: the hex private key printed bydart run build_tool gen-key(keep it secret; never commit it).
Once a release exists, consuming builds download the matching signed binary instead of invoking cargo; with none present, cargokit builds from source.