The firebase_vertexai package that many Flutter AI tutorials still install is now marked discontinued on pub.dev. That small detail says a lot about this topic. Getting a model to answer in a demo is easy, but keeping that feature working for real users takes a lot more work.
This guide shows you how to add AI to Flutter app features that survive real traffic. The short version is eight steps. Use the firebase_ai package with App Check, load the model name from Remote Config, and validate every input and output. Then stream replies, cap usage per user, and add the report button and consent screen the app stores expect.
One scope note before you start. This guide covers AI that runs inside your app, such as a support assistant or a receipt reader. For AI that helps you write the code, see our list of the best AI tools for Flutter.
Key takeaways
- Use firebase_ai (Firebase AI Logic) today, since google_generative_ai is deprecated and firebase_vertexai is discontinued.
- Turn on Firebase App Check so your Gemini API key stays on Google's servers and unknown clients get blocked.
- Load the model name from Remote Config, because Google retires models on a schedule and users update apps slowly.
- Treat every model reply as untrusted input, and build the fallback before the feature.
- Google Play requires in-app reporting for AI-generated content, and Apple requires explicit consent before personal data goes to a third-party AI.
What do you need before you start?
Gather these six things before step one, because each of them prevents rework later.
- A Flutter project on a current stable release. Flutter 3.50, released on 11 November 2026, is the latest.
- A Firebase project connected to your app for Android, iOS and any other platform you ship.
- At least one physical Android phone and one iPhone, since App Check attestation is built for real devices.
- A one-paragraph spec of the feature, including what happens when the model fails.
- A privacy policy that names the AI provider and the data you send to it.
- One person on your side who owns the cloud bill and receives billing alerts.
Step 1. Decide whether the feature needs AI at all
AI fits tasks that are shaped like language. Summarizing long content, answering scoped support questions and reading a photo of a receipt are good examples. A model is the wrong tool when an answer must be exactly right and a wrong one cannot be undone.
Write the spec as input, output and failure behavior. For example, a user pastes a long email, the app returns a three-bullet summary, and the original email stays visible if the model fails.
Expected result. You have a one-paragraph spec with a named fallback for every failure case.
Common mistake. Teams let a model compute account balances, medication doses or prices that a user will act on. Fix. Keep those numbers in normal code, and let AI only explain or summarize them.
Step 2. Install firebase_ai and connect Firebase
The current package is firebase_ai, shown on its firebase_ai package page from Google's verified Firebase publisher at version 5.2.0. It is the Flutter plugin for Firebase AI Logic, which Google renamed from Vertex AI in Firebase in May 2025.
Firebase AI Logic talks to two providers through the same code. The Gemini Developer API has a free tier for getting started. The Agent Platform Gemini API, formerly Vertex AI, is the other option, and switching takes a few lines of setup code. Both are covered in the Firebase AI Logic documentation.
Expected result. A test prompt sent from a debug build returns text in your app.
Common mistake. Older tutorials tell you to add google_generative_ai or firebase_vertexai. The first is deprecated with no further changes planned, and the firebase_vertexai listing marks it discontinued. Fix. Remove both packages from your pubspec file and depend on firebase_ai only.
Step 3. Turn on App Check before anyone else can call the API
Never ship a model API key inside the app, because anyone can extract it from a release build. Firebase AI Logic keeps your Gemini API key on the server and proxies requests for you. App Check then proves each request came from your genuine app.
For Flutter, the default App Check providers are Play Integrity on Android, DeviceCheck on Apple platforms and reCAPTCHA v3 on the web. Enforce App Check for Firebase AI Logic once your metrics show real traffic passing.
Expected result. The App Check console shows verified requests, and calls from a script without a valid token are rejected.
Common mistake. AI calls start failing on emulators and CI runners after enforcement. Fix. Use the App Check debug provider in debug builds, and register each debug token in the Firebase console.
Step 4. Pick a model and load its name from Remote Config
Gemini models come in tiers, and the tier sets both cost and speed. Flash-class models are fast and cheap, Flash-Lite models suit high volume, and the larger models cost more and respond more slowly. Start every feature on a current Flash-class model, and move a feature up only after you prove the quality gap.
Do not hard-code a model version from a blog post, including this one. The Firebase AI Logic models page lists what is current and what is retiring. For example, Google shut down the Gemini 2.5 Pro, Flash and Flash-Lite models on Agent Platform on 20 October 2026.
Google's docs recommend explicit, pinned model names for production rather than aliases that change underneath you. They also strongly recommend changing the model name with Remote Config, because many users never update to your latest release.
Expected result. You can switch every installed copy of the app to a new model from the Firebase console, with no store release.
Common mistake. Teams hard-code the model string in Dart, and old app versions break when that model retires. Fix. Read the model name from Remote Config with a safe default, and retest your prompt on each new model before you switch.
Step 5. Validate what goes in and what comes out
Flutter's AI best practices guide makes a simple point. Expect the model to get things wrong eventually, and use Flutter to build guardrails around it.
Before sending, reject empty prompts, cap the length and screen for obvious injection text such as "ignore your previous instructions". That check costs nothing and saves the API call.
After receiving, check why the model stopped. A normal finish is safe to show. A safety block should produce a plain message, and a cut-off reply means you hit the output limit.
For structured data, ask for JSON that matches a schema, then parse and check it before it reaches your UI. When the model needs real data, such as an order status, use function calling. The model asks your app to run a named function and sees only what that function returns.
Expected result. Empty, oversized and blocked requests all show a clear message instead of an error or a blank card.
Common mistake. The app renders whatever comes back, so a safety block shows an empty bubble. Fix. Handle each finish reason as its own UI state, and let users correct AI-generated data where accuracy matters.
Step 6. Stream replies and build the fallback first
Treat AI as an extra layer on top of a feature that already works. If the model is down, slow or rate-limited, the user should still finish the task. A smart reply box can fall back to a plain text field, and a failed summary can show the original content.
Generative replies usually take seconds, not milliseconds. Streaming shows the reply word by word as it arrives, so the wait feels like a conversation. Check connectivity before you show the AI entry point, and explain clearly when the feature is paused offline.
Streaming text also needs careful state handling, so that partial replies do not trigger needless rebuilds across the screen.
Expected result. With the network turned off, the screen still works and explains why the AI part is unavailable.
Common mistake. A full-screen spinner blocks the user until the whole reply arrives. Fix. Stream by default for anything generative, and keep the rest of the screen usable.
Step 7. Cap cost per user and set billing alerts
These APIs bill by tokens, which are roughly the words in your prompt plus the words in the reply. Ten test calls cost almost nothing, but thousands of daily users change the math quickly.
A long system instruction adds its cost to every single request. Sending the full chat history on every turn also grows the bill as conversations get longer. Keep the system instruction short, and send only a sliding window of recent turns.
Firebase AI Logic applies rate limits per user by default, and you can configure them. Set those limits to match your plan, and set budget alerts on the Google Cloud billing account before launch.
Expected result. A single user hitting the feature in a loop gets throttled, and your billing owner gets an alert before the budget runs out.
Common mistake. Teams rely on an in-memory counter in the app, which resets every time the app restarts. Fix. Enforce limits on the server side through Firebase AI Logic's per-user limits or your own backend.
Step 8. Meet the Google Play and App Store AI rules
Store rules are where many AI features get rejected or pulled. Google Play's AI-Generated Content policy says apps that generate content with AI must include in-app reporting or flagging for offensive content. A report button on each AI reply meets that mechanism if reports reach a person who reviews them.
Apple's App Review Guidelines cover AI in two places. Guideline 1.2 lists AI content creation apps under user-generated content, which brings filtering, reporting and blocking duties. Guideline 5.1.2(i) requires you to disclose when personal data goes to third-party AI and to get explicit permission first.
Expected result. Every AI reply has a report control, and first use of the feature shows a clear consent screen naming the provider.
Common mistake. The AI disclosure lives only in the privacy policy. Fix. Add an in-app consent step before the first request, and make sure your privacy policy and App Store privacy details say the same thing.
How do you check that the whole AI feature works?
Run this final check on a release build, on physical devices, before you submit to either store.
| Check | How to test it | Pass condition |
|---|---|---|
| Package | Search pubspec.yaml for old AI packages | Only firebase_ai is present |
| App Check | Call the API from a script without a token | The request is rejected |
| Model switch | Change the model name in Remote Config | The app uses the new model without an update |
| Guardrails | Send an empty prompt, a huge prompt and an injection attempt | Each shows a clear message |
| Offline | Turn on airplane mode and open the screen | The core task still works |
| Cost limits | Fire requests in a loop from one test account | The account is throttled |
| Store rules | Use the feature for the first time and report a reply | Consent appears first, and the report reaches a reviewer |
If every row passes, the feature is ready for review. If you need on-device models instead of cloud calls, read what on-device AI costs in app size and installs before you change course.
When is it worth bringing in a Flutter AI team?
The model call is usually the smallest part of the estimate. Most of the effort goes into the service boundary, state handling for streams, App Check, limits, store compliance and fallbacks.
Our Flutter case studies include an AI Trip Planner App and an AI-Powered Fitness App. If your team is short on time, an outside team can take on the production layer while your developers own the product.
Frequently asked questions
Which package should I use to add AI to a Flutter app?
Use firebase_ai, the Flutter plugin for Firebase AI Logic. It replaces google_generative_ai, which is deprecated, and firebase_vertexai, which is discontinued. The same code works with the Gemini Developer API and the Agent Platform Gemini API.
Do I need Firebase to build AI features in Flutter?
Not strictly, but you do need a server between the app and the model. Firebase AI Logic with App Check gives you that server without writing your own backend. Calling a model API directly from the app means shipping a key that anyone can extract.
Which Gemini model should a production Flutter app use?
Start with a current Flash-class model, and move individual features to a larger model only when tests prove the need. Check the Firebase AI Logic models page for what is current, because Google retires models on a published schedule. Load the model name from Remote Config so you can switch without an app update.
What do Google Play and the App Store require for AI features?
Google Play requires in-app reporting or flagging for AI-generated content. Apple treats AI content creation apps as user-generated content, and it requires disclosure and explicit permission before personal data goes to a third-party AI. Both stores still apply all their other rules to AI features.
How do I keep AI feature costs under control?
Keep the system instruction short and send only recent conversation turns, because you pay for every token. Configure the per-user rate limits in Firebase AI Logic, and set billing alerts before launch. Test a looping request from one account to confirm the limits work.
Ship the feature, then keep it healthy
Adding AI to a Flutter app is mostly about the layer around the model. Use the current package, lock down access, plan for model retirement and give users a way to report bad output. If you want help with that layer, talk to our Flutter AI app development team.





