Open In App

How to Add Firebase to Flutter Project From Mac Terminal?

Last Updated : 07 Mar, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

If you are a Flutter developer you must know that it supports multi-platform applications. It is more hectic to add firebase support for all platforms like web, android, ios, macOS, Linux, and many more to come. For every platform, there are different files and settings which consumes lots of time. Today in this article you will learn about How to add firebase to the flutter project for all platforms at 1 time from the command line. So let’s get started.

Step by Step Implementation

Step 1: Install Brew  for Mac users

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

 

Step 2: Check whether the brew is installed or not

Check whether the brew is installed or not. By typing brew –version in your terminal. If it was installed you will get different commands available in the brew.

 

Step 3: Install npm

Refer to this link.

Step 4: Install firebase in the node

npm install -g firebase-tools

Step 5: Login with your firebase account from which you want to do hosting with the command

firebase login

 

Step 6: Install dart

Refer to this article: Dart SDK Installation

Step 7: Activate 

dart pub global activate flutterfire_cli

 

Step 8: Set the path flutterfirecli by this

export PATH="$PATH":"$HOME/.pub-cache/bin"

Step 9: Go to your project folder where you want to add firebase through the same cmd only

Now check whether flutterfire is available or not for this by writing flutterfire in the command line it will show like this. If it is flutter project

 

If not it will show

 

Step 11: Now add this command

flutterfire configure

 

Step 12: Now select firebase project if it already creates on firebase or creates a project from the CLI only

If it is already created then you jump to the next step

 

If you creating a project then it will ask a question like this

 

Enter a project id for your new Firebase project (e.g. my-cool-project)

Step 13: Now select the platform for which you want to make the firebase project

Select and deselect the platform using the spacebar in the terminal. If you select all the platforms it will ask you a question like this answer yes to this question to add dependency in all files automatically.

The files android/build.gradle & android/app/build.gradle will be updated to apply Firebase configuration and gradle build plugins. Do you want to continue? (? The files android/build.gradle & android/app/build.gradle will be updated to apply Firebase configuration and gradle build plugins. Do you want to continue? (✔ The files android/build.gradle & android/app/build.gradle will be updated to apply Firebase configuration and gradle build plugins. Do you want to continue? · yes 

Step 14: You have successfully  added firebase for all platforms you selected

 

Step 15: Add this file in lib/main.dart

WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
  options: DefaultFirebaseOptions.currentPlatform,
);

 

Now you can run the app Firebase is already added to your flutter project.


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads