firebase-ai
$
npx mdskill add evanca/flutter-ai-rules/firebase-aiInitialize Firebase AI Logic for Flutter apps with Gemini models.
- Configures Firebase AI services and handles offline error scenarios.
- Integrates the firebase_ai plugin and Gemini Developer API backend.
- Applies security checks and privacy considerations for AI features.
- Delivers initialized GenerativeModel instances ready for app use.
SKILL.md
.github/skills/firebase-aiView on GitHub ↗
---
name: firebase-ai
description: Integrates Firebase AI Logic into Flutter apps. Use when setting up the firebase_ai plugin, calling Gemini models, handling AI service errors, or applying security and privacy considerations for AI features.
---
# Firebase AI Skill
This skill defines how to correctly use Firebase AI Logic in Flutter applications.
## When to Use
Use this skill when:
* Setting up and configuring Firebase AI in a Flutter project.
* Implementing AI features on supported platforms.
* Handling errors and offline scenarios for AI operations.
* Applying security and privacy considerations for AI features.
---
## 1. Setup and Configuration
```
flutter pub add firebase_ai
```
```dart
import 'package:firebase_ai/firebase_ai.dart';
import 'package:firebase_core/firebase_core.dart';
import 'firebase_options.dart';
// Initialize FirebaseApp
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
// Initialize the Gemini Developer API backend service
// Create a GenerativeModel instance with a model that supports your use case
final model =
FirebaseAI.googleAI().generativeModel(model: 'gemini-2.5-flash');
```
- Ensure your Firebase project is properly configured for AI services (via the Firebase AI Logic page in the Firebase Console).
- Initialize Firebase before using any Firebase AI features.
- Use `FirebaseAI.googleAI()` for the **Gemini Developer API** backend (recommended starting point).
- Consider implementing **App Check** to prevent abuse of your Firebase AI endpoints.
**Platform support:**
| Platform | Support |
|---|---|
| iOS | Full |
| Android | Full |
| Web | Full |
| macOS / other Apple | Beta |
| Windows | Not supported |
---
## 2. Best Practices
- Be aware of **rate limits and quotas** when implementing AI features — monitor usage and costs in the Firebase Console.
- Handle AI service errors gracefully with appropriate **fallback mechanisms**.
- Consider **user privacy** when implementing AI features that process user data.
- Test AI functionality across all supported platforms during development.
---
## 3. Error Handling
- Implement proper error handling for AI service failures.
- Provide meaningful error messages to users when AI operations fail.
- Handle **offline scenarios** and implement appropriate fallback behavior.
- Handle **rate limiting and quota exceeded** errors appropriately.
---
## 4. Security
- Follow Firebase Security Rules best practices when using AI services alongside other Firebase products.
- Ensure proper **authentication and authorization** for AI feature access.
- Be mindful of **data privacy requirements** when processing user content with AI services.
- Implement appropriate **content filtering and moderation** as needed.
---
## References
- [Firebase AI Logic Flutter documentation](https://firebase.google.com/docs/ai-logic/get-started?platform=flutter)
More from evanca/flutter-ai-rules
- architecture-feature-firstStructures Flutter apps using layered architecture (UI / Logic / Data) with feature-first file organization. Use when creating new features, designing the project structure, adding repositories/services/view models (or cubits/providers/notifiers), or wiring dependency injection. State management agnostic.
- blocImplements Flutter state management using the bloc library (Bloc and Cubit). Use when creating new features, screens, or state management logic with bloc/cubit, modeling state, wiring Flutter widgets to blocs, or writing bloc/cubit unit tests.
- dart-3-updatesApplies Dart 3 language features in Flutter/Dart code. Use when writing if-else or switch statements, creating new classes, or deciding between a data class and a record.
- effective-dartApplies Effective Dart guidelines in Flutter/Dart code. Use when writing or reviewing Dart code for naming conventions, types, style, imports, file structure, usage patterns, documentation, testing, widgets, state management, or performance.
- firebase-analyticsIntegrates Firebase Analytics into Flutter apps. Use when setting up analytics, logging events, setting user properties, or configuring event parameters.
- firebase-app-checkIntegrates Firebase App Check into Flutter apps. Use when setting up App Check, selecting providers per platform, using debug providers during development, enabling enforcement, or applying App Check security best practices.
- firebase-authIntegrates Firebase Authentication into Flutter apps. Use when setting up auth, managing auth state, implementing email/password or social sign-in, handling auth errors, managing users, or applying security best practices.
- firebase-cloud-firestoreIntegrates Cloud Firestore into Flutter apps. Use when setting up Firestore, designing document/collection structure, reading and writing data, working with real-time listeners, designing for scale, or applying security rules.
- firebase-cloud-functionsCalls Firebase Cloud Functions from Flutter apps. Use when setting up callable functions, passing data to functions, handling errors from function calls, optimizing performance, or testing with the Firebase Emulator Suite.
- firebase-crashlyticsIntegrates Firebase Crashlytics into Flutter apps. Use when setting up crash reporting, handling fatal and non-fatal errors, customizing crash reports with keys/logs/user identifiers, or configuring opt-in reporting.