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:
- Create a new Flutter project in your IDE or editor.
- opens the file pubspec.yaml file.
- add the following dependency.
dependencies:
flutter:
SDK: flutter
cloud_firestore: ^0.14.0+1
- 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:
- Open https://www.firebase.google.com and log in or sign up. You need to log in with your Google credential.
- Next, click on Create Project in Firebase site.
- Once you click to create a project, a new screen appears where you have to enter your project name and continue.
- 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:
- Enter the package name of your app. It can be found in the project directory /app/src/main/AndroidManifest.xml eg.com.test.testproject
- Enter your app Nickname in the next text field.
- 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:
- 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.
- 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:
- After adding google-service.json in project click on the Next button and the Firebase SDK section will appear.
- 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{}. - Also add Implementation 'com.google.firebase:firebase-analytics:17.5.0' in current build.gradle inside dependencies.
- Click next and you are all done.
No comments: