isAvailable property

bool get isAvailable

Whether the Flex delegate library is available.

Returns true if the library can be loaded, i.e., flutter_litert_flex is in the project's dependencies.

Implementation

static bool get isAvailable {
  if (_flexLib != null) return true;

  if (Platform.isAndroid) {
    try {
      DynamicLibrary.open('libtensorflowlite_flex_jni.so');
      return true;
    } catch (_) {
      return false;
    }
  }

  // iOS: statically linked at build time by flutter_litert_flex podspec.
  if (Platform.isIOS) {
    try {
      DynamicLibrary.process().lookup<NativeFunction<Void Function()>>(
        'tflite_plugin_create_delegate',
      );
      return true;
    } catch (_) {
      return false;
    }
  }

  // Desktop: check app bundle paths (bundled by flutter_litert_flex).
  return _bundlePaths.any((p) => File(p).existsSync());
}