How to add firebase to flutter app ? Let’s get started.
Step 1: Set up your environment
Fluter.io provides a neat document on how to install flutter and setup your favourite IDE : Get Started
Once you have completed setup create a new Flutter project with your desired name.
Step 2: Create a Firebase project
Before adding firebase to flutter app go to Firebase console and create new Firebase project.
Tap on Add Project enter your Projects name , firebase will assign a project id based on the entered name you can also edit , Accept terms and Create project.
Your new firebase project will be created.
Step 3: Configure your app to use Firebase
To configure firebase to flutter we need some platform specific details to android and iOS apps. If you are working only on android you don’t need to add iOS specific changes.
Configure an iOS App: (Optional )
- In your Firebase project console overview page , Launch the iOS setup wizard.
- Find this bundle ID by opening your app in XCode, then accessing the General tab in the top-level
Runnerdirectory. The value of the Bundle Identifier field is the iOS bundle ID (for example,
2. Enter the Name and app store id (optional ) click next. Now download the GoogleService-info.plist
Copy the GoogleService-info.plist into iOS — Runner — Runner directory of your flutter project. In console click next and skip other steps.
Your iOS app is configured with Firebase.
Configure an Android App: (Optional )
- In your Firebase project console overview page , Launch the Android setup wizard.
Enter your application id into the Android package field, other fields are optional.
- An application ID is sometimes referred to as as a package name.
- Find this application ID in your module (app-level) Gradle file, usually
android/app/build.gradle(example application ID:
Register the app. On the next step download google-services.json and move the file into android/app folder of your flutter project.
2. Android requires another few more steps to add firebase support in your app .
In your root-level (project-level) Gradle file (
android/build.gradle), add rules to include the Google Services plugin. Check that you have Google’s Maven repository, as well.
// Add the following line:
classpath 'com.google.gms:google-services:3.2.1' // Google Services plugin
// Check that you have following line (if not, add it):
google() // Google's Maven repository
In your module (app-level) Gradle file (usually
android/app/build.gradle), add the following line to the bottom of the file.
// Add the following line to the bottom of the file:
apply plugin: 'com.google.gms.google-services' // Gradle plugin
flutter packages get.
Now our app is ready to integrate flutter firebase plugins.
Open your pubspec.yaml file and add the following line under dependencies
firebase_core: ^0.2.5 # add dependency for Firebase Core
Run your app and verify if app is working.
Documentation from firebase.google.com.