firebase
| Atributo | Valor | |----------|-------| | **ID** | `flutter-firebase` | | **Nivel** | π‘ Intermedio | | **VersiΓ³n** | 2.0.0 | | **Keywords** | `firebase`, `firestore`, `auth`, `cloud-messaging`, `analytics`, `storage`, `remote-config`, `crashlytics`, `provider` | | **Referencia
Install
mkdir -p .claude/skills/firebase-habitanexus && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/16899" && unzip -o skill.zip -d .claude/skills/firebase-habitanexus && rm skill.zipInstalls to .claude/skills/firebase-habitanexus
Activation
This is the description your AI agent reads to decide when to run this skill β the better it matches your request, the more reliably it fires.
| Atributo | Valor | |----------|-------| | **ID** | `flutter-firebase` | | **Nivel** | π‘ Intermedio | | **VersiΓ³n** | 2.0.0 | | **Keywords** | `firebase`, `firestore`, `auth`, `cloud-messaging`, `analytics`, `storage`, `remote-config`, `crashlytics`, `provider` | | **ReferenciaAbout this skill
π₯ Skill: Firebase Integration
π Metadata
| Atributo | Valor |
|---|---|
| ID | flutter-firebase |
| Nivel | π‘ Intermedio |
| VersiΓ³n | 2.0.0 |
| Keywords | firebase, firestore, auth, cloud-messaging, analytics, storage, remote-config, crashlytics, provider |
| Referencia | FlutterFire |
π Keywords para InvocaciΓ³n
firebasefirestorefirebase-authcloud-messagingfirebase-analyticsfirebase-storagefirebase-remote-configfirebase-crashlyticsprovider@skill:firebase
Ejemplos de Prompts
Integra Firebase con auth y Firestore
Implementa Firebase Authentication y Cloud Messaging
@skill:firebase - Configura Firebase completo
π DescripciΓ³n
Firebase Integration proporciona servicios backend completos: Authentication (Email/Password y Google Sign-In), Firestore Database, Cloud Storage, Push Notifications (FCM), Analytics (con tracking de screens, eventos personalizados, user ID y propiedades), Crashlytics y Remote Config. Incluye integraciΓ³n con Provider para state management y configuraciΓ³n multiplataforma con mejores prΓ‘cticas.
β οΈ IMPORTANTE: Todos los comandos de este skill deben ejecutarse desde la raΓz del proyecto (donde existe el directorio mobile/). El skill incluye verificaciones para asegurar que se estΓ‘ en el directorio correcto antes de ejecutar cualquier comando.
β οΈ IMPORTANTE: Todos los comandos de este skill deben ejecutarse desde la raΓz del proyecto (donde existe el directorio mobile/). El skill incluye verificaciones para asegurar que se estΓ‘ en el directorio correcto antes de ejecutar cualquier comando.
β CuΓ‘ndo Usar Este Skill
- Backend as a Service rΓ‘pido
- Authentication con mΓΊltiples providers
- Base de datos en tiempo real
- Push notifications
- Analytics y Crashlytics
- Remote Config para A/B testing
- Rapid prototyping
β CuΓ‘ndo NO Usar Este Skill
- Requieres control total del backend
- Costos de Firebase son prohibitivos
- Backend custom ya existe
ποΈ Estructura del Proyecto
lib/
βββ core/
β βββ firebase/
β β βββ firebase_options.dart (generado)
β β βββ firebase_config.dart
β β βββ firebase_initialization.dart
β βββ services/
β βββ analytics_service.dart
β βββ crashlytics_service.dart
β βββ remote_config_service.dart
β βββ storage_service.dart
β
βββ features/
β βββ authentication/
β β βββ data/
β β β βββ datasources/
β β β β βββ firebase_auth_datasource.dart
β β β βββ repositories/
β β β βββ auth_repository_impl.dart
β β βββ domain/
β β β βββ entities/
β β β β βββ user.dart
β β β βββ repositories/
β β β βββ auth_repository.dart
β β βββ presentation/
β β βββ screens/
β β β βββ login_screen.dart
β β βββ providers/
β β β βββ auth_provider.dart
β β βββ bloc/
β β βββ auth_bloc.dart
β β
β βββ products/
β β βββ data/
β β β βββ datasources/
β β β β βββ firestore_products_datasource.dart
β β β βββ models/
β β β βββ product_model.dart
β β βββ domain/
β β βββ entities/
β β βββ product.dart
β β
β βββ notifications/
β βββ data/
β β βββ datasources/
β β β βββ fcm_datasource.dart
β β βββ services/
β β βββ notification_service.dart
β βββ presentation/
β βββ screens/
β βββ notifications_screen.dart
β
βββ main.dart
π¦ Dependencias Requeridas
dependencies:
flutter:
sdk: flutter
# Firebase Core
firebase_core: ^2.24.2
# Firebase Authentication
firebase_auth: ^4.15.3
google_sign_in: ^6.2.1
# Cloud Firestore
cloud_firestore: ^4.13.6
# Cloud Storage
firebase_storage: ^11.5.6
# Cloud Messaging
firebase_messaging: ^14.7.9
flutter_local_notifications: ^16.3.0
# Firebase Analytics
firebase_analytics: ^10.7.4
# Crashlytics
firebase_crashlytics: ^3.4.8
# Remote Config
firebase_remote_config: ^4.3.8
# State Management
provider: ^6.1.1
# Image Picker (para Storage)
image_picker: ^1.0.7
# Utils
equatable: ^2.0.5
dartz: ^0.10.1
dev_dependencies:
flutter_test:
sdk: flutter
βοΈ ConfiguraciΓ³n Inicial
1. Firebase CLI Setup
# Instalar Firebase CLI
npm install -g firebase-tools
# Login a Firebase
firebase login
# Verificar que estamos en la raΓz del proyecto
if [ ! -d "mobile" ]; then
echo "Error: Ejecuta este comando desde la raΓz del proyecto"
exit 1
fi
# Instalar FlutterFire CLI
dart pub global activate flutterfire_cli
# Configurar Firebase para el proyecto
cd mobile
flutterfire configure
cd ..
flutterfire configure
2. Android Configuration
// android/build.gradle
buildscript {
dependencies {
classpath 'com.google.gms:google-services:4.4.0'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.9'
}
}
// android/app/build.gradle
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'
android {
defaultConfig {
minSdkVersion 21 // Firebase requires 21+
}
}
3. iOS Configuration
# ios/Podfile
platform :ios, '13.0' # Firebase requires 13.0+
# DespuΓ©s de flutter_install_all_ios_pods
post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
target.build_configurations.each do |config|
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '13.0'
end
end
end
π» ImplementaciΓ³n
1. Firebase Initialization
// lib/main.dart
import 'package:flutter/material.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_crashlytics/firebase_crashlytics.dart';
import 'firebase_options.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
// Initialize Firebase
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
// Pass all uncaught errors to Crashlytics
FlutterError.onError = FirebaseCrashlytics.instance.recordFlutterFatalError;
runApp(const MyApp());
}
2. Firebase Authentication
// lib/features/authentication/data/datasources/firebase_auth_datasource.dart
import 'package:firebase_auth/firebase_auth.dart' as firebase_auth;
import 'package:google_sign_in/google_sign_in.dart';
import '../models/user_model.dart';
abstract class FirebaseAuthDataSource {
Stream<UserModel?> get authStateChanges;
Future<UserModel> signInWithEmailAndPassword(String email, String password);
Future<UserModel> signUpWithEmailAndPassword(String email, String password);
Future<UserModel> signInWithGoogle();
Future<void> signOut();
Future<void> sendPasswordResetEmail(String email);
UserModel? getCurrentUser();
}
class FirebaseAuthDataSourceImpl implements FirebaseAuthDataSource {
final firebase_auth.FirebaseAuth _firebaseAuth;
final GoogleSignIn _googleSignIn;
FirebaseAuthDataSourceImpl({
firebase_auth.FirebaseAuth? firebaseAuth,
GoogleSignIn? googleSignIn,
}) : _firebaseAuth = firebaseAuth ?? firebase_auth.FirebaseAuth.instance,
_googleSignIn = googleSignIn ?? GoogleSignIn();
@override
Stream<UserModel?> get authStateChanges {
return _firebaseAuth.authStateChanges().map((firebaseUser) {
return firebaseUser != null ? UserModel.fromFirebaseUser(firebaseUser) : null;
});
}
@override
Future<UserModel> signInWithEmailAndPassword(
String email,
String password,
) async {
try {
final credential = await _firebaseAuth.signInWithEmailAndPassword(
email: email,
password: password,
);
if (credential.user == null) {
throw Exception('Sign in failed');
}
return UserModel.fromFirebaseUser(credential.user!);
} on firebase_auth.FirebaseAuthException catch (e) {
throw _handleAuthException(e);
}
}
@override
Future<UserModel> signUpWithEmailAndPassword(
String email,
String password,
) async {
try {
final credential = await _firebaseAuth.createUserWithEmailAndPassword(
email: email,
password: password,
);
if (credential.user == null) {
throw Exception('Sign up failed');
}
return UserModel.fromFirebaseUser(credential.user!);
} on firebase_auth.FirebaseAuthException catch (e) {
throw _handleAuthException(e);
}
}
@override
Future<UserModel> signInWithGoogle() async {
try {
// Trigger the authentication flow
final GoogleSignInAccount? googleUser = await _googleSignIn.signIn();
if (googleUser == null) {
throw Exception('Google sign in was cancelled');
}
// Obtain the auth details from the request
final GoogleSignInAuthentication googleAuth = await googleUser.authentication;
// Create a new credential
final credential = firebase_auth.GoogleAuthProvider.credential(
accessToken: googleAuth.accessToken,
idToken: googleAuth.idToken,
);
// Sign in to Firebase with the Google credential
final userCredential = await _firebaseAuth.signInWithCredential(credential);
if (userCredential.user == null) {
throw Exception('Google sign in failed');
}
return UserModel.fromFirebaseUser(userCredential.user!);
} on firebase_auth.FirebaseAuthException catch (e) {
throw _handleAuthException(e);
} catch (e) {
throw Exception('Google sign in failed: $e');
}
}
@override
Future<void> signOut() async {
await Future.wait([
_firebaseAuth.signOut(),
_googleSignIn.signOut(),
]);
}
@override
Future<void> sendPasswordResetEmail(String email) async {
try {
await _firebaseAuth.sendPasswordResetEmail(email: em
---
*Content truncated.*