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

  1. Go to Firebase Console β†’ https://console.firebase.google.com
  2. Click Add Project
  3. Enter project name β†’ Continue β†’ Finish

πŸ“± Step 2: Add App to Firebase Project

βœ… Android

  1. Click Android icon
  2. Enter Package Name com.example.myapp
  3. Download google-services.json
  4. Place it here: android/app/google-services.json

βœ… iOS

  1. Click iOS icon
  2. Enter Bundle ID
  3. Download GoogleService-Info.plist
  4. Place it here: ios/Runner/GoogleService-Info.plist

βœ… Web (Optional)

  1. Click Web icon
  2. Register app
  3. 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/

Categories: Flutter

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *