A Complete Guide to Setting Up Firebase in Flutter

Flutter Studio
3 min readJul 5, 2023

Firebase, a comprehensive development platform provided by Google, offers a wide range of powerful tools and services for building mobile and web applications.

In this tutorial, we will walk you through the process of setting up Firebase in Flutter, a popular framework for building cross-platform apps. By the end of this guide, you will have a solid understanding of how to integrate Firebase into your Flutter project and leverage its features for enhanced functionality.

Table of Contents:

  1. Prerequisites
  2. Creating a Firebase Project
  3. Adding Firebase to Your Flutter Project
  4. Configuring Firebase for Android
  5. Configuring Firebase for iOS
  6. Adding Firebase Services
  7. Testing Firebase Integration
  8. Conclusion

Prerequisites: Before we dive into setting up Firebase in Flutter, make sure you have the following:

  • Flutter SDK installed on your system
  • A Flutter project created and ready for Firebase integration
  • A Google account to create a Firebase project

Creating a Firebase Project: To get started, visit the Firebase website (firebase.google.com) and sign in with your Google account. Follow these steps to create a new Firebase project:

  • Click on “Go to Console” or “Add project” button.
  • Click on “Create a project.”
  • Provide a project name and select your country/region.
  • Enable Google Analytics if desired (optional).
  • Click on “Create Project.”

Adding Firebase to Your Flutter Project: To integrate Firebase into your Flutter project, you need to add the Firebase packages to your pubspec.yaml file. Open your Flutter project in your preferred code editor, locate the pubspec.yaml file, and add the following dependencies:

dependencies:
firebase_core: ^1.10.0
firebase_auth: ^3.1.0
cloud_firestore: ^2.5.0
firebase_storage: ^10.2.0

Save the file and run flutter pub get in the terminal to download the packages.

Configuring Firebase for Android: To configure Firebase for your Flutter project on Android, follow these steps:

  • Go back to the Firebase console and select your project.
  • Click on the “Android” icon to add an Android app.
  • Provide the package name of your Flutter app (e.g., com.example.myapp).
  • Download the google-services.json file.
  • Move the downloaded google-services.json file to the android/app directory of your Flutter project.
  • Open the android/build.gradle file and add the following classpath dependency in the dependencies section:
classpath 'com.google.gms:google-services:4.3.10'
  • Open the android/app/build.gradle file and add the following plugins at the bottom of the file:
apply plugin: 'com.google.gms.google-services'
  • Save the files, and Android configuration is complete.

Configuring Firebase for iOS: To configure Firebase for your Flutter project on iOS, follow these steps:

  • Go back to the Firebase console and select your project.
  • Click on the “iOS” icon to add an iOS app.
  • Provide the iOS bundle identifier of your Flutter app (e.g., com.example.myapp).
  • Download the GoogleService-Info.plist file.
  • Open your Flutter project in Xcode (open ios/Runner.xcworkspace).
  • Drag and drop the downloaded GoogleService-Info.plist file into the "Runner" directory in Xcode.
  • Make sure the file is added to the “Runner” target.
  • Save the changes, and iOS configuration is complete.

Adding Firebase Services: Now that Firebase is configured in your Flutter project, you can start using various Firebase services. Here are a few examples of how to add Firebase services to your Flutter app:

  • Authentication: Use firebase_auth package to enable user authentication.
  • Realtime Database or Firestore: Use cloud_firestore package to store and retrieve data.
  • Cloud Storage: Use firebase_storage package to upload and download files.

Remember to follow the documentation and APIs of each Firebase service to properly implement their features in your app.

Testing Firebase Integration: To test if Firebase is integrated successfully, you can add some basic functionality like signing in a user or retrieving data from Firestore. Run your Flutter app and verify if the Firebase-related features are functioning as expected.

Conclusion: Congratulations! You have successfully set up Firebase in your Flutter project. Firebase offers a vast array of services that can enhance the functionality and user experience of your Flutter app. With this guide as a starting point, you can now explore and leverage the power of Firebase to build dynamic and feature-rich applications.

Photo by Marvin Meyer on Unsplash

Remember to refer to the official Firebase documentation and packages for detailed information on each service and their implementation in Flutter.

Happy coding with Firebase and Flutter!

--

--