Open In App

How to Add Firebase into Flutter in a New Way?

Last Updated : 30 Dec, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

Recently Firebase give another option for adding Firebase to Flutter and It is only made for Flutter, As of now we add firebase using the android option for flutter but now we can add using the flutter option that is recently updated by Flutter. Here you can find how to add firebase as an Android in Flutter.

Step By Step Implementation

Step 1: First, you have to visit the Firebase console. Now let’s move to the next step. Click on the “Add project”  as shown in the below image.

 

Step 2: Provide the firebase project name. Let’s give it “addflutter”. Then click on “Continue”. Disable the “Enable Google Analytics for this project” because we don’t need this and click on “Create project”. It takes some time to wait till the project is created, After that click on “Continue”. Now there will be a screen, Here you can find the old Android version and the New Flutter option. Click on the Flutter icon button.

 

Step 3: Now time to add Firebase to the flutter app,

 

As shown in the above image, Before going to start you have to Install the Firebase CLI and Login in if you have not previously installed it. Now click on Next.

 

Step 4: Now run these two commands from your terminal-

dart pub global activate flutterfire_cli

 

While doing this you must notify the following warning

Warning: Pub installs executables into C:\Users\PC\AppData\Local\Pub\Cache\bin, which is not on your path. You can fix that by adding that directory to your system’s “Path” environment variable. A web search for “configure windows path” will show you how.

This means you need to add C:\Users\*username*\AppData\Local\Pub\Cache\bin into your System’s environment path. Now Again fire this command-

flutterfire configure --project=addflutter-72e0c

Surely again you will get an error,

bash: flutterfire: command not found

flutterfire configure command should work now – close and open again command prompt or another terminal. Sometimes there is a problem with other editors and terminals where flutterfire configure still does not work. In that case, open Command Prompt and it works there for sure. 

This command add the firebase_options.dart into your lib file. Now add the following code to your main file.

import 'package:firebase_core/firebase_core.dart';
import 'firebase_options.dart';
// ...
await Firebase.initializeApp(
   options: DefaultFirebaseOptions.currentPlatform,
);

Congratulations you have successfully Installed the firebase in your flutter application. And now use firebase in your flutter application.


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads