Melange
API ReferenceFlutter

ZeticMLangeModel

Complete API reference for the ZeticMLangeModel class in Flutter.

This page reflects zetic_mlange 1.8.1.

ZeticMLangeModel is the primary Dart interface for running general on-device AI models through the native Android and iOS SDKs. It handles service-managed model download, native runtime initialization, execution, and native-handle release through a single Dart API.

Import

import 'package:zetic_mlange/zetic_mlange.dart';

Constructors

create

Creates a model from the Melange service using a personal key and model name.

static Future<ZeticMLangeModel> create({
  required String personalKey,
  required String name,
  int? version,
  ModelMode modelMode = ModelMode.runAuto,
  QuantType? quantType,
  Target? target,
  APType apType = APType.na,
  MlangeProgressCallback? onProgress,
  ZeticMLangeCacheHandlingPolicy cacheHandlingPolicy =
      CacheHandlingPolicy.removeOverlapping,
})
ParameterTypeDefaultDescription
personalKeyStringYour personal authentication key.
nameStringFull model identifier in account_name/project_name format.
versionint?nullSpecific model version to load. null uses the latest.
modelModeModelModerunAutoAutomatic selection strategy. See Enums.
quantTypeQuantType?nullQuantization precision filter (fp32, fp16, int). null disables precision-based filtering.
targetTarget?nullOptional runtime target. Use this only when you need to pin a backend and your account tier supports explicit target selection.
apTypeAPTypenaOptional processor preference: cpu, gpu, npu, or na.
onProgressMlangeProgressCallback?nullDownload progress callback from 0.0 to 1.0.
cacheHandlingPolicyZeticMLangeCacheHandlingPolicyremoveOverlappingNative model cache policy. See Cache Management.
final model = await ZeticMLangeModel.create(
  personalKey: personalKey,
  name: 'Steve/YOLOv11_comparison',
  modelMode: ModelMode.runAuto,
  onProgress: (progress) => print(progress),
);

Throws: MlangeException or a native SDK error if the model cannot be downloaded, initialized, or matched to the requested runtime options.

Model creation performs network and file-system work on first use. The default FFI binding runs remote model creation asynchronously before returning the model handle.

Properties

isClosed

bool get isClosed

Returns true after close releases the native model handle.


Methods

run

Runs inference with optional input tensors.

List<Tensor> run([List<Tensor> inputs = const []])
ParameterTypeDescription
inputsList<Tensor>Input tensors matching the model's expected shapes and data types.

Returns: List<Tensor> containing the output tensors from the native model.

Throws: MlangeException if the input tensor count or byte length does not match the native model input buffers, or a native SDK error if inference fails.

final outputs = model.run([inputTensor]);

run() with no arguments executes against the model's existing native input buffers. Flutter does not currently expose those buffers directly, so most app code should pass inputs.

close

Releases the native model handle.

void close()

Call close() when the model is no longer needed.

After close(), calling run() or close() again throws MlangeException because the native handle has been released.


Full Working Example

import 'dart:typed_data';

import 'package:zetic_mlange/zetic_mlange.dart';

final model = await ZeticMLangeModel.create(
  personalKey: personalKey,
  name: modelName,
);

final input = Tensor.float32View(
  Float32List.fromList([/* values */]),
  shape: const [1, 3, 224, 224],
);

final outputs = model.run([input]);
final first = outputs.first.asFloat32List();

model.close();

On this page