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/
0 Comments