So today I am going to show you step by step process How to integrate the firebase in a flutter, so you can access service which is provided by firebase API for your project or your client project.

Before we start our tutorial I want to let you know about Firebase backend-as-service back by google Which allows Developers to start with free to focus on making fabulous user experience. firebase is going to handle everything for you in the backend services, you don’t need to manage servers. it provides a feature like a cloud Firestore, Cloud Function, Authentication, Cloud Storage which is used for developing a modern Mobile app like the Android & iOS platform.

  • It offered a realtime database (Cloud Firestore).
  • An advanced authentication platform (Firebase Authentication).
  • A web hosting platform (Firebase Hosting).
  • A file storage platform (Cloud Storage).
  • A backend logic handling platform (Cloud Functions).

Add Firebase into Flutter app as Below –

After Setting up & creating a Simple flutter app, If you don’t know how to create one then click here

Create a Firebase Project

create firebase project in firebase console

https://firebase.google.com/

then click on get started Button

* Create a New Project by click on Add Project Button

*You Need to Enter Firebase Project Name such as Ex- firebase-flutter-demo

*In the Second Step You need to Enable Analytics for this Project because it is going to give Data of the App Which is Essential for App developers.

Source- Firebase

*In the third Step you Need to Select Analytics Location represents your country of the Organization Or Client. Click on the Create Project.

Source – Firebase

Right Now it’s Creating your Project it will take a couple of seconds.

Finally the Project is created Successfully then Firebase is Showing “Your new project is ready” click on Continue.

 

 

 

Configure an Android app

  • In the Get Started Page, You Need to Click On Android Icon to add an android app to firebase

  • On the Next Screen, Add Firebase to your Android app which you need to Enter Android package name, Second you Need to enter App nickname 

Following Step Will Help you Register App With Efficient ways So lets Start.

Step 1. Android Package Name

  • you can find Android Package Name in android Folder, android > app > src > main > AndroidManifest.xml

Step 2. Application nickname

  • you can Any name like example firebase flutter demo

 

Step 3. Debug signing certificate SHA-1

Note: Only Required for Dynamic Links, Invites, and Google Sign-In or phone number support in Auth. Edit SHA-1s in Settings.

  • Go to Folder C:\Program Files\Java\jdk-13.0.1\bin

  • replace name folder with cmd & press Enter After that Black windows is going to open LIke Below Image

  • Type Command as Follow:

For Windows: keytool -list -v -keystore C:\Users\YOURUSERPROFILENAME\.android\debug.keystore -alias androiddebugkey -storepass android -keypass android

For Mac: keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android

  • Change YOURUSERPROFILENAME with your Desktop Name for Example watch below image..

  • THen Click enter you can find out SHA1 Key in cmd

  • you Need to Download google-services.json & Paste to app Folder

you can watch Below Image, Where to put google-service.json file.

The Google services plugin for Gradle loads the google-services.json file you just downloaded. Modify your build.gradle files to use the plugin.Project-level build.gradle (<project>/build.gradle):

buildscript {
  repositories {
    // Check that you have the following line (if not, add it):
    google()  // Google's Maven repository
  }
  dependencies {
    ...
    // Add this line
    classpath 'com.google.gms:google-services:4.3.2'
  }
}

allprojects {
  ...
  repositories {
    // Check that you have the following line (if not, add it):
    google()  // Google's Maven repository
    ...
  }
}

App-level build.gradle (<project>/<app-module>/build.gradle):

apply plugin: 'com.android.application'

dependencies {
  // add the Firebase SDK for Google Analytics
  implementation 'com.google.firebase:firebase-analytics:17.2.0'
  // add SDKs for any other desired Firebase products
  // https://firebase.google.com/docs/android/setup#available-libraries
}
...
// Add to the bottom of the file
apply plugin: 'com.google.gms.google-services'

* you Also Need to Add firebase_auth: ^0.14.0+9 to pubspec.yaml file, As Shown in Below Image

After Adding All Code to the Gradle & in the pubspec.yaml Then Click on Next Button

In this Step You Need to Run Flutter Project On Android Virtual Device (AVD) Or Physical Device After project buid on device. You Need to Go to FIrebase & it will show Congratulations, you’ve successfully added Firebase to your app!

 

 

View on github