Firebase in Flutter 1

Integrate Firebase with Flutter – Part 1

🚀 Integrate Firebase with Flutter – Part 1

🔥 What is Firebase?

Firebase is a powerful Backend-as-a-Service (BaaS) platform developed by Google. It provides a wide suite of tools to help developers build, scale, and manage mobile and web applications without the need to manage backend infrastructure. Firebase supports features like authentication, real-time databases, cloud storage, analytics, messaging, hosting, and more — all integrated seamlessly under one platform.

🚀 Why Use Firebase in Flutter?

  • Easy Integration: Firebase packages for Flutter are officially supported and well-documented, making it easy to set up.
  • Authentication: Google, Facebook, phone, and email/password sign-ins are just a few lines of code away.
  • Real-Time Database & Firestore: Sync data across devices instantly – perfect for chat apps and live features.
  • Cloud Messaging: Push notifications are crucial for user engagement, and Firebase makes it seamless with FCM.
  • Storage: Easily upload and retrieve user-generated files like profile pictures, videos, and documents.
  • Analytics: Track user behavior and app performance with built-in Firebase Analytics.
  • No Server Needed: You don't need to write your own backend APIs for most use cases – Firebase handles it.

🎯 Flutter + Firebase = Productivity Boost

With Flutter’s expressive UI framework and Firebase’s robust backend tools, developers can build full-featured, cross-platform apps faster than ever. Whether you're working on a small side project or a full-scale production app, Firebase provides the essential tools to get up and running quickly without worrying about servers or scaling infrastructure.

This is the first part of a 4-part blog series where we will build real-world projects in Flutter using Firebase. In this part, we will set up Firebase correctly and verify its integration in your Flutter app.

📦 What You’ll Learn

  • How to add Firebase to your Flutter project
  • Set up the Firebase console
  • Install required packages using the terminal
  • Test if the Firebase integration works

🛠 Prerequisites

  • Flutter installed and running
  • Android Studio or VS Code setup
  • Firebase account (free)

🔥 Step 1: Create a Firebase Project

  1. Go to Firebase Console
  2. Click on "Add Project"
  3. Give your project a name and click next
  4. Disable Google Analytics (for now)
  5. Click Create Project
📸 You can add a screenshot here showing the Firebase dashboard and project creation.

📲 Step 2: Register Your App

  • Click "Add App" in Firebase → Select Android
  • Enter your Android package name (e.g. com.example.firebaseflutter)
  • Download google-services.json and place it in android/app/
Make sure your applicationId in android/app/build.gradle matches the package name you used.

🧱 Step 3: Configure Android Gradle

Edit the android/build.gradle file:

// Top-level build.gradle

buildscript {

  dependencies {

    classpath 'com.google.gms:google-services:4.3.15'

  }

}

Now edit android/app/build.gradle:

// Bottom of the file

apply plugin: 'com.google.gms.google-services'

📥 Step 4: Add Firebase Packages via Terminal

Open terminal in your Flutter project and run:

flutter pub add firebase_core firebase_auth cloud_firestore firebase_messaging google_sign_in firebase_storage flutter_local_notifications

📄 Step 5: Initialize Firebase in main.dart

import 'package:flutter/material.dart';

import 'package:firebase_core/firebase_core.dart';

void main() async {

  WidgetsFlutterBinding.ensureInitialized();

  await Firebase.initializeApp();

  runApp(MyApp());

}

class MyApp extends StatelessWidget {

  @override

  Widget build(BuildContext context) {

    return MaterialApp(

      home: Scaffold(

        appBar: AppBar(title: Text('Firebase Test')),

        body: Center(child: Text('✅ Firebase is connected!')),

      ),

    );

  }

}

🧪 Step 6: Run the App

If you did everything correctly, you should see:

✅ Firebase is connected!
📸 Add a screenshot of the running app with the confirmation text.

⚡ Bonus: Shell Script to Auto Install Packages

# firebase_setup.sh

#!/bin/bash

flutter pub add firebase_core

flutter pub add firebase_auth

flutter pub add cloud_firestore

flutter pub add firebase_messaging

flutter pub add google_sign_in

flutter pub add firebase_storage

flutter pub add flutter_local_notifications

echo "✅ Firebase packages added!"

Make it executable and run:

chmod +x firebase_setup.sh

./firebase_setup.sh

🎯 What’s Next?

  • Part 2: Build Google Authentication using Firebase Auth
  • Part 3: Push Notifications with Firebase Messaging
  • Part 4: Build a WhatsApp-style Chat App using Firestore

|

0 Comments

Post a Comment

0 Comments