Building AI-powered Flutter apps used to mean managing multiple APIs, handling different SDKs, and reinventing the wheel for every project. Today, there are better ways.
In this guide, we'll explore every approach to adding AI to Flutter — from simple cloud APIs to sophisticated on-device inference — and show you which to use when.
The Problem
Flutter developers want to add AI, but face fragmentation:
- Different API shapes for each provider (Gemini, OpenAI, Claude)
- No standard way to switch between cloud and on-device
- Tool calling, memory, and safety aren't built in
- Vendor lock-in if you choose one provider
The Approaches
1. Direct API Calls (Simple, Limited)
Simplest approach — call cloud APIs directly:
import 'package:google_generative_ai/google_generative_ai.dart';
final model = GenerativeModel(
model: 'gemini-1.5-flash',
apiKey: 'YOUR_KEY',
);
final response = await model.generateContent([
Content.text('What is 1337 * 42?')
]);
print(response.text);
Pros: Quick, minimal code
Cons: Only one provider, no tool calling, no memory, vendor lock-in
2. Firebase ML (Google-Owned, Limited)
Use Firebase ML Kit:
final vision = FirebaseVision.instance;
final imageLabeler = vision.imageLabeler();
final labels = await imageLabeler.processImage(image);
Pros: Built into Firebase ecosystem
Cons: Limited to Google models, no LLMs, no multi-provider support
3. On-Device Models (Privacy-First)
Run Gemma locally:
import 'package:flutter_gemma/flutter_gemma.dart';
final gemma = Gemma();
await gemma.loadModel('gemma-2b');
final response = await gemma.generateText('Hello');
print(response);
Pros: Full privacy, no API calls
Cons: Slow on older devices, large model files, limited model selection
4. Unified SDK (Best of All Worlds) - (genesis_ai_sdk)
Use a multi-provider SDK:
import 'package:genesis_ai_sdk/genesis_ai_sdk.dart';
// Start with Gemini
final agent = GenesisAgent(
provider: GeminiProvider(apiKey: 'YOUR_KEY'),
tools: [GenesisTools.calculator],
);
final response = await agent.chat('What is 1337 * 42?');
print(response);
// Switch to Ollama with ONE line change
final agentLocal = GenesisAgent(
provider: OllamaProvider(model: 'llama3.2'),
tools: [GenesisTools.calculator],
);
Tool calling, memory, and safety all built in.
Comparison Table
| Feature | Direct API | Firebase ML | On-Device | Unified SDK |
|---|---|---|---|---|
| Multiple Providers | ❌ | ❌ | ⚠️ | ✅ |
| Tool Calling | ❌ | ❌ | ❌ | ✅ |
| Persistent Memory | ❌ | ❌ | ❌ | ✅ |
| Safety Guards | ❌ | ❌ | ❌ | ✅ |
| Privacy (On-Device) | ❌ | ❌ | ✅ | ✅ |
| Cloud Support | ✅ | ⚠️ | ❌ | ✅ |
| Setup Complexity | Low | Medium | Medium | Low |
Real-World Use Cases
Travel Assistant (Cloud)
final agent = GenesisAgent(
provider: GeminiProvider(apiKey: 'key'),
tools: [
searchFlights(),
bookHotel(),
getWeather(),
],
);
await agent.chat('Plan a trip to Tokyo for 3 days under $2000');
Email Agent (On-Device + Cloud)
final router = SmartRouter(
primary: OllamaProvider(model: 'mistral'), // Local
secondary: OpenAIProvider(apiKey: 'key'), // Fallback
);
final agent = GenesisAgent(provider: router);
Privacy-First Chatbot (Gemma)
final agent = GenesisAgent(
provider: GemmaProvider(
modelId: 'gemma-2b',
modelPath: await GenesisHubPlatformPaths.platformModelsDir(),
),
memory: HiveMemoryStore(sessionId: 'user_123'),
);
Which Approach Should You Use?
Use Direct API calls if:
- You need just one provider (Gemini, OpenAI)
- Simple, lightweight integration
Use Firebase ML if:
- You're already in the Firebase ecosystem
- Only need vision/speech tasks
Use On-Device if:
- Privacy is non-negotiable
- Users have no internet
- Can accept slower responses
Use a Unified SDK if:
- You want flexibility (cloud + on-device)
- Need tool calling and memory
- Want to avoid vendor lock-in
- Building production apps
Getting Started with genesis_ai_sdk
Multi-provider support means you can start with cloud (fast development) and switch to on-device later (privacy/cost):
dependencies:
genesis_ai_sdk: ^0.1.1
Then pick your provider and go:
// Cloud: Gemini, OpenAI, Claude, HuggingFace
// Local: Ollama, Gemma, GGUF
// Automatic: Fallback between them
final agent = GenesisAgent(provider: YOUR_CHOICE);
Platform support: Android, iOS, macOS, Windows, Linux, Web.
Conclusion
Integrating AI into Flutter apps is no longer complicated. You have options:
- Simple projects? Direct API calls.
- Firebase projects? Firebase ML.
- Privacy-critical? On-device models.
- Everything else? Use a unified SDK.
The future of Flutter AI development isn't picking one provider — it's having the flexibility to use the right tool for the right situation.
Top comments (0)