Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Gemini in your Flutter app with Firebase AI Logic

Gemini in your Flutter app with Firebase AI Logic

What if you could add gen AI to your Flutter app today, calling Gemini directly from your Dart code with no backend to build or maintain? Firebase AI Logic makes this possible, already trusted by thousands of apps in the App Store and Play Store, serving millions of requests. In this session, you will go from zero to a working AI feature in minutes: generate text, images, and structured output, stream live conversations, and call tools, all from the client. Then we will make it production-ready: protect your app with App Check, update prompts instantly with Server Prompt Templates, and understand usage with AI Monitoring. Be ready to ship AI features your users will love.

Avatar for Rosário P. Fernandes

Rosário P. Fernandes

October 07, 2026

More Decks by Rosário P. Fernandes

Other Decks in Programming

Transcript

  1. Gemini in your Flutter app with Firebase AI Logic Fluttercon

    Berlin, October, 2026 Miguel Ramos Rosário Fernandes Senior Product Manager Firebase @Google Developer Relations Engineer Firebase @Google 1
  2. What gen AI experience are you building? Proofreading content (grammar

    and spelling  Summarize a long text   errors) Generate or modify images based on a description Rewrite a text with specific tone or style  Find the timestamp of a specific scene in a  Generate a short description of a given image  criteria Recommend items from a list based on simple  Generate a transcription from an audio file  Translating text between different languages  Generate an audio from a text  video Analyze patterns from a small text and extract  data info AI conversation with video/audio  Real-time input & output Solving self-contained & well-defined tasks
  3. Common Challenges & Needs  API Key Security Gemini API

    keys must never reside on client devices, as they can be easily extracted from binaries or intercepted in transit.  Updating Models Hardcoding model names and prompts in binaries breaks app features when older models are decommissioned and end users don't update their apps.  File Privacy File uploads lack user-level access controls, risking cross-user data exposure, and not enforcing per-user security boundaries before sending files to the model.
  4. Service layer < /> Gemini API providers Google Gen AI

    SDK ADK, LangChain, etc It works! You owns a backend though
  5. Dart / Flutter Firebase client SDKs < /> Gemini API

    providers Firebase AI Logic Accelerate the time-to-market and reduce costs
  6. Enable developers to securely add gen AI to client mobile

    and web apps in production Consumer apps (and B2C) running on untrusted devices GA since 2024
  7. import 'package:firebase_core/firebase_core.dart'; import 'package:firebase_app_check/firebase_app_check.dart'; import 'package:firebase_ai/firebase_ai.dart'; import 'firebase_options.dart'; Future<void> _generate()

    async { final model = FirebaseAI.googleAI().generativeModel( 1 model: 'gemini-3.8-flash', ); 2 final response = await model.generateContent([ Content.text('Write a story about a magic backpack'), ]); setState(() => output = response.text ?? ''); 3 }
  8. App Check is not optional Illegitimate request ✓ Gemini API

    providers Firebase AI Logic Legitimate request
  9. void main() async { WidgetsFlutterBinding.ensureInitialized(); await Firebase.initializeApp( options: DefaultFirebaseOptions.currentPlatform, );

    await FirebaseAppCheck.instance.activate( providerAndroid: kDebugMode 1 ? const AndroidDebugProvider() : const AndroidPlayIntegrityProvider(), 2 providerApple: kDebugMode ? const AppleDebugProvider() : const AppleAppAttestProvider(), providerWeb: kDebugMode ? WebDebugProvider() : ReCaptchaEnterpriseProvider(_recaptchaEnterpriseSiteKey), ); runApp(const MaterialApp(home: MagicBackpackGenerator())); } Always configure App Check before any Firebase service
  10. Firebase AI Logic overview Other Product Integrations and features Cloud

    Storage, Remote Config, Model Armor, Live APIs, Hybrid inference, AI Monitoring, etc Firebase Auth Firebase client SDKs < /> Firebase AI Logic P4SA to Google AI and Agent Platform Firebase App Check Gemini API providers Template Storage Storyteller-v1 --model: 'gemini-3-flash' input: schema:... tools:... —-{... P4SA to Gemini APIs on server Cloud Function Triggers Server Prompt Templates
  11. Security Prompt < /> System Instructions You're a storyteller that

    tells nice and joyful stories with happy endings. User Prompts Create a story about a cat with the length of 40 words in Spanish language. Full prompt is in the client, even if you got from Remote Config
  12. Server Prompt Templates Firebase AI Logic Template Storage Storyteller-v1 <

    /> Template Name: Storyteller-v1 Parameters: {cat, 200, English} --model: 'gemini-3-flash' input: schema:... tools:... —-{{role "system"}} You're a storyteller that tells nice and joyful stories with happy endings. Prompt Composer {{role "user"}} Create a story about {{topic}} with the length of {{length}} words in the {{language}} language. Prompt Management and reduce prompt injection Gemini API providers
  13. final generativeModel = FirebaseAI.googleAI().templateGenerativeModel(); final responseStream = generativeModel.generateContentStream( 'storyteller-v10', inputs:

    { 'topic': topic, 'length': _length, 'language': _language, }, ); await for (final chunk in responseStream) { final chunkText = chunk.text; if (chunkText != null && mounted) { setState(() { _output += chunkText; }); } } Your client code
  14. Cloud Functions triggers Before Generate Content Request < /> Response

    Request Response Gemini API providers After Generate Content
  15. GenerateContentRequestPayload beforeGenerateContent( AIBlockingEvent<BeforeGenerateContentData> event, ) { final resolved = _resolveUser(event);

    final profile = resolved.profile; final request = event.data.request; Blocking the request if (profile.isFree && (profile.tokensRemaining <= 0 || profile.tokensRemaining < estimatedPromptTokens)) { throw const HttpsError( HttpsErrorCode.resourceExhausted, 'You have used all your Free plan tokens. Upgrade to Pro for unlimited access!', ); } } return request.copyWith( systemInstructionText: resolved.cleanedSystemInstruction, maxOutputTokens: profile.isFree ? freeTierMaxOutputTokensPerTurn : premiumTierMaxOutputTokensPerTurn, );
  16. GenerateContentResponsePayload afterGenerateContent( AIBlockingEvent<AfterGenerateContentData> event, ) { final uid = event.authId;

    final response = event.data.response; if (uid == null || uid.isEmpty) return response; final profile = _userProfilesByUid[uid]; final totalTokens = response.usageMetadata.totalTokenCount; if (profile != null && profile.isFree) { _userProfilesByUid[uid] = profile.copyWith( tokensRemaining: math.max(0, profile.tokensRemaining - totalTokens), totalTokensConsumed: profile.totalTokensConsumed + totalTokens, ); } } return response;
  17. Gemini Live API for conversational interactions Firebase AI Logic stream

    audio/video input stream voice response Your mobile or web app using Firebase client SDKs Gemini API providers Live Gemini API
  18. 1 LiveSession? _session; Future<void> connect({ required void Function(Uint8List pcm24kHz) onAudioChunk,

    required void Function() onInterrupted, }) async { final liveModel = FirebaseAI.googleAI().liveGenerativeModel( model: 'gemini-3.1-flash-live-preview', liveGenerationConfig: LiveGenerationConfig( responseModalities: [ResponseModalities.audio], speechConfig: SpeechConfig(voiceName: 'Fenrir'), ), ); 2 _session = await liveModel.connect(); 3 } _session!.receive().listen((response) { if (response.message case final LiveServerContent content) { for (final part in content.modelTurn?.parts ?? const <Part>[]) { if (part is InlineDataPart && part.mimeType.startsWith('audio/pcm')) { onAudioChunk(part.bytes); } } if (content.interrupted == true) onInterrupted(); } }); Future<void> sendText(String text) async => _session?.send(input: Content.text(text), turnComplete: true); Future<void> sendAudioPcm(Uint8List pcm16Bytes) async => _session?.sendAudioRealtime(InlineDataPart('audio/pcm', pcm16Bytes)); Future<void> sendCameraJpeg(Uint8List jpegBytes) async => _session?.sendVideoRealtime(InlineDataPart('image/jpeg', jpegBytes)); 4 Future<void> disconnect() async => _session?.close(); Reduce the complexity of WebSockets client-server architecture to just a few lines of code
  19. The Challenge Needed to scale a nutrition app to 400k+

    users while maintaining a "science-driven" approach. They required iterate quickly to deliver an MVP and provide fast, photo-based meal logging to help users build consistent habits. The AI Solution Allows users to log meals by taking a photo, which automates the breakdown of complex dishes into ingredient-level data. Business Impact +400k Subscribers Speed 2 Engineers only TECH STACK: Firebase (AI Logic, Auth, Remote Config, Cloud Functions), Flutter, Gemini 2.5 Flash, and Vertex AI.
  20. Developed by The Challenge They faced a high volume of

    manual customer support requests for routine tasks, which was unsustainable for a lean team. The AI Solution Implement a conversational layer within the "Mun Moi" app to allow customers to do things. e.g, retrieve PUK codes, manage subscriptions, and check invoices without human intervention Business Impact Growth Double-digit Boosted Customer Satisfaction with 4-5 stars in mobile stores. TECH STACK: Firebase AI Logic, Flutter, Gemini 2.5 Flash
  21. Call to action 01 Start building. Deploy with the same

    confidence as the thousands of apps today on the production tools. Use App Check, Server 02 Lean Prompt Templates, AI Monitoring, and much more your experience. Let us know how we can 03 Share improve the product