DevFest Noida 2026
Flutter · Gemma 4 · On-device

Building
On-Device AI Apps
with Flutter & Gemma

Akansha Jain
Senior Software Engineer · AutoNation Inc.
Organiser - Flutter Delhi · FFDG New Delhi
Women Techmakers Ambassador
Building On-Device AI Apps with Flutter & Gemma01 / 33
DevFest Noida 2026

How most AI features work today

Every AI feature you've shipped
works the same way.

Your app
Sends the user's request
a question, a photo, a voice note →
← the answer, after a round trip
Someone else's GPU
Runs the model and replies
Building On-Device AI Apps with Flutter & Gemma02 / 33
DevFest Noida 2026

The round trip

That round trip isn't free.

Latency

The user waits for the network before the first word appears, and longer on a weak connection.

Cost

You pay per token, so the bill grows as more people use the feature.

Privacy

Whatever the user typed, photographed or recorded leaves their phone.

Availability

No signal means no feature, whether that's on a flight or on patchy mobile data.

Building On-Device AI Apps with Flutter & Gemma03 / 33
DevFest Noida 2026

So here's the question

What if the model
lived inside
your app?

Building On-Device AI Apps with Flutter & Gemma04 / 33
01

Meet
Gemma

Google's family of open models, including the one we'll run on the device today.

Building On-Device AI Apps with Flutter & Gemma05 / 33
DevFest Noida 2026

The Gemma 4 lineup

Five sizes, and two are made for phones.

Phones, laptops, browsers
E2B
Effective 2B
E4B
Effective 4B

128K-token context. Takes text, images and audio.

What does the “E” mean?

Google says the “E” stands for “effective” parameters. Per-Layer Embeddings keep the working memory close to that of a much smaller model.

Workstations and servers
12B
Multimodal
26B A4B
Mixture of Experts, 3.8B active
31B
Dense

256K-token context.

Building On-Device AI Apps with Flutter & Gemma06 / 33
DevFest Noida 2026

In 2024, the smallest Gemma could only read text

2.3B
Gemma 4 E2B, the model in our demo
effective parameters,
running on a phone.

It understands text, images and audio, and was pre-trained on 140+ languages.

On an iPhone 17 Pro it starts replying in 0.3 s and writes 56.5 tokens a second, faster than anyone can read.

56.5 tokens/s
iPhone 17 Pro · GPU
52.1 tokens/s
S26 Ultra · GPU
160.2 tokens/s
MacBook Pro M4 Max · GPU

Speeds from the litert-community/gemma-4-E2B-it-litert-lm model card: 1,024-token prompt, 256 generated tokens, 2,048-token context. Parameters and languages from Google's Gemma 4 E2B model card.

Building On-Device AI Apps with Flutter & Gemma07 / 33
DevFest Noida 2026

Who has no other option

Some apps can't use the cloud.

Healthcare

Summarise a consultation while it happens.

Patient notes are not allowed to reach someone else's server.

Field work

An assistant for the technician on site.

Basements, rigs, aircraft, rural roads — there is no signal where the work is.

Banking

Read an ID or a claim form from a photo.

The document never has to leave the customer's phone.

Accessibility

Describe what the camera is pointed at.

It has to answer in the moment, even with no connection at all.

Building On-Device AI Apps with Flutter & Gemma08 / 33
02

How it
works

From your Dart code down to the chip.

Building On-Device AI Apps with Flutter & Gemma09 / 33
DevFest Noida 2026

What's inside the device

You only write the top layer.

the device
Your Flutter app
Dart and widgets
flutter_edge_ai
models, chats, downloads
flutter_edge_ai_litertlm
the engine, via dart:ffi
LiteRT-LM
Google's on-device LLM runtime
CPU · GPU · NPU
the hardware
LiteRT-LM

Google's runtime for running LLMs on devices. It also powers on-device AI in Chrome, Chromebook Plus and Pixel Watch.

Straight from Dart

flutter_edge_ai talks to the runtime straight from Dart through dart:ffi, on Android, iOS and desktop.

Building On-Device AI Apps with Flutter & Gemma10 / 33
DevFest Noida 2026

How the package is put together

A small core, plus what you actually use.

flutter_edge_aithe core, always needed
flutter_edge_ai_litertlm.litertlm engine: mobile, desktop, web
flutter_edge_ai_speechspeech-to-text and text-to-speech
flutter_edge_ai_mediapipe.task engine: mobile, web
flutter_edge_ai_ragon-device RAG
flutter_edge_ai_agentagent skills
flutter_edge_ai_onnxONNX Runtime
Why it is split up

Every engine comes with its own native libraries. Splitting them up means your app only ships the ones it uses.

The catch

The core doesn't register an engine for you. Forget to add one and the app still compiles, then fails at runtime.

Building On-Device AI Apps with Flutter & Gemma11 / 33
DevFest Noida 2026

Picking a model format

One model file for every platform.

.litertlm

The LiteRT-LM format, and what this demo uses.

Android
iOS
macOS, Windows, Linux
.task

The MediaPipe format, used by older models.

Android
iOS
macOS, Windows, Linux
Building On-Device AI Apps with Flutter & Gemma12 / 33
DevFest Noida 2026

Same code, different weights

Gemma is one choice, not the only one.

Small and quick
SmolLM 135M135 MB
LFM2.5 230M168 MB
FunctionGemma 270M284 MB

FunctionGemma does one job: it calls your functions.

Text, tools, reasoning
Qwen3 0.6B586 MB
Qwen 2.5 1.5B1.6 GB
DeepSeek R1 1.5B1.7 GB
Phi-4 Mini3.9 GB

Qwen3 and DeepSeek R1 also stream their reasoning.

Vision
SmolVLM2 500M360 MB
FastVLM 0.5B0.5 GB
Qwen2-VL 2B1.8 GB

Pick the smallest one that can do the job.

Or the model already in the operating system

Gemini Nano on Android, Apple Foundation Models on iOS and macOS, Phi Silica on Windows. Nothing to download — but it is a different model on every platform, and it may be switched off.

Switching costs two lines

The file you install, and the ModelType you pass. Everything after that is the same code.

Building On-Device AI Apps with Flutter & Gemma13 / 33
03

Let me
show you

One Flutter app running Gemma 4 E2B, entirely on the device.

Building On-Device AI Apps with Flutter & Gemma14 / 33
Demo 1 · Vision

Show it a photo.

Try asking
“What's in this image?”
Recording neededassets/demo/vision.mp4

Vision chat: attach a photo, ask “What's in this image?”, record until the answer finishes. 20–40 s.

Demo 2 · Thinking

Watch it think.

The prompt
“If a bat and ball cost 1.10 and the bat costs 1 more than the ball, what does the ball cost?”
Recording neededassets/demo/thinking.mp4

Thinking mode: tap the bat-and-ball suggestion, expand “Reasoning” while it streams. 30–60 s.

Demo 3 · Function calling

It calls your Dart.

The prompt
“Add buy milk, then tell me what is on my list”
Recording neededassets/demo/function-calling.mp4

Function calling: send “Add buy milk, then tell me what's on my list”. Show both tool bubbles and the task strip update. 20–40 s.

Demo 4 · Voice

Talk to it.

What I asked
“Tell me a joke about programmers.”
Recording neededassets/demo/voice-loop.mp4

Voice loop, push-to-talk, recorded WITH system audio: ask a short question and let it speak the reply. 20–40 s.

Demo 5 · Offline

Now turn off the Wi‑Fi.

What to watch
Wi-Fi goes off in Control Center, then a new prompt.
Recording neededassets/demo/airplane-mode.mp4

Turn Wi-Fi off in Control Center on camera, then send a new prompt in Vision or Thinking. 20–40 s.

DevFest Noida 2026

What you just watched

Three models, one download each.

Whisper Tiny

151 MB

Your voice becomes text. It listens in 30-second windows.

Gemma 4 E2B

2.6 GB

Text and images in, the answer out. Every demo you just saw used this one.

Inflect-Nano

36 MB

The answer becomes speech. English only, and fast enough to keep a conversation going.

About 2.8 GB in total. Downloaded once, then nothing leaves the device.

Building On-Device AI Apps with Flutter & Gemma20 / 33
04

Build it

The code behind the demo, exactly as it runs.

Building On-Device AI Apps with Flutter & Gemma21 / 33
DevFest Noida 2026

Step 1 · Packages and engine

Add the packages, then register the engine.

pubspec.yaml
dependencies: flutter_edge_ai: ^2.1.1 flutter_edge_ai_litertlm: ^1.10.1
Toolchain

flutter_edge_ai needs Flutter 3.44+ and Dart 3.12+, because its native libraries come through Native Assets build hooks.

main.dart
Future<void> main() async { WidgetsFlutterBinding.ensureInitialized(); await FlutterEdgeAi.initialize( inferenceEngines: const [LiteRtLmEngine()], ); runApp(const App()); }

No Hugging Face token needed. The litert-community build of Gemma 4 E2B is public.

Building On-Device AI Apps with Flutter & Gemma22 / 33
DevFest Noida 2026

Step 2 · Download, load, open a chat

Download it once, then load it on the GPU.

gemma_service.dart
await FlutterEdgeAi.installModel( modelType: ModelType.gemma4, fileType: ModelFileType.litertlm, ).fromNetwork(gemma4E2bUrl).withProgress(onProgress) .install(); final model = await FlutterEdgeAi.getActiveModel( maxTokens: 4096, preferredBackend: PreferredBackend.gpu, supportImage: true, ); final chat = await model.createChat( modelType: ModelType.gemma4, supportImage: true, enableThinking: true, );
installModel

Downloads about 2.6 GB the first time. If the file is already there, it just marks the model as active.

maxTokens

This is the context window: prompt, history and reply combined. To limit the reply, use maxOutputTokens.

Watch those two highlighted lines

Get either one wrong and it still compiles — the app fails later, at runtime.

Building On-Device AI Apps with Flutter & Gemma23 / 33
DevFest Noida 2026

Step 3 · Send a message, stream the reply

Stream the reply as it's written.

chat_screen.dart
await chat.addQueryChunk( Message.text(text: prompt, isUser: true), ); await for (final r in chat.generateChatResponseAsync()) { switch (r) { case TextResponse(:final token): answer += token; case ThinkingResponse(:final content): reasoning += content; case FunctionCallResponse(): case ParallelFunctionCallResponse(): break; } }
A sealed type

ModelResponse is sealed, so the switch has to handle every case. A new response type gives you a compile error instead of silently lost tokens.

Adding an image is one change
Message.withImage(
  text: 'What do you see?',
  imageBytes: photo,
  isUser: true,
)
Building On-Device AI Apps with Flutter & Gemma24 / 33
05

What broke

The parts most talks skip. All of these happened while I was building this app.

Building On-Device AI Apps with Flutter & Gemma25 / 33
DevFest Noida 2026

Lesson 1

Speech models listen for a fixed length.

My first voice turns were cut off mid-sentence, and nothing in the logs said why. A speech-to-text model is exported with one fixed window. Anything longer than that is dropped, quietly.

Moonshine Tiny
5s

The filename says it: moonshine_tiny_5s_f32.tflite. Say a sentence and a half, and only the first five seconds reach the model.

Whisper Tiny
30s

A 30-second window, and multilingual. That is what makes a real conversational turn possible, so this is what the demo ships.

What I do now

Cap the recorder below the window — mine stops at 25 seconds — and show the countdown while it listens. Short audio is padded, so there is no cost to stopping early.

The same holds for whichever model you pick: read the window it was exported with.

Building On-Device AI Apps with Flutter & Gemma26 / 33
DevFest Noida 2026

Lesson 2

Small models slip into other languages.

An actual reply from the voice demo

Yes, I know about Flutter. It is an open-ソース software development kit created by Google…

Why

The model knows the same word in many languages. ソース is Japanese for “source”, and with loose sampling it can beat the English word.

What helped
  • Tighter sampling, such as temperature 0.7 for chat and 0.3 for voice
  • Say which language to use in the system instruction
  • For speech, remove characters the voice can't pronounce

That made it rare, but it still happens now and then.

Building On-Device AI Apps with Flutter & Gemma27 / 33
DevFest Noida 2026

Not a prototype

Shipping today, on-device.

Pixel Recorder

Summarises your recording with Gemini Nano, with no internet connection.

Apple Intelligence

Rewrites and summarises your text on a 3-billion-parameter model, on the phone.

Chrome

Gemini Nano built into the browser, reachable from JavaScript.

Google AI Edge Gallery

Google’s own app. Download a model, turn off your Wi-Fi, and keep chatting. The same Gemma 4 E2B you just watched is in there.

Building On-Device AI Apps with Flutter & Gemma28 / 33
DevFest Noida 2026

Your turn

Get it running tonight.

1
Flutter 3.44 or newer

flutter_edge_ai needs Flutter 3.44+ and Dart 3.12+.

2
Add two packages

flutter pub add flutter_edge_ai flutter_edge_ai_litertlm

3
Register the engine

Call FlutterEdgeAi.initialize(inferenceEngines: …) in main.

4
Platform setup

iOS 15+. Android: minSdk 30 and arm64. macOS: Apple Silicon, with Swift Package Manager off and the Podfile step from the docs.

5
Install Gemma 4 E2B

It's public, so no token. About 2.6 GB, downloaded once.

6
Turn off the Wi‑Fi

It keeps working.

The codelab on the next slide walks through every one of these steps, including the platform setup.

Building On-Device AI Apps with Flutter & Gemma29 / 33
DevFest Noida 2026

Build it yourself

Build this app, step by step.

16 steps, about 90 minutes
Streaming chat, vision, thinking and tool calling
Setup for Android, iOS and macOS
Gemma 4 E2B, with no token and no server
Start the codelab
akanshajain.dev/codelabs/on-device-ai
Building On-Device AI Apps with Flutter & Gemma30 / 33
DevFest Noida 2026

Scan to open

Everything from this talk.

The demo app
github.com/jakansha2001/gemma-on-device-demo
flutter_edge_ai
pub.dev/packages/flutter_edge_ai
Docs & guides
flutteredge.ai
Gemma 4 E2B
huggingface.co/litert-community
My article
Why I think on-device AI changes mobile architecture
Building On-Device AI Apps with Flutter & Gemma31 / 33
DevFest Noida 2026

On-device AI isn't replacing cloud AI.

It's unlocking a different class of app — one that's private, offline-capable, and free to scale.

Building On-Device AI Apps with Flutter & Gemma32 / 33
DevFest Noida 2026

Thank you

Akansha Jain
Senior Software Engineer · AutoNation Inc.
Women Techmakers Ambassador
Feedback for my talk
forms.gle/PXoRAra5ZidN1PeJ8
Website
akanshajain.dev
Connect
LinkedIn
Building On-Device AI Apps with Flutter & Gemma33 / 33