GEMINI LABJP
NANOLITE — Nano Banana 2 Lite is here: Google's fastest and most cost-efficient Gemini Image model, made for running lightweight image generation cheaplyOMNIFLASH — Gemini Omni Flash is in public preview, a natively multimodal model that lets enterprises and developers build custom, dynamic video workflowsAGENTS — Managed Agents expand with background: true for async server-side runs and polling, remote MCP server integration, and refreshing credentials across interactionsMEMORY — The Memory Bank IngestEvents API is generally available, decoupling event ingestion from memory generation so you can stream content continuouslyTHROUGHPUT — Provisioned Throughput now lets you submit up to seven pending orders for the same model and regionDEPRECATE — Image generation models shut down on August 17, and the Grok 4.1 family on the Gemini Enterprise Agent Platform on August 20NANOLITE — Nano Banana 2 Lite is here: Google's fastest and most cost-efficient Gemini Image model, made for running lightweight image generation cheaplyOMNIFLASH — Gemini Omni Flash is in public preview, a natively multimodal model that lets enterprises and developers build custom, dynamic video workflowsAGENTS — Managed Agents expand with background: true for async server-side runs and polling, remote MCP server integration, and refreshing credentials across interactionsMEMORY — The Memory Bank IngestEvents API is generally available, decoupling event ingestion from memory generation so you can stream content continuouslyTHROUGHPUT — Provisioned Throughput now lets you submit up to seven pending orders for the same model and regionDEPRECATE — Image generation models shut down on August 17, and the Grok 4.1 family on the Gemini Enterprise Agent Platform on August 20
Articles/Dev Tools
Dev Tools/2026-03-27Advanced

Notes from Adding a Gemini-powered Chat to a Flutter App I Run Solo — design choices and gotchas across iOS and Android

Working notes from layering Gemini API on top of a Flutter app I've been shipping to iOS and Android as a solo indie developer. Covers monthly cost breakdown (Gemini + Firestore + AdMob), how I recover streamed responses that stall on iOS background, and the practical line for free vs. premium tiering — with code and real numbers.

gemini-api277flutterdartcross-platform3chat-appstreaming28firebase6multimodal44

Premium Article

I've been shipping wallpaper and ambient apps to the iOS and Android stores as an indie developer since 2014, and the cumulative downloads have crossed 50 million. AdMob revenue is what keeps the lights on, so when I started adding a small Gemini-powered chat feature to one of those apps last year, the question wasn't "how do I build the best AI chat?" — it was "how do I add an AI chat that doesn't drag the AdMob math underwater?"

That practical constraint is what this article is really about. I'll cover the Flutter + Gemini code you need to get a streaming chat working across iOS and Android, but I'll keep coming back to numbers from the app I actually run: how much Gemini Flash costs me per month at ~8,000 MAU, how Firestore writes blow up if you save streamed deltas live, and where the AdMob increase from longer sessions started showing up.

Setup and context — why I picked Flutter × Gemini as a solo developer

To set expectations: my apps are AdMob-funded, so the first criterion was "can this be added without dropping eCPM?" Flutter lets me target iOS and Android (and the Web build, with caveats I'll mention later) from one codebase — that matters because, as a solo developer running multiple apps, the time cost of maintaining two native chat implementations would have killed the project before launch.

Gemini Flash at $0.075 / 1M input tokens and $0.30 / 1M output tokens (May 2026 pricing) is the part that made the math work. At an average of 800–1,200 tokens per chat session, the marginal cost stays well under the AdMob lift I'd expect from the extra session time. This is roughly the same calculation I ran when I added a Kotlin-native Gemini integration to a different app — see Gemini API × Kotlin — embedding AI in an Android app for the native-side version of this story.

Environment Setup and Project Configuration

Prerequisites

Before you begin, ensure you have the following ready:

  • Flutter SDK 3.22+ (Dart 3.4+)
  • A Gemini API key from Google AI Studio
  • A Firebase project (for authentication and Firestore)
  • Android Studio or VS Code with Flutter extensions

Creating the Project and Adding Dependencies

Start by creating a Flutter project and adding the required packages:

flutter create gemini_chat_app
cd gemini_chat_app
flutter pub add google_generative_ai
flutter pub add flutter_markdown
flutter pub add image_picker
flutter pub add firebase_core firebase_auth cloud_firestore
flutter pub add flutter_riverpod
flutter pub add envied envied_generator build_runner --dev

Here's what each key package does:

  • google_generative_ai — The official Gemini API Dart SDK. Provides a unified interface for model calls, streaming, and multimodal input
  • flutter_markdown — Renders Gemini's Markdown-formatted responses with rich styling
  • flutter_riverpod — State management for chat history, streaming state, and error handling
  • envied — Obfuscates API keys at compile time to prevent hardcoding exposure

Secure API Key Management

Hardcoding API keys in source code is strictly prohibited. Use the envied package to load keys from environment variables:

// lib/env/env.dart
import 'package:envied/envied.dart';
 
part 'env.g.dart';
 
@Envied(path: '.env')
abstract class Env {
  @EnviedField(varName: 'GEMINI_API_KEY', obfuscate: true)
  static String geminiApiKey = _Env.geminiApiKey;
}

Create a .env file at the project root and add it to .gitignore:

GEMINI_API_KEY=YOUR_GEMINI_API_KEY
dart run build_runner build

This obfuscates the API key within the compiled binary, providing resistance against reverse engineering.

Thank you for reading this far.

Continue Reading

What follows includes implementation code, benchmarks, and practical content we hope you'll find useful. This site runs without ads — server and development costs are supported entirely by members like you. If it's been helpful, we'd be truly grateful for your support.

WHAT YOU'LL LEARN
Real monthly cost breakdown of running Gemini + Firestore in a Flutter app whose revenue is mostly AdMob, with the numbers that actually offset the API spend
The Riverpod + AppLifecycleState pattern I use to recover streamed responses that silently stall when iOS suspends the HTTP/2 socket
Where AdMob and an AI chat feature can coexist without dragging eCPM down — and the MAU threshold where I'd flip to a paid tier instead
Secure payment via Stripe · Cancel anytime

Unlock This Article

Get full access to the rest of this article. Buy once, read anytime. This site is ad-free — your support goes directly toward keeping it running.

or
Unlock all articles with Membership →
Share

Thank You for Reading

Gemini Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.

  • Copy-paste ready implementation code
  • New advanced guides published daily
  • $5/mo or $10 for lifetime access
View Membership →

Related Articles

Dev Tools2026-04-18
Building Cross-Platform AI Desktop Apps with Gemini API and Tauri 2.0
A practical guide to building macOS, Windows, and Linux desktop AI apps using Tauri 2.0 and Gemini API. Learn secure API key management with a Rust backend, real-time streaming via Tauri's event system, and native OS integration with working production code.
Dev Tools2026-06-02
A Lightweight Gemini Backend with Bun and Hono — Reclaiming the Small Tools of Indie Development
Has your Node and Express Gemini backend grown heavy with dependencies and build times? Here is how I moved one to Bun and Hono — folding streaming, rate limiting, cost caps, testing, and self-hosting into a single light runtime — along with the pitfalls I hit in production.
Dev Tools2026-04-18
Gemini API × Kotlin Multiplatform: to Shared AI Logic for iOS and Android
A complete guide to integrating Gemini API with Kotlin Multiplatform (KMP) for shared AI logic across iOS and Android. Covers Gradle setup, Ktor HTTP client, SwiftUI/Compose UI, secure API key management, multimodal image analysis, and production deployment.
📚RECOMMENDED BOOKS
Build a Large Language Model (From Scratch)
Sebastian Raschka
LLM Dev
Prompt Engineering for LLMs
Berryman & Ziegler
Prompting
AI Engineering
Chip Huyen
AI Eng
* Contains affiliate links
See all →