一键导入
firebase-ai
Use when setting up firebase_ai, generating text/chat with Gemini, streaming AI output, building multimodal prompts, or handling AI errors.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Use when setting up firebase_ai, generating text/chat with Gemini, streaming AI output, building multimodal prompts, or handling AI errors.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Use when working on accessibility, a11y, WCAG, ARIA, screen readers, keyboard nav, focus order, contrast, alt text, captions, reduced motion, or target sizes; not language/culture/device (see inclusive-design).
Use when creating a feature, designing folder structure, adding repositories/services/view models, wiring dependency injection, or deciding which layer owns logic.
Use when creating a Cubit or Bloc, modeling state with sealed classes or status enums, wiring BlocBuilder/BlocListener/BlocProvider, writing bloc tests, or choosing between Cubit and Bloc.
Use when asked to review a PR, MR, branch, or diff, audit changed files, or check code quality.
Use when writing switch statements, refactoring if-else chains, creating data classes, choosing records vs classes, destructuring values, or modernizing pre-Dart-3 code.
Use when writing Dart code, reviewing for style, refactoring naming, adding doc comments, structuring imports, or enforcing type annotations.
| name | firebase-ai |
| description | Use when setting up firebase_ai, generating text/chat with Gemini, streaming AI output, building multimodal prompts, or handling AI errors. |
This skill defines how to correctly use Firebase AI Logic in Flutter applications.
Use this skill when:
flutter pub add firebase_ai
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
final model =
FirebaseAI.googleAI().generativeModel(model: 'gemini-2.5-flash');
FirebaseAI.googleAI() for the Gemini Developer API backend (recommended starting point).Platform support:
| Platform | Support |
|---|---|
| iOS | Full |
| Android | Full |
| Web | Full |
| macOS / other Apple | Beta |
| Windows | Not supported |
final response = await model.generateContent([
Content.text('Summarize the benefits of Flutter for mobile development'),
]);
final text = response.text; // The generated summary string
final chat = model.startChat();
final response = await chat.sendMessage(
Content.text('What is the difference between StatelessWidget and StatefulWidget?'),
);
print(response.text);
// Follow-up in the same conversation
final followUp = await chat.sendMessage(
Content.text('When should I use StatefulWidget?'),
);
print(followUp.text);
Use streaming to display partial results as they arrive:
final stream = model.generateContentStream([
Content.text('Write a step-by-step guide to implementing dark mode in Flutter'),
]);
await for (final chunk in stream) {
// Append chunk.text to the UI progressively
setState(() => _output += chunk.text ?? '');
}
final imageBytes = await File('photo.jpg').readAsBytes();
final response = await model.generateContent([
Content.multi([
TextPart('Describe what you see in this image'),
InlineDataPart('image/jpeg', imageBytes),
]),
]);
Wrap AI calls in structured error handling:
try {
final response = await model.generateContent([Content.text(prompt)]);
return response.text;
} on FirebaseAIException catch (e) {
if (e.message?.contains('quota') ?? false) {
// Handle rate limiting — show retry message or queue the request
return 'Service is busy. Please try again shortly.';
}
return 'AI service error: ${e.message}';
} catch (e) {
return 'Unexpected error: $e';
}
final model = FirebaseAI.googleAI().generativeModel(
model: 'gemini-2.5-flash',
safetySettings: [
SafetySetting(HarmCategory.harassment, HarmBlockThreshold.medium),
SafetySetting(HarmCategory.dangerousContent, HarmBlockThreshold.high),
],
);