flutter_litert_flex
FlexDelegate (SELECT_TF_OPS) addon for flutter_litert. Automatically downloads and bundles the TensorFlow Lite Flex delegate native library at build time for all platforms.
When do you need this?
The Flex delegate is required when your .tflite model uses TensorFlow ops that aren't available as TFLite builtins. Common cases:
- On-device training with convolutional or batch-normalized layers (gradient ops like
Conv2DBackpropFilter) - Checkpoint-based persistence using
tf.raw_ops.Save/Restore - Models converted with
SELECT_TF_OPSenabled
If your model only uses TFLITE_BUILTINS, you don't need this package.
Installation
dependencies:
flutter_litert: ^2.6.0
flutter_litert_flex: ^1.1.0
That's it. The native libraries are downloaded automatically on the first build.
iOS + Swift Package Manager:
flutter_litert_flexmust be used alongsideflutter_litert— the FlexDelegate links against core TFLite symbols thatflutter_litertprovides. Likeflutter_litert, its xcframework shipsarm64device +arm64simulator slices, so iOS simulator builds require an Apple Silicon Mac; the x86_64 (Intel) simulator is not supported under SPM. CocoaPods builds are unaffected.
Usage
import 'package:flutter_litert/flutter_litert.dart';
final options = InterpreterOptions();
options.addDelegate(FlexDelegate());
final interpreter = await Interpreter.fromAsset('model.tflite', options: options);
No FlexDelegate.download() call needed when using this package.
Platform details
| Platform | Library | Size | Mechanism |
|---|---|---|---|
| iOS | TensorFlowLiteFlex.xcframework |
~492 MB | CocoaPods or SPM (static framework) |
| macOS | libtensorflowlite_flex-mac.dylib |
~123 MB | CocoaPods or SPM (bundled resource) |
| Linux | libtensorflowlite_flex-linux.so |
~333 MB | CMake download |
| Windows | libtensorflowlite_flex-win.dll |
~227 MB | CMake download |
| Android | tensorflow-lite-select-tf-ops |
auto | Maven dependency |
Libraries are downloaded once and cached in the plugin directory. Subsequent builds use the cached copy.
Credits
Based on TensorFlow Lite v2.20.0. See flutter_litert for the base inference library.
Libraries
- flutter_litert_flex
- FlexDelegate (SELECT_TF_OPS) addon for flutter_litert.