flutter_edge_ai library
The app library of flutter_edge_ai: everything an application needs to install models and run inference, embeddings and speech.
Engine, backend, tokenizer, resolver and skill-executor packages import
package:flutter_edge_ai/engine.dart instead (it re-exports this library);
native-only helpers live in engine_io.dart, web-only ones in
engine_web.dart. Nothing under lib/src is public.
Every export carries an explicit show list, and the namespace is pinned by
the symbol golden in test/public_surface/.
Classes
- AssetSource
- Asset source - copies from Flutter assets
- BundledSource
- Bundled source - native platform resources
- CanceledError
- Download canceled
- CancelToken
- Token for cancelling model downloads
- CorruptionDetectionResult
- Result of corruption detection
- DiagnosticReport
- Diagnostic information for troubleshooting
- DownloadError
- Download error types using sealed classes for exhaustive pattern matching
- DownloadProgress
- Progress information for model downloads
- EmbeddingBackendProvider
-
A pluggable embedding backend (LiteRT C API + Gecko/EmbeddingGemma, ONNX,
or a third-party backend). Same probe-chain shape as
InferenceEngineProvider: selected by probing the embedding model spec, highest-priority first match. - EmbeddingInput
-
One thing to embed, shaped like
Message: optional text plus media. - EmbeddingInstallation
- Result of embedding model installation
- EmbeddingInstallationBuilder
- Fluent builder for embedding model installation
- EmbeddingModel
-
An embedding model, as returned by
FlutterEdgeAi.getActiveEmbedder(). - EmbeddingModelSpec
-
Specification for an embedding model: a model file plus its tokenizer
(
.tflite,.onnx, …), or a single.litertlmbundle that carries its own tokenizer (isSelfContained). - EmbeddingTokenizerProvider
- A pluggable source of EmbeddingTokenizerFactory — the "text -> token ids" half of an embedding.
- EncodedMediaFormat
- An encoded media container (a file format, not a decoded image or waveform).
- ErrorHandlingResult
- Result of error handling
- EstimatedDimensions
- Estimated image dimensions
- FileSource
- File source - external files (mobile only)
- FileSystemService
- Abstraction for file system operations Allows different implementations for different platforms (mobile/web) and easy mocking in tests
- FlutterEdgeAi
- Modern API facade for Flutter Edge AI
- FlutterEdgeAiDesktop
- Desktop implementation of FlutterEdgeAi plugin
- FlutterEdgeAiPlugin
-
Low-level platform-interface tier (the federated-plugin SPI) for
flutter_edge_ai. It hosts the abstract runtime types (
InferenceModel,InferenceModelSession,InferenceChat,EmbeddingModel,SpeechRecognizer,SpeechSynthesizer, …) and the platform-dispatch singleton instance. - ForbiddenError
- HTTP 403 - Access forbidden
- FunctionCallParser
-
Facade for backward compatibility.
Delegates to model-specific
FunctionCallFormatimplementations. - FunctionCallResponse
- Gemma3Specs
- Gemma 3 SigLIP vision encoder specifications
- GeneralVisionSpecs
- General vision encoder specifications
- HuggingFaceResolver
- A pluggable resolver that turns a Hugging Face repo id into a ResolvedHfModel by reading that repo's deployment metadata.
- ImageErrorHandler
- Comprehensive error handling and debugging utilities for AI image processing to prevent corruption that causes repeating text patterns in model responses.
- ImageProcessor
- Comprehensive image processing utilities to prevent AI image corruption and ensure proper vision encoder compatibility.
- ImageTokenizer
- Handles proper image tokenization for multimodal AI models to prevent "Prompt contained 0 image tokens but received 1 images" errors and corruption that causes repeating text patterns.
- InferenceChat
- InferenceEngineProvider
-
A pluggable inference engine (MediaPipe
.task, LiteRT-LM.litertlm, or a third-party.onnx/.ggufengine). - InferenceInstallation
- Result of inference model installation
- InferenceInstallationBuilder
- Fluent builder for inference model installation
- InferenceModel
- Represents an LLM model instance.
- InferenceModelSession
- Session managing response generation from the model.
- InferenceModelSpec
- Specification for inference models (main model + optional LoRA)
- Message
- ModelFile
- Represents a single file that belongs to a model
- ModelFileManager
- ModelResponse
- Base interface for model responses from InferenceChat Can be either TextResponse, FunctionCallResponse, or ThinkingResponse
- ModelRuntimeDefaults
-
Runtime defaults resolved from a Hugging Face repo's deployment metadata
(e.g. a
litertlm_manifest.json), in flutter_edge_ai's own runtime vocabulary. - ModelSource
- Sealed class representing all possible model sources Provides type-safe alternative to string URLs
- ModelSpec
- Base specification for any model (inference or embedding)
- ModelThinkingFilter
- MultimodalImageHandler
- Main integration class for handling multimodal image processing in Flutter Edge AI to prevent AI image corruption and repeating text pattern issues.
- MultimodalImageResult
- Result of multimodal image processing
- NetworkError
- Network connectivity error
- NetworkSource
- Network source - downloads from HTTPS/HTTP URLs
- NotFoundError
- HTTP 404 - Resource not found
- OrphanedFileInfo
- Information about a potentially orphaned file
- ParallelFunctionCallResponse
- Multiple function calls in a single model response.
- ProcessedImage
- Represents a processed image ready for AI model consumption
- RateLimitedError
- HTTP 429 - Rate limit exceeded
- ResolvedHfFile
-
One file of a multi-file (directory) model resolved from a Hugging Face
repo — e.g. an ORT-GenAI model is a DIRECTORY (
genai_config.json+model.onnx+`model.onnx_data`+ tokenizer files), not a single file. - ResolvedHfModel
- A model resolved from a Hugging Face repo's deployment metadata into flutter_edge_ai's install + runtime vocabulary.
- ResolvedSampling
- Sampling parameters with every field set: what an engine sends.
- ResponseValidationResult
- Result of response validation
- SamplingParams
- Sampling parameters for a session, as the caller asked for them.
- ServerError
- HTTP 5xx - Server error
- SessionMetrics
- Session metrics containing token usage and performance statistics.
- SkillExecutorProvider
-
A pluggable skill executor — the seam between core and the opt-in
flutter_edge_ai_agentpackage's agentic "skills" runtime. - SpeechRecognizer
- Represents a speech-to-text model instance.
- SpeechSynthesizer
- Represents a text-to-speech model instance.
- StorageStats
- Storage statistics
- SttBackendProvider
- A pluggable STT backend (LiteRT C API, or a third-party backend). Same probe-chain shape as EmbeddingBackendProvider/InferenceEngineProvider: selected by probing the STT model spec, highest-priority first match.
- SttInstallation
- Result of STT model installation
- SttInstallationBuilder
- Fluent builder for STT (speech-to-text) model installation
- SttModelSpec
- Specification for STT models (model.tflite + tokenizer.json).
- TextResponse
- Text token during streaming
- ThinkingResponse
- Thinking process content from the model
- Tool
- TtsBackendProvider
- A pluggable TTS backend (LiteRT C API, or a third-party backend). Same probe-chain shape as EmbeddingBackendProvider/InferenceEngineProvider: selected by probing the TTS model spec, highest-priority first match.
- TtsInstallation
- Result of TTS model installation.
- TtsInstallationBuilder
- Fluent builder for TTS (text-to-speech) model installation.
- TtsModelSpec
- Specification for a TTS model — a SELECTABLE bundle. ttsModelType carries the model family so one generic backend dispatches to the right runtime profile; sources is one entry per file in that type's manifest.
- HTTP 401 - Authentication required
- UnknownError
- Unknown error
- ValidationResult
- Result of image validation
- VisionEncoderValidator
- Validates images for compatibility with AI vision encoders to prevent corruption that causes models to interpret images as repeating text patterns.
- VisionSpecs
- Base class for vision encoder specifications
Enums
- ActivationDataType
-
Numeric type of the model's activations, for native
.litertlmmodels (Android, iOS, desktop). - CorruptionAction
- Actions to take when corruption is detected
- EdgeAiLogLevel
- Verbosity for flutter_edge_ai's internal logs.
- EmbeddingModality
- A kind of input an embedding model can turn into a vector.
- ErrorType
- Types of errors that can occur in image processing
- MessageType
- ModelFileType
- ModelManagementType
- Base enumeration for different model management types
- ModelReplacePolicy
-
Policy for what happens to a previously-installed model when a new one is
set active. Lives with the spec value types (it's a per-spec install policy);
re-exported from
model_file_manager_interface.dartfor backward compat. - ModelType
- PreferredBackend
- Hardware backend for model inference.
- ResponseAction
- Actions to take for corrupted responses
- SttModelType
-
Speech-to-text model families supported by the pluggable STT backends.
Only moonshine has a shipped
SttModelProfile/pipeline (flutter_edge_ai_speech); the others are follow-ons that need a log-mel frontend. - TaskType
- What an embedding is for. Every engine prepends prefix to the TEXT part of an input, native and web alike; media parts never get a prefix.
- ToolChoice
- Controls whether the model should call tools.
- TtsModelType
-
Text-to-speech model families supported by the pluggable TTS backends.
matcha, qwen3 and inflect have shipped
TtsModelProfile/pipelines (flutter_edge_ai_speech); kokoro/supertonic are documented follow-ons (fail-loud until wired). - VisionEncoderType
- Vision encoder types with their specifications
- WebStorageMode
- Storage mode for web platform models
Mixins
- RawSdkResponseSession
-
Mixin for sessions that surface the SDK's structured raw JSON response
(LiteRT-LM Gemma 4 path with
tool_calls). Allows InferenceChat to read the structured tool calls without a hard dependency on a concrete session type, and lets non-FFI sessions opt out by simply not implementing this mixin.
Extensions
- DownloadErrorMessage on DownloadError
- Extension to convert DownloadError to user-friendly messages
Constants
- defaultMaxFunctionBufferLength → const int
- Default maximum length for function call buffer before flushing as text. Must accommodate verbose formats (DeepSeek tags, parallel calls).
-
supportedLoraRanks
→ const List<
int>
Functions
-
sniffEncodedMediaFormat(
Uint8List bytes) → EncodedMediaFormat? -
The container
bytesstart with, from their magic bytes, or null when they match none of EncodedMediaFormat.known.
Exceptions / Errors
- DownloadCancelledException
- Exception thrown when a download is cancelled
- DownloadException
- Custom exception for download failures
- EmbedderClosedException
- The model was closed, or closed before this request started — so the request never ran.
- EmbedderCloseTimeoutException
-
The previous embedder's close did not finish within the limit (60 s),
measured from the moment that close STARTED, so
FlutterEdgeAi.getActiveEmbedderbuilt nothing: two native models are never resident at once. - EmbeddingCancelledException
-
embedAllwas cancelled through itsCancelToken. No partial results are returned. - EmbeddingEngineException
- The engine failed while embedding.
- EmbeddingException
- Common base of every embedding failure. Not sealed, so a later kind of failure is an additive change; catch this to handle them all.
- EmbeddingFormatNotSupportedException
- A media part's container is not one the engine accepts (e.g. HEIC where the engine decodes JPEG/PNG/GIF/BMP only).
- EmbeddingInputTooLongException
- The input is longer than maxInputTokens — task prefix, BOS and EOS included. Nothing was truncated; split the text and embed the pieces.
- EmbeddingLoadException
- The engine could not load the model, or refused the requested configuration (e.g. a modality it cannot serve).
- EmbeddingModalityNotLoadedException
-
The input carries modality, which this model was not loaded with
(loaded is what it was loaded with). Declare media at load:
getActiveEmbedder(supportImage: true). - ImageProcessingException
- Exception thrown when image processing fails
- ImageTokenizationException
- Exception thrown when image tokenization fails
- ModelStorageException
- Exception thrown when model storage operations fail
- NoActiveModelError
-
Thrown when a model is asked for and none is installed and active: the
app has to install one first (
FlutterEdgeAi.installModel()orinstallEmbedder()). - UnsupportedEmbeddingCombinationException
- The input carries several modalities (requested) and the engine embeds one modality per vector.
- VisionEncoderValidationException
- Exception thrown when validation fails