Firebase Setup
Firebase is a platform developed by Google for creating mobile and web applications. It provides a variety of services like authentication, real-time database, cloud storage, and more. In this section, we will set up Firebase for our Flutter project.
Pre-requisites
- Install Node.js from here
- Install Firebase CLI by running the following command in your terminal:
npm install -g firebase-tools
- Login to Firebase by running the following command in your terminal:
firebase login
- Install FlutterFire cli by running the following command in your terminal:
dart pub global activate flutterfire_cli
Firebase Setup
- In the root of your project, run the following command:
flutterfire configure
Select the Firebase project you want to use for this Flutter project, or create a new one.
Enable
android
andios
platforms for Firebase Authentication in the cli.Go to firebase console, select your project, and navigate to
Authentication
tab. Then click onGet Started
to enable Firebase Authentication. Then click onSign-in method
tab and enableemail
,google
, andapple
sign-in methods.
- Generate SHA-1 and SHA-256 keys for your app by running the following command in your terminal:
In MacOS:
keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android
In Windows:
keytool -list -v -keystore "\.android\debug.keystore" -alias androiddebugkey -storepass android -keypass android
In Linux:
keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android
- Copy the SHA-1 and SHA-256 keys and paste them in the Firebase console under
Project settings
->General
->Your apps
->SHA certificate fingerprints
.
Enable
Firestore Database
,Analytics
,Storage
,Crashlytics
, andFirebase Cloud Messaging
in the Firebase console.Download the
google-services.json
file and replace the existing file created by flutterfire_cli in theandroid/app
directory of your Flutter project.Copy the client id for web and android from your
google-services.json
orfirebase_options.dart
file and paste it into the.env
file underGOOGLE_CLIENT_ID_APP
andGOOGLE_CLIENT_ID_WEB
variables.