Poorgramer-Zack/dart-expert-skills / skills/firebase
integrating-firebase
VerifiedFirebase integration for Flutter including Auth, Firestore, FCM, Cloud Storage, Analytics, and Crashlytics. Use when implementing serverless backend features, real-time sync, or push notifications.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 3.0 KB |
| references/analytics-crashlytics.md | markdown | 3.0 KB |
| references/app-check.md | markdown | 2.9 KB |
| references/auth.md | markdown | 6.2 KB |
| references/cost.md | markdown | 4.2 KB |
| references/database.md | markdown | 3.5 KB |
| references/messaging.md | markdown | 4.2 KB |
| references/serverpod-bff.md | markdown | 4.3 KB |
| references/setup.md | markdown | 2.7 KB |
| references/storage.md | markdown | 2.8 KB |
references/analytics-crashlytics.md
View on GitHub---
metadata:
last_modified: "2026-03-12 11:18:17 (GMT+8)"
---
# Observability (`firebase_analytics`, `firebase_crashlytics`)
## Goal
Implement a robust observability layer to track user engagement metrics (Analytics) and automatically trap and report fatal/non-fatal errors before they reach production users (Crashlytics).
## Instructions
### Firebase Crashlytics (Global Error Trapping)
You must configure Crashlytics to catch both Flutter UI errors and underlying asynchronous Isolate errors. Do this immediately in `main.dart`.
```dart
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
// 1. Catch all errors thrown by the Flutter framework (UI rendering, layout errors)
FlutterError.onError = (errorDetails) {
FirebaseCrashlytics.instance.recordFlutterFatalError(errorDetails);
};
// 2. Catch asynchronous errors (Promises/Futures that weren't awaited)
PlatformDispatcher.instance.onError = (error, stack) {
FirebaseCrashlytics.instance.recordError(error, stack, fatal: true);
return true; // Return true to indicate the error was handled
};
runApp(const MyApp());
}
```
*Note: Crashlytics automatically captures native Android (Java/Kotlin) and iOS (Swift/ObjC) crashes without extra Dart code once the package is installed.*
### Firebase Analytics (Event Tracking)
Analytics tracks user journeys. While screen routing can be tracked automatically (via `FirebaseAnalyticsObserver`), custom business events require manual logging.
```dart
final analytics = FirebaseAnalytics.instance;
// Log a custom event (e.g., when a user adds an item to their cart)
Future<void> logAddToCart(String itemId, String itemName, double price) async {
await analytics.logEvent(
name: "add_to_cart",
parameters: {
"item_id": itemId,
"item_name": itemName,
"value": price,
"currency": "USD",
},
);
}
// Log standard user properties to segment audiences in the console
Future<void> setUserProperties(String userId, String userTier) async {
await analytics.setUserId(id: userId);
await analytics.setUserProperty(name: "subscription_tier", value: userTier);
}
```
### Route Tracking (AnalyticsObserver)
To automatically see which screens users visit the most, attach the `FirebaseAnalyticsObserver` to your `MaterialApp` or GoRouter instance.
```dart
MaterialApp(
navigatorObservers: [
FirebaseAnalyticsObserver(analytics: FirebaseAnalytics.instance),
],
home: const HomeScreen(),
)
```
## Constraints
* **PII (Personally Identifiable Information):** NEVER log emails, physical addresses, phone numbers, or passwords as raw text into Firebase Analytics event parameters. Google will aggressively suspend your Analytics account if PII is detected.
* **Development Masking:** Crashlytics can quickly become noisy during local development. Consider wrapping the `recordError` calls in `if (!kDebugMode)` checks so you only receive reports from TestFlight or Production.
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| deprecation-and-migrationaddyosmani/agent-skillsManages deprecation and migration. Use when removing old systems, APIs, or features. Use when migrating users from one implementation to another. Use when migrating a database schema in production, such as renaming or dropping a column without downtime (expand/contract). Use when deciding whether to maintain or sunset existing code. | Stars: 119k | Updated | Claude CodeCodex | Verified | Install |
| performance-optimizationaddyosmani/agent-skillsOptimizes application performance across frontend, backend, queries, and databases. Use when performance requirements exist, when you suspect performance regressions, when Core Web Vitals or load times need improvement, when N+1 query patterns need fixing, or when profiling reveals bottlenecks. | Stars: 119k | Updated | Claude CodeCodex | Verified | Install |
| agent-cost-reportthedotmack/claude-memBelievable agent cost report for any period, default the last 7 full days PT, not counting today. Measured tokens from Claude Code transcripts priced at OpenRouter list prices (ESTIMATED), measured provider spend when a sanctioned source exists, note-taker cost separate, Timing-style HTML/PDF plus report.json, line-items.csv, evidence.json. | Stars: 118k | Updated | Claude CodeCodex | Verified | Install |
| agent-cost-reportthedotmack/claude-memBelievable agent cost report for any period, default the last 7 full days PT, not counting today. Measured tokens from Claude Code transcripts priced at OpenRouter list prices (ESTIMATED), measured provider spend when a sanctioned source exists, note-taker cost separate, Timing-style HTML/PDF plus report.json, line-items.csv, evidence.json. | Stars: 118k | Updated | Claude CodeCodex | Verified | Install |