Below is a clear, step-by-step guide to integrate Firebase with a Flutter app (latest approach used in 2025–2026). This works for Android, iOS, and Web.
🔥 Step 1: Create Firebase Project
- Go to Firebase Console → https://console.firebase.google.com
- Click Add Project
- Enter project name → Continue → Finish
📱 Step 2: Add App to Firebase Project
✅ Android
- Click Android icon
- Enter Package Name
com.example.myapp - Download
google-services.json - Place it here:
android/app/google-services.json
✅ iOS
- Click iOS icon
- Enter Bundle ID
- Download
GoogleService-Info.plist - Place it here:
ios/Runner/GoogleService-Info.plist
✅ Web (Optional)
- Click Web icon
- Register app
- Copy Firebase config (used later)
⚙️ Step 3: Install FlutterFire CLI
Run in terminal:
dart pub global activate flutterfire_cli
Login to Firebase:
firebase login
🔧 Step 4: Configure Firebase for Flutter
Inside your Flutter project:
flutterfire configure
✔ Automatically generates:
lib/firebase_options.dart
✔ Links Android, iOS & Web correctly
📦 Step 5: Add Firebase Packages
Add required dependencies in pubspec.yaml:
dependencies:
firebase_core: ^3.6.0
firebase_auth: ^5.3.0
cloud_firestore: ^5.5.0
Run:
flutter pub get
🚀 Step 6: Initialize Firebase
In main.dart:
import 'package:flutter/material.dart';
import 'package:firebase_core/firebase_core.dart';
import 'firebase_options.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
runApp(const MyApp());
}
🔐 Step 7: Firebase Authentication Example
import 'package:firebase_auth/firebase_auth.dart';
Future<void> signInUser() async {
await FirebaseAuth.instance.signInWithEmailAndPassword(
email: "test@gmail.com",
password: "123456",
);
}
🗄️ Step 8: Firestore Example
import 'package:cloud_firestore/cloud_firestore.dart';
Future<void> addUser() async {
await FirebaseFirestore.instance.collection("users").add({
"name": "Dheeraj",
"age": 22,
});
}
🛠 Android Extra Setup
android/build.gradle
buildscript {
dependencies {
classpath 'com.google.gms:google-services:4.4.2'
}
}
android/app/build.gradle
apply plugin: 'com.google.gms.google-services'
🍎 iOS Extra Setup
Run:
cd ios
pod install
Ensure:
platform :ios, '12.0'
🌐 Web Setup (Optional)
await Firebase.initializeApp(
options: FirebaseOptions(
apiKey: "API_KEY",
appId: "APP_ID",
messagingSenderId: "SENDER_ID",
projectId: "PROJECT_ID",
),
);
✅ Firebase Services You Can Use
✔ Authentication
✔ Cloud Firestore
✔ Realtime Database
✔ Firebase Storage
✔ Cloud Messaging (FCM)
✔ Analytics
📌 Best Practice (Recommended for You)
Since you often use BLoC & Clean Architecture, structure Firebase like this:
data/
├─ datasources/
├─ repositories/
domain/
├─ usecases/
presentation/
├─ bloc/
