Skip to main content

flutter_edge_ai_mediapipe 1.3.0 copy "flutter_edge_ai_mediapipe: ^1.3.0" to clipboard
flutter_edge_ai_mediapipe: ^1.3.0 copied to clipboard

MediaPipe (.task) on-device inference engine for flutter_edge_ai (Android/iOS/Web). Opt-in package; provides an InferenceEngineProvider. Bundles Google's MediaPipe Pod/Gradle deps.

flutter_edge_ai_mediapipe #

Renamed from flutter_gemma_mediapipe. Same package, new name: swap the dependency and the package:flutter_gemma_mediapipe/ imports; nothing on the device changes. See the migration guide.

MediaPipe (.task) on-device inference engine for flutter_edge_ai. Opt-in package — add it only if you run MediaPipe .task models. Android, iOS, and Web.

Google moved MediaPipe LLM Inference to maintenance-only. New features and optimizations focus on LiteRT-LM, so a new app should use .litertlm models with flutter_edge_ai_litertlm. On iOS, do not load a .task model on the GPU: Gemma 3 1B reached the app's memory limit while loading and iOS terminated the app (details).

Teach your AI assistant this package #

dart run skills@ get --all

Installs the agent skills flutter_edge_ai bundles — this package depends on it, so they come with it. One of them, flutter-edge-ai-mediapipe, covers .task and .bin models on Android, iOS and web.

Usage #

import 'package:flutter_edge_ai/flutter_edge_ai.dart';
import 'package:flutter_edge_ai_mediapipe/flutter_edge_ai_mediapipe.dart';

await FlutterEdgeAi.initialize(
  inferenceEngines: [MediaPipeEngine()],
);

MediaPipeEngine handles ModelFileType.task / ModelFileType.binary (.bin, .tflite) models; pass it alongside other engines (e.g. LiteRtLmEngine from flutter_edge_ai_litertlm) if your app uses both formats.

maxTokens is the whole context (input plus output), and a small value is not raised as it is on .litertlm. maxOutputTokens is ignored (only a debug log says so); stop early with session.stopGeneration().

On Android and iOS, pass supportImage: true to openChat as well as to getActiveModel, or the image is dropped. The Gemma 3n .task files carry no audio encoder; use a .litertlm model for audio.

Structured output #

MediaPipe does not expose constrained decoding. model.structuredOutputSupport reports no support, and openSession(responseFormat: …) / openChat(responseFormat: …) throw ResponseFormatUnsupportedException. Use prompt-only JSON or an engine that supports ResponseFormat.

Sampling #

A .task file ships no sampler, so an unset temperature, topK or topP comes from the model family's defaults (SamplingParams.forModelType), with an unset topK capped at 40, MediaPipe's own default; an unset randomSeed is 1. topK: 1 or temperature: 0 decodes greedily, as Phi and Hammer do by default; before 1.2.0 every family did. On Android and iOS each session starts from its seed, so vary randomSeed for a different answer to the same prompt. On web the loaded model keeps the sampling and LoRA of its first session, so those of a later openSession are not applied, and a one-time warning names them; web also has no top-p, and a topP you pass is ignored with a one-time warning.

Web setup #

On Web, the MediaPipe runtime is loaded from a CDN. Add this to your app's web/index.html (inside a <script type="module"> before your Flutter bootstrap), exposing the symbols on window:

<script type="module">
import { FilesetResolver, LlmInference } from 'https://cdn.jsdelivr.net/npm/@mediapipe/tasks-genai@0.10.30';
window.FilesetResolver = FilesetResolver;
window.LlmInference = LlmInference;
</script>

Load the model's -web.task build (e.g. gemma3-1b-it-int4-web.task); mobile .task files generally do not run on web. Also copy cache_api.js and opfs_helper.js from the flutter_edge_ai package's web/ directory into your app's web/ and load them inside the <head> of web/index.html with <script src="cache_api.js"></script> and <script src="opfs_helper.js"></script> — see Installation → Web. Web runs on the GPU only.

On web, MediaPipe keeps nothing between calls, so the session keeps the conversation itself and sends all of it with every turn: each answer re-reads the whole history, and its time grows with the chat. Past turns stay in it with the model's replies, images and audio included, so maxNumImages counts every image of the conversation, not one prompt. A turn that would go past it fails with an error that names maxNumImages; nothing is dropped. openSession and openChat open sessions that stay live side by side until closed: each keeps its own conversation, and they take turns on the one loaded model, so a turn waits for the turns of the other sessions, as long as they run, unless they are stopped (a wait past 30 s prints a warning once). maxConcurrentSessions caps them. A stop, a close or a cancelled response stream of one session ends only its own turn. The turn markers are read from the .task file's own metadata (Gemma 4 declares <|turn>), and a file that declares none falls back to its model type. A .bin file and FunctionGemma keep the markers core writes into their messages, and a .task that carries MediaPipe's own prompt_templates is sent without markers of ours. stopGeneration() keeps what a streamed reply had produced. A turn that fails, or is stopped before any text, is taken back: the conversation is left as it was before that turn's user message, as the chat leaves its history.

(Android needs no extra setup — the MediaPipe Gradle deps are bundled by this package.)

iOS setup #

iOS needs a 16.0 minimum. MediaPipe GenAI requires it — core, flutter_edge_ai_litertlm, built-in AI and embeddings build from 15.0 (#441); flutter_edge_ai_llama needs 16.4.

This package ships no Package.swift, so even an app on Swift Package Manager gets a Podfile for it. Set the floor in BOTH places: platform :ios, '16.0' in the Podfile, and iOS Deployment Target on the Runner target in Xcode. Below 16, pod install reports that specs satisfying the flutter_edge_ai_mediapipe dependency "required a higher minimum deployment target".

MediaPipe ships static xcframeworks, so the Podfile also needs use_frameworks! :linkage => :static — with the Flutter template's bare use_frameworks!, pod install fails on "transitive dependencies that include statically linked binaries".

Platforms #

Platform Support
Android ✅ com.google.mediapipe:tasks-genai 0.10.35 (Gradle)
iOS ✅ MediaPipeTasksGenAI 0.10.35 (CocoaPods) — requires iOS 16.0+; run .task models on PreferredBackend.cpu
Web ✅ @mediapipe/tasks-genai 0.10.30 (CDN, see above) — GPU only, -web.task models
Desktop ❌ (MediaPipe .task not supported on desktop — use flutter_edge_ai_litertlm)

Built something with flutter_edge_ai? #

See what others ship on the showcase, and add your app: it takes a couple of minutes, and the listing links to your app's Google Play or App Store page.

0
likes
140
points
3.07k
downloads

Documentation

API reference

Publisher

verified publishersashadenisov.dev

Weekly Downloads

MediaPipe (.task) on-device inference engine for flutter_edge_ai (Android/iOS/Web). Opt-in package; provides an InferenceEngineProvider. Bundles Google's MediaPipe Pod/Gradle deps.

Homepage
Repository (GitHub)
View/report issues

Topics

#gemma #llm #mediapipe #on-device #ai

License

MIT (license)

Dependencies

flutter, flutter_edge_ai, meta, mutex, plugin_platform_interface

More

Packages that depend on flutter_edge_ai_mediapipe

Packages that implement flutter_edge_ai_mediapipe