FlutterGemma class

Modern API facade for Flutter Gemma

Provides clean, type-safe API for model management and inference.

Initialization

Initialize once at app startup:

void main() {
  FlutterGemma.initialize(
    huggingFaceToken: 'hf_...',     // Optional: for gated models
    maxDownloadRetries: 10,         // Optional: default is 10
  );
  runApp(MyApp());
}

Install Models

// From network
final installation = await FlutterGemma.installModel(
  modelType: ModelType.gemmaIt,
)
  .fromNetwork('https://huggingface.co/.../model.bin')
  .withProgress((progress) => print('Progress: $progress%'))
  .install();

// From asset
await FlutterGemma.installModel(
  modelType: ModelType.gemmaIt,
)
  .fromAsset('models/gemma.bin')
  .install();

// From bundled resource
await FlutterGemma.installModel(
  modelType: ModelType.gemmaIt,
)
  .fromBundled('gemma.bin')
  .install();

// From external file
await FlutterGemma.installModel(
  modelType: ModelType.gemmaIt,
)
  .fromFile('/path/to/model.bin')
  .install();

Load Models

// Get active model after installation
final model = await FlutterGemma.getActiveModel(maxTokens: 1024);
final session = await model.createSession();
final response = await session.getResponse();

Constructors

FlutterGemma()

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Properties

logLevel GemmaLogLevel
Controls flutter_gemma's internal log verbosity.
getter/setter pair

Static Methods

clearActiveEmbeddingIdentity() Future<void>
Clears the active embedding identity (in-memory spec + persisted prefs).
clearActiveInferenceIdentity() Future<void>
Clears the active inference identity (in-memory spec + persisted prefs).
clearActiveSttIdentity() Future<void>
Clears the active STT identity (in-memory spec + persisted prefs).
clearActiveTtsIdentity() Future<void>
Clears the active TTS identity (in-memory spec + persisted prefs).
dispose() Future<void>
Closes the active vector store (releasing its native handle — qdrant-edge shard / sqlite connection) and then resets the DI singleton.
getActiveEmbedder({PreferredBackend? preferredBackend}) Future<EmbeddingModel>
Get the active embedding model as a ready-to-use EmbeddingModel
getActiveModel({int maxTokens = 1024, PreferredBackend? preferredBackend, bool supportImage = false, bool supportAudio = false, int? maxNumImages, bool? enableSpeculativeDecoding, int? maxConcurrentSessions}) Future<InferenceModel>
Get the active inference model as a ready-to-use InferenceModel
getActiveStt({PreferredBackend? preferredBackend}) Future<SpeechRecognizer>
Get the active STT model as a ready-to-use SpeechRecognizer
getActiveTts({PreferredBackend? preferredBackend}) Future<SpeechSynthesizer>
Get the active TTS model as a ready-to-use SpeechSynthesizer
hasActiveEmbedder() bool
Check if there's an active embedding model
hasActiveModel() bool
Check if there's an active inference model
hasActiveStt() bool
Check if there's an active STT model
hasActiveTts() bool
Check if there's an active TTS model
initialize({String? huggingFaceToken, int maxDownloadRetries = 10, WebStorageMode webStorageMode = WebStorageMode.cacheApi, bool? enableWebCache, List<InferenceEngineProvider> inferenceEngines = const [], List<EmbeddingBackendProvider> embeddingBackends = const [], List<SttBackendProvider> sttBackends = const [], List<TtsBackendProvider> ttsBackends = const [], List<SkillExecutorProvider> skillExecutors = const [], VectorStoreRepository? vectorStore, FilterSchema filterSchema = const FilterSchema(), Stream<Object>? downloadUpdatesStream, FileSystemService? fileSystemService}) Future<void>
Initialize Flutter Gemma
installEmbedder() EmbeddingInstallationBuilder
Start building an embedding model installation
installModel({required ModelType modelType, ModelFileType fileType = ModelFileType.task}) InferenceInstallationBuilder
Start building an inference model installation
installStt() SttInstallationBuilder
Start building an STT (speech-to-text) model installation
installTts() TtsInstallationBuilder
Start building a TTS (text-to-speech) model installation
isModelInstalled(String modelId) Future<bool>
Check if a model is installed
isStreamingSupported() Future<bool>
Check if OPFS streaming mode is supported by the current browser
listInstalledModels() Future<List<String>>
List all installed models
reset() → void
Reset ServiceRegistry (primarily for testing)
uninstallModel(String modelId) Future<void>
Uninstall a model