Learn More

Try out the world’s first micro-repo!

Learn More

How to Setup Firebase in Your Flutter Project

How to Setup Firebase in Your Flutter Project

What Is Firebase?

Firebase is a Backend-as-a-Service (BaaS) app development platform that offers hosted backend services like a real-time database, cloud storage, authentication, crash reporting, machine learning, remote configuration and static file hosting.

What Will You Build?

This tutorial will walk you through the process of integrating Firebase into a Flutter app. Non-essential concepts and code blocks are glossed over, but you can copy and paste them simply thanks to the Pieces app. We also have a step-by-step guide to build a Flutter app from scratch.

Set Up a Firebase project

After you've set up and created a simple Flutter app, go to the Firebase official website here: Firebase Console

  • Create a new project by clicking the Create a project button:
  • Next, type in your Project Name, accept the Firebase agreement terms, and click Continue:
  • Enable Google Analytics, which will provide you with detailed analytics about your project. Then, click Continue:
  • Next, you can select the Google Analytics location based on your projected users. If you’re not sure, you can choose the U.S. for a location. Now, accept the Analytics terms and click Create project.
  • Now, you can select the Android icon to configure Firebase with your Android application:
  • Next, you’ll have to register your app by providing your app nickname and package name. You can find your app package name in Flutter here, and as shown below: project directory->android->app->src->main->AndroidManifest.xml
  • Now, you can download your google-services.json file and put it inside your Flutter Project as shown below:
  • To make the google-services.json config values accessible to Firebase SDKs, you need the Google services Gradle plugin.
  • Add the plugin as a buildscript dependency to your project-level build.gradle file:
  • Copy this line of code inside dependencies:
classpath 'com.google.gms:google-services:4.3.13'

Save this code

Root-level (project-level) Gradle file (<project>/build.gradle):

  • Then, Select Kotlin and in your module (app-level) build.gradle file, add both the google-services plugin and any Firebase SDKs that you want to use in your app.
  • Replace following lines of code with your dependencies (last part inside build.gradle file (app-level):
apply plugin: 'com.google.gms.google-services'

Save this code

  • After adding the plugin and the desired SDKs, Click Next, and Continue to Console.

Add Firebase Packages

Firebase is accessed via a variety of libraries, and there is one for each Firebase product (e.g., database, authentication, analytics or storage). Flutter provides a collection of Firebase plugins known as FlutterFire.

Available FlutterFire plugins

  • cloud_firestore
  • cloud_functions
  • firebase_admob
  • firebase_analytics
  • firebase_auth
  • firebase_core
  • firebase_crashlytics
  • firebase_database
  • firebase_dynamin_links
  • firebase_messaging
  • firebase_ml_vision
  • firebase_performance
  • firebase_remote_config
  • firebase_storage

Steps to Add Firebase Packages into Your Project:

  • Open the pubspec.yaml file from the root directory of your Flutter app.
  • Add any package that you want to use, such as firebase_core:
sdk: flutter

firebase_core: ^1.21.1

Save this code

Running the Application

  • Connect your Android emulator or physical device to test the application. Next, click Build & Run.

Bonus Tip

If you want to be more productive and grab code easily from any website, try the Pieces app. It allows you to save snippets in one-click from the web or your editor, plus, it autosaves your frequently used code. Pieces also recommends snippets with Framework standards, saves snippets from screenshots and much more.

Interested in becoming a Pieces Content Partner?

Learn More

Get our latest blog posts and product updates by signing up for our monthly newsletter! 

Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.

Table of Contents



More from Pieces