Sunday, January 25, 2026
HomeFlutterHow to integrate firebase in our flutter project

How to integrate firebase in our flutter project

Here’s a clear, step-by-step guide to integrating Firebase into a Flutter project (Android + iOS). This works for most Firebase services (Auth, Firestore, Analytics, etc.).


1️⃣ Prerequisites

Make sure you have:

  • Flutter SDK installed (flutter doctor shows no major issues)
  • A Google account
  • Android Studio / Xcode set up
  • A real device or emulator

2️⃣ Create a Firebase Project

  1. Go to Firebase Console: https://console.firebase.google.com
  2. Click Add project
  3. Enter project name → Continue
  4. Enable/disable Google Analytics (your choice)
  5. Create project

3️⃣ Install FlutterFire CLI (Recommended way)

This is the official and easiest method.

dart pub global activate flutterfire_cli

Make sure Dart’s global bin is in your PATH.

Check installation:

flutterfire --version

4️⃣ Configure Firebase for Your Flutter App

From your Flutter project root:

flutterfire configure

This will:

  • Ask you to select your Firebase project
  • Detect Android / iOS / Web platforms
  • Automatically:
    • Register apps in Firebase
    • Download config files
    • Generate firebase_options.dart

✔️ This replaces manual setup for most cases


5️⃣ Add Firebase Core Dependency

In pubspec.yaml:

dependencies:
  flutter:
    sdk: flutter
  firebase_core: ^2.24.2

Then:

flutter pub get

6️⃣ Initialize Firebase in main.dart

Import Firebase and initialize before runApp.

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());
}

7️⃣ Platform-Specific Notes

✅ Android

FlutterFire CLI handles:

  • google-services.json
  • Gradle setup

Make sure:

  • minSdkVersion21
    In android/app/build.gradle:
minSdkVersion 21

✅ iOS

FlutterFire CLI handles:

  • GoogleService-Info.plist
  • Firebase pods

Run:

cd ios
pod install

In Xcode:

  • Set iOS deployment target to 11.0 or higher

8️⃣ Add Firebase Services (Example)

🔐 Firebase Authentication

flutter pub add firebase_auth

Example usage:

import 'package:firebase_auth/firebase_auth.dart';

final auth = FirebaseAuth.instance;

User? user = auth.currentUser;

📦 Cloud Firestore

flutter pub add cloud_firestore

Example:

FirebaseFirestore.instance
  .collection('users')
  .add({'name': 'John', 'age': 25});

9️⃣ Run the App

flutter run

If everything is correct, the app will launch without Firebase errors 🎉


🔥 Common Errors & Fixes

ErrorSolution
Firebase not initializedEnsure initializeApp() is awaited
Gradle build failedCheck minSdkVersion >= 21
iOS pod issuesRun pod repo update
App crashes on launchVerify config files

✅ Recommended Next Steps

  • Enable Authentication providers (Email, Google, Phone)
  • Set up Firestore rules
  • Add Crashlytics
  • Add Push Notifications (FCM)
RELATED ARTICLES

1 COMMENT

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments