Build AI features in Flutter with Gemini and the Dart MCP server in 2026

How to add Gemini to a Flutter app with Firebase AI Logic and the AI Toolkit, and how the Dart MCP server lets an agent build and hot reload your app.

Read time
13 min
Word count
2.1K
Sections
10
FAQs
8
Share
Glass tablet on a dark studio surface with glowing neural filaments flowing into its screen
AI features flowing into a mobile app, and an agent building it.
On this page · 10 sections
  1. Path one: add Gemini to your app with Firebase AI Logic
  2. Path two: ship a chat interface with the Flutter AI Toolkit
  3. Path three: build the app itself with the Dart MCP server
  4. A concrete feature, end to end
  5. Choosing your setup
  6. Costs, security, and India considerations
  7. Common pitfalls to avoid
  8. FAQ
  9. How eCorpIT can help
  10. References

Summary. Gemini shows up in Flutter two ways in 2026, and they solve different problems. Inside your app, Firebase AI Logic gives the Dart SDK a direct line to Gemini models for text, image, audio, and video, and the Flutter AI Toolkit, first shipped in December 2024, drops in a full chat interface over that. Around your app, the Dart and Flutter MCP server, announced with Dart 3.12 at Google I/O 2026, lets a coding agent read your code, run tests, and hot reload the running app with zero configuration. The pricing is concrete: Gemini 2.5 Flash costs $0.30 per million input tokens and $2.50 per million output, Gemini 2.5 Pro runs $1.00 and $10.00, and Gemini 2.5 Flash-Lite is $0.10 and $0.40, with a Gemini 3 Flash preview around $0.50 per million input. For a team paying a Flutter developer $20 to $30 an hour in India, the model bill is usually the smaller line item, and the agent that writes the glue code is where the hours move. This guide covers both halves: adding Gemini features to a Flutter app, and using AI to build the app itself.

The two paths overlap in name and diverge in purpose, which is where teams get confused. One is a runtime dependency your users hit. The other is a developer tool your engineers hit. You can adopt either without the other, and most production teams end up using both. Our recap of what Google I/O 2026 meant for Flutter and Gemini sets the wider context; this guide is the hands-on version.

Path one: add Gemini to your app with Firebase AI Logic

If you want a Flutter app to call Gemini, Firebase AI Logic is the current answer. It provides client SDKs, a proxy service, and security controls that let a mobile or web app reach Google's generative models without you standing up a backend. The SDKs cover Swift, Kotlin and Java, JavaScript, Unity, and Dart for Flutter, and the Dart package is firebase_ai.

There is a history worth knowing. The earlier path was the google_generative_ai package, which called the Gemini API directly with a key generated in Google AI Studio. That works for a prototype, but shipping an API key inside a mobile app is a security problem. Google now advises migrating from the Google AI client SDKs to Firebase AI Logic, which keeps the key off the device and adds Firebase App Check to block unauthorized clients. If you have a Flutter app still calling google_generative_ai in production, treat the migration as a security task, not a nice-to-have.

A minimal call with firebase_ai looks like this:


            import 'package:firebase_ai/firebase_ai.dart';

final model = FirebaseAI.googleAI().generativeModel(
  model: 'gemini-2.5-flash',
);

final response = await model.generateContent([
  Content.text('Summarize this support ticket in one sentence.'),
]);

print(response.text);
          

Firebase AI Logic exposes two endpoints behind the same SDK. The Gemini endpoint is meant for prototyping and consumer apps, and the Vertex AI endpoint is meant for production workloads that need enterprise controls and quotas. You switch endpoint without rewriting your calls, which is the point of routing through Firebase rather than hand-rolling HTTP.

Picking a Gemini model and knowing the bill

Model choice is a cost and latency decision. Gemini 2.5 is the current production line, in three sizes, with a Gemini 3 Flash preview available for teams that want the next generation early. The prices below are the Gemini Developer API rates as of July 2026.

Model Input, $ per million tokens Output, $ per million tokens Best for
Gemini 2.5 Flash-Lite 0.10 0.40 High-volume, simple classification and extraction
Gemini 2.5 Flash 0.30 2.50 The balanced default for most app features
Gemini 2.5 Pro 1.00 10.00 Deep reasoning, long context, and code
Gemini 3 Flash (preview) 0.50 preview pricing Early access to the next generation

The practical rule: start on Flash, drop to Flash-Lite for high-volume simple calls, and reserve Pro for features that genuinely need reasoning. Output tokens cost far more than input across the line, so the cheapest optimization is usually asking for shorter answers, not switching models.

Path two: ship a chat interface with the Flutter AI Toolkit

Most teams that add Gemini want a chat window, and building one from scratch means rebuilding streaming, message history, attachments, and voice input every time. The Flutter AI Toolkit, introduced in December 2024, is a set of chat widgets that give you that window in a few lines. It is organized around an abstract LLM provider API, so you can swap the model backend, and it supports Firebase AI Logic out of the box.

What you get without writing it yourself is substantial: multiturn chat that keeps context across messages, streaming responses that appear token by token, voice input, multimedia attachments, function calling to your own tools, chat serialization so conversations survive between sessions, and custom response widgets for rich replies. It runs on Android, iOS, web, and macOS, and it supports both the Gemini endpoint for prototyping and the Vertex endpoint for production, matching the Firebase AI Logic split.

The design choice that matters is the provider abstraction. Because your UI talks to a provider interface rather than a specific model SDK, moving from the Gemini endpoint in development to the Vertex endpoint in production, or swapping models entirely, does not touch your widget code. For most product teams, the AI Toolkit plus Firebase AI Logic is the fastest route from idea to a shippable AI chat feature, and it is where I would start a new build.

Path three: build the app itself with the Dart MCP server

The second meaning of "AI in Flutter" is using AI to write the Flutter. The Dart and Flutter MCP server, announced with Dart 3.12 at Google I/O 2026, exposes Dart and Flutter tooling to AI-assistant clients through the Model Context Protocol, the open standard for connecting tools to AI agents. Instead of an agent guessing at your project, it can query the analyzer, run the formatter, add packages through pub, run tests, capture screenshots, and trigger hot reload, all as real actions against your workspace.

The standout feature is agentic hot reload. The Flutter team describes it as a capability "designed to keep you and your coding agent in flow." In practice, you prompt an agent to fix a bug or change a widget, and it modifies the code, pulls live runtime diagnostics, and hot reloads the running app without you copying a Dart Tooling Daemon connection URI by hand. The daemon exposes the connection through a CLI command the MCP server runs, so the agent discovers and connects to your running app with zero configuration.

Setup is a short client config. The server starts with the Dart CLI, and you register it with a compatible client such as Gemini CLI, Cursor, GitHub Copilot, or Antigravity:


            {
  "mcpServers": {
    "dart": {
      "command": "dart",
      "args": ["mcp-server"]
    }
  }
}
          

Dart 3.12 also brought language changes that pair well with agent-written code, including private named parameters and experimental primary constructors, which cut the boilerplate an agent has to generate and you have to review. The Flutter "Create with AI" guide is the official entry point, covering Gemini Code Assist, Gemini CLI, and the MCP server together.

A concrete feature, end to end

Here is the shape of a real feature, an AI summary of a support ticket, built the way I would ship it. The runtime path has five steps, and none of them needs a custom backend.

First, add the firebase_ai package to pubspec.yaml and run flutter pub get. Second, initialise Firebase in your app and turn on Firebase App Check, so only builds you shipped can call the model. Third, create the model once and reuse it, choosing Gemini 2.5 Flash as the default for a summarisation task that does not need Pro-level reasoning. Fourth, call the model and stream the result so the summary appears as it is generated rather than after a pause:


            final stream = model.generateContentStream([
  Content.text('Summarize this ticket for an agent:\n$ticketBody'),
]);

await for (final chunk in stream) {
  setState(() => summary += chunk.text ?? '');
}
          

Fifth, handle the failure cases explicitly: a network timeout, a safety block, or an empty response. A model call is a network call, and treating it as one, with a loading state, a retry, and a fallback message, is the difference between a demo and a feature. If the same screen also needs a back-and-forth conversation rather than a one-shot summary, switch to the Flutter AI Toolkit and let its chat widget own the streaming and history instead of writing that loop yourself.

The cost of this feature is easy to bound. A ticket summary might send 800 input tokens and return 60 output tokens, so at Gemini 2.5 Flash rates the marginal cost is a fraction of a cent per summary. The engineering cost, wiring App Check, error states, and the UI, is the part worth estimating carefully, and the part the Dart MCP server shortens.

Choosing your setup

Match the tool to the job. These paths compose, but each has a clear primary use.

Your goal Use Why
Add Gemini to an app with no backend Firebase AI Logic (firebase_ai) Client SDK keeps the key off-device, adds App Check
Ship an AI chat window fast Flutter AI Toolkit Prebuilt chat widgets over a provider API
Prototype against Gemini quickly Gemini endpoint via Firebase AI Logic Fastest path, swap to Vertex for production
Run production with governance Vertex endpoint via Firebase AI Logic Enterprise controls, quotas, and per-project limits
Let an agent edit and hot reload Dart and Flutter MCP server Agentic hot reload with zero configuration
Call Gemini directly, no Firebase google_generative_ai (legacy) Older path; migration to Firebase AI Logic advised

The common production shape is Firebase AI Logic for the runtime calls, the AI Toolkit when the feature is conversational, and the Dart MCP server in the development loop. None of the three locks out the others, and adopting one does not commit you to the rest.

Costs, security, and India considerations

The cost model has two lines: the Gemini tokens your app consumes at runtime, and the engineering time to build it. Token costs are predictable from the table above and scale with usage; a chat feature on Gemini 2.5 Flash at $0.30 input and $2.50 output per million tokens is cheap until it is popular, at which point Flash-Lite for the simpler calls matters. Engineering time is the larger variable, and a Flutter developer in India bills roughly $20 to $30 an hour at mid level, which is where the Dart MCP server pays back by compressing the edit-run-fix loop.

Security and privacy are not optional. Routing through Firebase AI Logic instead of google_generative_ai keeps your API key off the device and lets App Check reject clients you did not ship, which is the single most important production hardening for a client-side AI app. On privacy, remember that prompts sent to Gemini leave the device. If your Flutter app sends user content, personal data covered by the Digital Personal Data Protection Act 2023 should be handled with consent and minimisation in mind, and sensitive fields should be redacted before they reach any model. Design the data flow first, then wire the model in. For the cross-platform performance side of Flutter that sits underneath all of this, our Impeller renderer note and the Flutter web with WebAssembly guide cover the runtime, and our enterprise AI strategy guide covers the governance layer.

Common pitfalls to avoid

A few mistakes show up in almost every first Flutter AI build. Shipping the google_generative_ai package to production with an embedded API key is the most serious, because anyone can extract the key from the app and spend against it; route through Firebase AI Logic instead. Skipping Firebase App Check leaves your endpoint open to clients you did not ship, which is the same problem wearing a different hat. Returning the whole model response at once, rather than streaming it, makes the feature feel slow even when it is not, because the user stares at a spinner while tokens generate.

On cost, defaulting every call to Gemini 2.5 Pro is a common way to turn a cheap feature into an expensive one; most app calls belong on Flash or Flash-Lite, and only reasoning-heavy work needs Pro. On privacy, sending raw user content to a model without redacting personal fields is both a data-protection risk under the Digital Personal Data Protection Act 2023 and an unnecessary one, since most features only need the relevant slice of the input. Watch quotas too: the Gemini endpoint has rate limits that a sudden traffic spike can hit, so plan the Vertex endpoint and per-project quotas before a launch, not during one. Finally, treating the model as deterministic leads to brittle interfaces; the same prompt can return differently worded output, so parse defensively and never assume a fixed structure unless you constrain the response format. Each of these is cheap to fix at the start and expensive to retrofit after launch.

FAQ

How eCorpIT can help

eCorpIT is a CMMI Level 5, Gurugram-based engineering organisation that ships production Flutter with senior-led teams. We wire Gemini into apps through Firebase AI Logic with App Check and sensible model choices, build conversational features on the Flutter AI Toolkit, and set up the Dart MCP server in your team's workflow so an agent speeds delivery without touching your governance. If you are planning AI features in a Flutter app, talk to our team and we will map the models, costs, and privacy controls for your case.

References

  1. Dart and Flutter MCP server, Flutter documentation
  1. Supercharge your Dart and Flutter development with the Dart MCP server, Flutter blog
  1. Announcing Dart 3.12, Dart blog
  1. Create with AI, Flutter documentation
  1. Firebase AI Logic, Firebase
  1. Get started with the Gemini API using the Firebase AI Logic SDKs, Firebase
  1. Migrate to the Firebase AI Logic SDKs from the Google AI client SDKs, Firebase
  1. Supported models, Firebase AI Logic
  1. Flutter AI Toolkit, Flutter documentation
  1. Gemini Developer API pricing, Google AI for Developers
  1. Google Gemini API pricing, July 2026, TLDL
  1. Flutter Developer Hourly Rate in 2026, Aalpha

_Last updated: 7 July 2026._

Frequently asked

Quick answers.

01 How do I add Gemini to a Flutter app in 2026?
Use Firebase AI Logic with the firebase_ai Dart package. It gives your app a client SDK to Gemini models for text, image, audio, and video without a custom backend, and adds Firebase App Check to block unauthorized clients. Initialize a model, call generateContent with your prompt, and read the response text.
02 What is the Dart MCP server?
The Dart and Flutter MCP server, announced with Dart 3.12 at Google I/O 2026, exposes Dart and Flutter tooling to AI agents through the Model Context Protocol. An agent can query the analyzer, run tests, manage packages, capture screenshots, and hot reload your running app, turning an assistant into one that takes real actions in your workspace.
03 Should I use google_generative_ai or Firebase AI Logic?
Use Firebase AI Logic for anything shipping to users. The older google_generative_ai package embeds a Gemini API key in the app, which is a security risk. Google advises migrating to the Firebase AI Logic client SDKs, which keep the key off-device and add App Check. Keep google_generative_ai only for quick local prototypes.
04 What does the Flutter AI Toolkit do?
The Flutter AI Toolkit, shipped in December 2024, is a set of chat widgets that add an AI chat window to your app. It handles multiturn context, streaming responses, voice input, attachments, function calling, and chat storage. It works on Android, iOS, web, and macOS, and supports Firebase AI Logic with both Gemini and Vertex endpoints.
05 How much does Gemini cost for a Flutter app?
As of July 2026, Gemini 2.5 Flash costs $0.30 per million input tokens and $2.50 per million output, Gemini 2.5 Pro is $1.00 and $10.00, and Gemini 2.5 Flash-Lite is $0.10 and $0.40. Output tokens dominate the bill, so shorter responses cut cost more than switching models for most apps.
06 What is agentic hot reload?
Agentic hot reload is a Dart MCP server feature that lets a coding agent modify your code, fetch live runtime diagnostics, and hot reload the running app automatically. The Dart Tooling Daemon exposes the connection through a CLI command, so the agent connects with zero configuration, removing the manual step of copying a connection URI.
07 Which coding agents work with the Dart MCP server?
The Dart and Flutter MCP server works with MCP-compatible clients including Gemini CLI, Cursor, GitHub Copilot, and Antigravity. You register the server with a short config entry that runs the dart mcp-server command, and the agent then has access to analysis, testing, package management, and hot reload for your project.
08 Is my users' data safe when calling Gemini from Flutter?
Prompts sent to Gemini leave the device, so treat the data path carefully. Route calls through Firebase AI Logic to keep your key off-device and enable App Check. Under the Digital Personal Data Protection Act 2023, obtain consent and minimise personal data, and redact sensitive fields before they reach any model rather than after.

About the author

Manu Shukla

Founder & Director

Founder of eCorpIT. Hands-on engineer leading senior-only delivery for AI apps, custom software, and cloud systems for global clients.

Subscribe

One engineering note a week. No fluff, no spam.

Senior-architect playbooks on AI agents, mobile apps, cloud, security, data, and marketing — delivered every Wednesday.

Past the reading

Read enough. Let's build something.

A senior architect responds in 24 working hours with scope, indicative cost, and a timeline. NDA before any technical conversation.