flutter-firebase
Original:🇺🇸 English
Translated
Firebase Auth, Firestore, FCM, Crashlytics & Analytics Patterns
3installs
Sourcedhruvanbhalara/skills
Added on
NPX Install
npx skill4agent add dhruvanbhalara/skills flutter-firebaseTags
Translated version includes tags in frontmatterSKILL.md Content
View Translation Comparison →Firebase Setup
- Use for initialization — call
firebase_corebeforeFirebase.initializeApp()runApp() - Use for platform-specific setup
flutterfire configure - Use separate Firebase projects per flavor (see skill)
app-config - Register Firebase services via for consistent DI
injectable
Authentication
- Use for user management
firebase_auth - Wrap all auth calls in an — no direct
AuthRepositoryusage in BLoCs or UIFirebaseAuth - Support email/password, Google Sign-In, and Apple Sign-In at minimum
- Handle auth state changes via stream in
FirebaseAuth.instance.authStateChanges()AuthBloc - Store auth tokens via — never in
flutter_secure_storageor source codeSharedPreferences - Implement proper sign-out: clear local cache, navigate to login, dispose user-specific BLoCs
Firestore
- Use for remote data persistence
cloud_firestore - DataSources wrap all Firestore calls (,
get,set,update,delete)snapshots - Use typed model classes with /
fromFirestorefactory methodstoFirestore - Prefer for type-safe collection references
.withConverter<T>() - Use batch writes for multi-document operations — never multiple sequential writes
- Implement offline persistence (enabled by default on mobile)
Security Rules
- NEVER rely on client-side validation alone — enforce rules in Firestore Security Rules
- Default deny: start with and open only what's needed
allow read, write: if false; - Always validate for authenticated-only collections
request.auth != null - Test rules with the Firebase Emulator Suite before deploying
Push Notifications (FCM)
- Use for push notifications
firebase_messaging - Request notification permissions early but gracefully (explain value before requesting)
- Handle foreground, background, and terminated-state messages separately
- Store FCM token in Firestore user document for server-side targeting
- Re-register token on stream
onTokenRefresh
Crashlytics
- Use for crash reporting
firebase_crashlytics - Enable in staging and production flavors only — disable in dev
- Record Flutter errors:
FlutterError.onError = FirebaseCrashlytics.instance.recordFlutterFatalError - Catch async errors via
PlatformDispatcher.instance.onError - Add custom keys for user context:
Crashlytics.instance.setCustomKey('userId', id)
Analytics
- Use for user behavior tracking
firebase_analytics - Log meaningful events with descriptive names:
analytics.logEvent(name: 'purchase_completed') - Set user properties for segmentation:
analytics.setUserProperty(name: 'plan', value: 'premium') - Track screen views via in
FirebaseAnalyticsObserverGoRouter - NEVER log PII (emails, passwords, phone numbers) in analytics events
Remote Config
- Use for feature flags and A/B testing
firebase_remote_config - Set sensible defaults locally — app MUST work without Remote Config fetched
- Fetch and activate on app start with a timeout fallback
- Cache values and respect minimum fetch intervals to avoid throttling