Google Gemini in Flutter with google_generative_ai
Want a real, multimodal AI assistant in your Flutter app without wiring up a backend? The official google_generative_ai SDK gives you direct access to Google's Gemini models — text, images, and streaming responses — in about twenty lines of Dart.
Why Gemini for Flutter
Gemini is fast, multimodal (it reads images as easily as text), and has a
generous free tier for prototyping. Because google_generative_ai is
maintained by Google, it tracks new model versions quickly and exposes streaming,
function calling, and vision through one clean Dart API.
Installing
dependencies:
google_generative_ai: ^0.4.6
Grab a free API key from Google AI Studio and keep it out of source control (use --dart-define or a secrets file).
Your first Gemini call
import 'package:google_generative_ai/google_generative_ai.dart';
final model = GenerativeModel(
model: 'gemini-1.5-flash',
apiKey: const String.fromEnvironment('GEMINI_KEY'),
);
final response = await model.generateContent(
[Content.text('Give me a witty tagline for a Flutter blog.')],
);
print(response.text);
Streaming responses
For a chat feel, stream tokens as they arrive instead of waiting for the full reply:
final stream = model.generateContentStream(
[Content.text('Explain widgets like I am five.')],
);
await for (final chunk in stream) {
setState(() => _buffer += chunk.text ?? '');
}
Going multimodal
Pass an image alongside text and Gemini will reason about it — perfect for "describe this photo" or receipt parsing:
final bytes = await File(path).readAsBytes();
final res = await model.generateContent([
Content.multi([
TextPart('What is in this image?'),
DataPart('image/jpeg', bytes),
]),
]);
Live demo
Try it: fluttercook.github.io/demos/google_generative_ai · source on github.com/fluttercook.
Gotchas
- Never ship your API key in the client. For production, proxy calls through a backend or Firebase AI with App Check.
- Handle rate limits and safety blocks — wrap calls in try/catch and inspect
promptFeedback. - Pick the right model:
flashfor speed and cost,profor hard reasoning.
Takeaway
google_generative_ai is the fastest way to put a capable, multimodal
LLM into a Flutter app. Start with gemini-1.5-flash, stream the output
for a snappy chat, and move key handling to a backend before you launch.
FlutterCook is publishing 100 hands-on guides to the best open-source Flutter libraries — AI-first. Every demo is runnable at github.com/fluttercook.
Package: pub.dev/packages/google_generative_ai · Tags: Flutter, AI, LLM, Gemini
The Best Open-Source Flutter Libraries in 2026 (AI-First)
The Flutter ecosystem moves fast, and in 2026 the most exciting momentum is around on-device AI. This is a hands-on tour of the open-source libraries worth knowing right now — grouped by what they do, each with a one-line reason to care and a link to dive deeper. Everything here is free and open source.
AI & LLMs (start here)
- flutter_gemma — run Google's Gemma models on-device for a private, offline chatbot. No cloud, no per-token bill. Full guide & demo →
- google_generative_ai — the official Google Gemini SDK: multimodal chat, vision and streaming in about 20 lines of Dart.
- langchain.dart — chains, agents, tools and RAG — the LangChain ecosystem, natively in Dart.
- flutter_ai_toolkit — Google's drop-in AI chat widget with text, image and voice input out of the box.
- ollama_dart — talk to Llama, Mistral and Phi models running locally through Ollama.
On-device machine learning & vision
- google_ml_kit — one plugin for text recognition, face detection, barcode scanning, pose, translation and more.
- tflite_flutter — fast, flexible TensorFlow Lite inference with GPU delegates.
- ultralytics_yolo — real-time YOLO object detection and segmentation on-device.
State management
- Riverpod — compile-safe, testable reactive state; the 2026 default for many teams.
- flutter_bloc — predictable, event-driven state that scales cleanly.
- signals.dart — fine-grained, signals-based reactivity coming to Flutter.
UI, animation & design
- flutter_animate — chainable, declarative animations in a single line.
- Rive — interactive, state-machine-driven vector animations you control at runtime.
- flex_color_scheme — gorgeous, consistent Material 3 light/dark themes, fast.
Backend, data & navigation
- dio — a powerful HTTP client with interceptors, retries and cancellation.
- supabase_flutter — auth, Postgres, realtime and storage — a full open-source backend in minutes.
- Isar — a blazing-fast local NoSQL database with full-text search.
- go_router — declarative routing with deep links and guards, officially backed.
See what's trending, live
Want to know which Flutter and Dart repos are climbing right now? We built a live leaderboard that pulls straight from the GitHub API every time you open it: fluttercook.github.io/trends. It ranks the most-starred and fastest-rising projects across AI, apps and packages.
FlutterCook is publishing 100 hands-on guides to the best open-source Flutter libraries — AI-first. Each one ships with a runnable demo. Follow along and grab the code at github.com/fluttercook, and browse live demos at fluttercook.github.io.
Tags: Flutter, Dart, open source, AI, LLM, on-device AI, state management, libraries, packages
Run Gemma On-Device in Flutter with flutter_gemma
What if your app could chat with a real large language model that runs entirely on the phone — offline, private, and free to run? That is exactly what flutter_gemma unlocks: it loads Google's open Gemma models and runs inference directly on-device, so no text ever leaves the handset and there is no per-token cloud bill.
Why on-device AI matters in 2026
Cloud LLM APIs are powerful, but they come with three recurring costs: privacy
(user data is sent to a server), latency (a network round-trip per message), and
money (you pay per token, forever). For a large class of features — smart replies,
summarization, offline assistants, on-device search — a small model running locally
is faster, cheaper, and dramatically more private. flutter_gemma brings
that capability to Flutter with GPU acceleration and multimodal support.
Installing the package
Add it to your pubspec.yaml:
dependencies:
flutter_gemma: ^0.9.0
Then place a Gemma model file (for example a quantized .task or
.bin Gemma variant) in your assets or download it at runtime. Small
quantized models keep the download light while still being genuinely useful.
A minimal on-device chat
Here is the shortest path from "nothing" to "streaming answers on-device":
import 'package:flutter_gemma/flutter_gemma.dart';
// 1. Load a model that lives on the device.
final gemma = FlutterGemmaPlugin.instance;
await gemma.modelManager.installModelFromAsset('gemma-2b-it.bin');
// 2. Create an inference model + a chat session.
final model = await gemma.createModel(
modelType: ModelType.gemmaIt,
maxTokens: 1024,
);
final chat = await model.createChat(temperature: 0.7);
// 3. Ask a question and stream tokens back.
await chat.addQuery(Message.text(text: 'Explain Flutter in one sentence.'));
await for (final token in chat.generateChatResponseAsync()) {
stdout.write(token.token); // append to your chat bubble
}
That is the whole loop: install a model, open a chat, stream the response. No API
key, no server, no network permission required. Wire the token stream into a
ListView of chat bubbles and you have a private assistant.
Live demo
See a working UI for this pattern here: fluttercook.github.io/demos/flutter_gemma, with the full runnable source on github.com/fluttercook.
Gotchas worth knowing
- Model size vs. device RAM. Pick a quantized 2B-class model for phones; larger models need more memory and warm-up time.
- First-run latency. Loading the model takes a moment — show a warm-up state and keep the model in memory between messages.
- GPU delegate. Enable GPU acceleration where available for a big speed-up over CPU inference.
- Licensing. Review the Gemma model license before shipping a bundled model.
The takeaway
flutter_gemma turns "add AI to my app" from a recurring cloud
expense into a one-time, on-device capability. It is one of the most exciting tools
in the Flutter AI ecosystem right now, and a perfect starting point if you care about
privacy, offline support, or cost. Try the demo, drop the snippet into a project,
and you will have a working local chatbot in an afternoon.
FlutterCook is publishing 100 hands-on guides to the best open-source Flutter libraries — AI-first. Follow along and grab every runnable demo at github.com/fluttercook.
Package: pub.dev/packages/flutter_gemma · Tags: Flutter, AI, LLM, on-device AI, Gemma, privacy
About This Blog
Search This Blog
Topics
- 3D (2)
- A19 Pro (2)
- Agent Skills (2)
- AI (7)
- AI/ML (17)
- Android 17 (4)
- Animation (10)
- App/Template (11)
- Apple (8)
- Apple Intelligence (2)
- Backend (1)
- Backend/Data (11)
- Bản phát hành (1)
- Canvas (2)
- Cupertino (4)
- CustomPaint (2)
- Dart (5)
- Dart 3.13 (2)
- Design (1)
- Desktop (6)
- DevTools (2)
- dio (1)
- Đồ hoạ (1)
- flutter (6)
- Flutter (133)
- Flutter 3.44 (2)
- Flutter 3.47 (22)
- flutter_gemma (1)
- Foldable iPhone (1)
- Foldables (1)
- Gemini (5)
- Gemma (1)
- GetX (1)
- Google (2)
- google_generative_ai (1)
- Graphics (1)
- Hardware (1)
- Hiệu năng (2)
- Hướng dẫn (1)
- Impeller (6)
- iOS (4)
- iOS 26 (6)
- iPhone 17 Pro (2)
- iPhone 18 Pro (2)
- iPhone gập (1)
- Language (1)
- Learning/Awesome (5)
- libraries (1)
- Library/Tooling (26)
- Linux (2)
- Liquid Glass (2)
- LLM (3)
- Lộ trình (1)
- macOS 26 (2)
- Material (4)
- Máy gập (1)
- Migration (4)
- Ngôn ngữ (1)
- on-device AI (1)
- open source (3)
- Performance (2)
- Phần cứng (1)
- Phát hành (1)
- Plugin (1)
- Plugins (1)
- Refactoring (2)
- Release (2)
- Roadmap (1)
- Rumors (1)
- Smart TV (2)
- state management (2)
- State management (5)
- Swift Package Manager (2)
- Tahoe (2)
- Thiết kế (1)
- Tin đồn (1)
- Tooling (4)
- Tutorial (1)
- UI (2)
- UI/Components (18)
- UIScene (2)
- Web (6)
- WebAssembly (4)
- Widget Preview (2)
- Windows (2)
Popular Posts
-
What if your app could chat with a real large language model that runs entirely on the phone — offline, private, and free to r...
-
🌐 English · Tiếng Việt 📌 In summary ez_tickets_app is an open-source UI component library in the UI/Components category. It has 439★ ...
-
The Flutter ecosystem moves fast, and in 2026 the most exciting momentum is around on-device AI . This is a hands-on tour of th...
-
🌐 English · Tiếng Việt 📌 In summary Fable is an open-source developer tooling library in the Library/Tooling category. It has 3,133★ ...
-
🌐 English · Tiếng Việt 📌 In summary eso is an open-source backend & data library in the Backend/Data category. It has 1,775★ and...
-
🌐 English · Tiếng Việt 📌 In summary Echo-Loop is an open-source AI/ML toolkit in the AI/ML category. It has 1,975★ and 193 forks, an...
-
🌐 English · Tiếng Việt 📌 In summary BloomeeTunes is an open-source state-management library in the State management category. It has ...
-
🌐 English · Tiếng Việt 📌 In summary audioplayers is an open-source backend & data library in the Backend/Data category. It has 2,...
-
🌐 English · Tiếng Việt 📌 In summary AAA is an open-source open-source app / starter template in the App/Template category. It has 3,0...
macOS 26 Tahoe: Liquid Glass comes to the Mac — and it's the last stop for Intel
macOS 26, named Tahoe , is Apple’s current Mac operating system, and it carries two stories at once. The first is cosmetic and immediate: th...
Blog Archive
- August 2026 (40)
- July 2026 (109)
- July 2024 (1)