Setup guide for Flutter

This page shows you how to set up your development environment to use MediaPipe Tasks in your Flutter and Dart applications. Each task runs Google's MediaPipe runtime for the platform it runs on, and Google's pinned models are bundled with your app at build time.

Supported platforms and versions

To create Flutter applications with MediaPipe Tasks, your development environment requires the following:

  • Flutter 3.47 or newer. The latest stable release is recommended.
  • One or more of the following target platforms:
    • Android 9 (API level 28) or higher
    • iOS 15.0 or higher
    • macOS 14.0 or higher on Apple Silicon
    • Linux x64
    • Windows x64
    • Web

All tasks run on every platform listed above, except Text Proofreader and Text Summarizer, which are not yet available on the web. This matches the MediaPipe Tasks Web SDK, which doesn't support these two tasks. For per-platform requirements, see Platform notes.

MediaPipe Tasks dependencies

MediaPipe Tasks provides five Flutter packages for vision, text, audio, retrieval, and decision tasks. Add only the packages your app uses: each one bundles only the MediaPipe library for its domain. Every package depends on mediapipe_core, which holds the shared model store and web runtime settings, and re-exports its types, so you don't need to add mediapipe_core yourself.

Vision tasks

The MediaPipe Tasks vision package (mediapipe_vision) contains tasks that process images, video frames, and live camera streams (such as Face Landmarker, Hand Landmarker, Pose Landmarker, Object Detector, and Image Segmenter). See Prepare vision input data for supported inputs.

flutter pub add mediapipe_vision

Text tasks

The MediaPipe Tasks text package (mediapipe_text) contains tasks that analyze and embed text strings (such as Text Classifier, Language Detector, and Text Embedder), plus Text Proofreader and Text Summarizer on platforms other than the web.

flutter pub add mediapipe_text

Audio tasks

The MediaPipe Tasks audio package (mediapipe_audio) contains tasks that classify audio clips and streams, transcribe speech, and synthesize speech (Audio Classifier, Audio Transcriber, and Text-to-Speech). See Prepare audio input data for supported inputs.

flutter pub add mediapipe_audio

Retrieval tasks

The MediaPipe Tasks retrieval package (mediapipe_retrieval) provides text, image, and audio embeddings in a shared embedding space and an on-device vector index over them (Universal Embedder and Semantic Retriever).

flutter pub add mediapipe_retrieval

Decision tasks

The MediaPipe Tasks decision package (mediapipe_decision) answers yes-or-no, choice, and score questions about a text (Decision Maker).

flutter pub add mediapipe_decision

Bundle models

Apps bundle the models they use at build time, so nothing is downloaded at run time and the app works offline from its first launch.

  1. In your app's pubspec.yaml, declare the assets/mediapipe/ folder and list the models each package uses under hooks.user_defines. Each package's XxxModels.byName (for example, VisionModels.byName) lists the names it accepts.

    flutter:
      assets:
        - assets/mediapipe/
    
    hooks:
      user_defines:
        mediapipe_vision:
          models: [face_landmarker, hand_landmarker]
        mediapipe_audio:
          models: [yamnet]
    
  2. From your app's root, download and verify the listed models. Run this command again whenever the list changes:

    dart run mediapipe_core:bundle_models
    

    The command downloads each listed model, checks it against its pinned SHA-256 hash, writes it into assets/mediapipe/, and removes models that are no longer listed.

  3. In continuous integration, verify that the folder matches the list without changing it:

    dart run mediapipe_core:bundle_models --check
    

Then create a task with the bundled model:

import 'dart:typed_data';

import 'package:mediapipe_vision/mediapipe_vision.dart';

Future<int> countFaces(Uint8List rgba, int width, int height) async {
  final landmarker = await FaceLandmarker.create(
    FaceLandmarkerOptions(model: VisionModels.faceLandmarker),
  );
  try {
    final result = await landmarker.detect(
      VisionImage.fromPixels(
        pixels: rgba,
        width: width,
        height: height,
        format: VisionPixelFormat.rgba,
      ),
    );
    return result.faceLandmarks.length;
  } finally {
    await landmarker.dispose();
  }
}

If a model isn't bundled, create throws a RuntimeUnavailableException whose fix names the pubspec.yaml entry to add. To use your own model, pass modelPath or modelBytes in the task options instead of model.

Download models at run time

Downloading models at run time is opt-in. To let model: download models that your app doesn't bundle, set ModelStore.allowDownloads before you create any tasks:

ModelStore.allowDownloads = true;

Downloaded models are verified against the same pinned hashes and cached on the device. Run-time downloads need network access: see the Android and macOS notes in Platform notes.

Platform notes

Android

  • Set minSdk to 28 (Android 9) or higher in android/app/build.gradle(.kts).
  • Tasks run on arm64-v8a and x86_64. On 32-bit devices (armeabi-v7a), the vision and audio tasks and the Text Classifier, Text Embedder, and Language Detector tasks run on the CPU. Decision Maker, the retrieval tasks, EmbeddingGemma, Text Proofreader, Text Summarizer, Audio Transcriber, and Text-to-Speech require a 64-bit device.
  • On the Android emulator, only the CPU delegate is available.
  • To download models at run time, add the INTERNET permission to android/app/src/main/AndroidManifest.xml. Flutter adds it only to debug and profile builds, so release builds need it explicitly:

    <uses-permission android:name="android.permission.INTERNET"/>
    

iOS

  • Set the deployment target to iOS 15.0 or higher.
  • On the iOS Simulator, only the CPU delegate is available.
  • For App Store submission, declare the required-reason APIs that the MediaPipe libraries call in your app's ios/Runner/PrivacyInfo.xcprivacy. See App Store privacy manifest for the categories to declare.

macOS

  • macOS 14.0 or higher on Apple Silicon is required.
  • Build the app for Apple Silicon only. Release and profile builds also build an Intel (x86_64) slice by default, which the MediaPipe libraries don't provide, so those builds fail. Add these lines to macos/Runner/Configs/AppInfo.xcconfig:

    ARCHS = arm64
    EXCLUDED_ARCHS = x86_64
    

    Alternatively, run flutter config --enable-macos-arm64-only to apply the same setting to every app built on that machine.

  • To download models at run time, a sandboxed app needs the network client entitlement in macos/Runner/DebugProfile.entitlements and macos/Runner/Release.entitlements:

    <key>com.apple.security.network.client</key>
    <true/>
    

Linux

  • The MediaPipe Linux library loads EGL and OpenGL ES, even for CPU inference. On Debian or Ubuntu, install them with:

    sudo apt-get install libegl1 libgles2
    

Windows

  • Tasks run on the CPU.

Web

  • By default, the MediaPipe JavaScript and WebAssembly runtimes load from jsDelivr, and each file is checked against a pinned SHA-384 hash before it runs. Bundled models load from your app's own assets.
  • To host the runtimes yourself (for offline use, an intranet, or a strict Content Security Policy), copy them into your app from its root:

    dart run mediapipe_core:web_runtime web/mediapipe
    

    Then set the base URL before you create the first task:

    MediaPipeWebRuntime.baseUrl = 'mediapipe/';
    
  • If your site sends a Content Security Policy, allow 'self' and blob: in script-src and worker-src, 'wasm-unsafe-eval' for WebAssembly, and 'self' and https://cdn.jsdelivr.net (unless self-hosted) in connect-src. Add https://storage.googleapis.com to connect-src only if you download models at run time.

  • Decision Maker and the retrieval tasks require WebGPU in the browser.

Samples and resources

Troubleshooting

For help with technical questions related to MediaPipe, visit the discussion group or Stack Overflow for support from the community. To report bugs or make feature requests for the Flutter packages, file an issue on GitHub.