How to setup Flutter for Firebase Cloud ?

 Firebase 


Nowadays, Building apps using Firebase is one of the fastest-growing technology trends. Using firebase, developers can build apps at a rapid pace without managing the infrastructure, including authentication, storing and syncing data,

securely hosting web assets and cloud storage.


Firebase has a totally free base plan, allowing 1 GB the storage and 100 simultaneous connections. If you wish to upgrade, you can check out the firebase plan here: https://www.firebase.google.com/pricing



Configuration


Here we go for our first set up to connect with Firebase. Follow the steps for firebase configuration as below:


  1.  Create a new Flutter project in your IDE or editor.
  2.  opens the file pubspec.yaml file.
  3.  add the following dependency.
    • dependencies:

         flutter:

         SDK: flutter

         cloud_firestore: ^0.14.0+1 

  4. Next, to make your connection, in your IDE or using command line run the following:
    •  flutter package get


Once the connection has been made, the next step will be to create a Firebase project, so, let's get started. 

Here the step is:

  1. Open https://www.firebase.google.com and log in or sign up. You need to log in with your Google credential.
  2. Next, click on Create Project in Firebase site.
  3. Once you click to create a project, a new screen appears where you have to enter your project name and continue.
  4. After clicking Continue the next page will appear where you have to pick your platform android, iso, etc. mine is Android so I choose the android platform, choose yours.

The next step is for app registration this easy and simple too. Here the steps:
  1. Enter the package name of your app. It can be found in the project directory /app/src/main/AndroidManifest.xml   eg.com.test.testproject
  2. Enter your app Nickname in the next text field.
  3. Enter the Sha1 key in the next text field. If you haven't created a key create a key.
    • To create the key you need to run following command: keytool -genkey -v -keystore C:\Users\ShobitPC\.android\blueappkey.jks> -storetype JKS -keyalg RSA -keysize 2048 -validity 10000 -alias key 
    • After entering command some questions will appear, fill them carefully and you are done.
    • To look Fingerprint use this command : keytool -list -v -keystore < key Filelocation path> -alias <alias key> -storepass <storepass here> -keypass <keypass here>.
    • After this, your fingerprint will appear copy sha1 and paste it in the third text field in the and click on next.

Config file Setup

The next step is to download and add Config File in Project. Here The Steps:

  1. After the previous process and click on the next button Config download page will appear download config file by clicking the Download google-service.json button as display in picture.
  2. Add the downloaded file to Android Module root directory eg.<project moduel>/android [com.test.testproject]/app/

Firebase SDK

Next, we need to add Firebase SDK in our project:

  1. After adding google-service.json in project click on the Next button and the Firebase SDK section will appear.
  2. add classpath 'com.google.gms:google-services:4.3.3' in build Gradle of  Project-level build.gradle (<project>/build.gradle): .it should be paste inside dependencies{}.
  3. Next is to copy and paste apply plugin: 'com.google.gms.google-services' and apply plugin: 'com.android.application' in build.gradle in-app module path App-level build.gradle (<project>/<app-module>/build.gradle): 
  4. Also add Implementation 'com.google.firebase:firebase-analytics:17.5.0' in current build.gradle inside dependencies.
  5. Click next and you are all done.

No comments:

Powered by Blogger.