Connect Flutter project to Firebase using FlutterFire CLI

Connect Flutter project to Firebase using FlutterFire CLI

Geekaid
4 min readJan 14, 2023

--

Connecting your project with Firebase is an easy but time-consuming process. But in the case of cross-platform applications like Flutter, it involves a lot of platform-specific, manual configuration steps.

Using FlutterFire CLI we can directly configure our projects with firebase from Dart. All of this is possible because of FLutterFire CLI which generates all the configuration and connect the project correctly for all the platform in your project.

1. Create a flutter project

To create a new flutter project I’ll prefer to build it from the terminal as I want to specify the organization name. The organization name is later used while you publish your app on the play store or app store. The organization name is also used when you connect your application with Firebase.

So while writing, ensure the organization name is readable and it’s not com.example. The organization name is returned in the reverse domain, for example, my domain is geekaid.com so it will be replaced with com.geekaid.

flutter create --org <organisation-name> <app-name>

flutter create --org com.geekaid flutterfire_tutorial

You can use the above command to create a flutter app with the organization-name with your organization name and app-name with your app name, in my case they are com.geekaid and flutterfire_tutorial.

2. Adding dependency

We need to add a dependency name firebase_core, this is a necessary dependency you will require if you want to use firebase services in your application.

If you have used firebase with native android then consider this as a firebase-bom dependency.

flutter pub add firebase_cored

You can use the above command to easily install the dependency or you can add it in the pubspec.yaml manually and then download the dependency.

3. Create a Firebase project

Open your browser and go to console.firebase.google.com, if you don’t have an account create one.

To create a project click on create the project and give your firebase project a name click on continue.

Firebase Console: Add Project

You can turn off the analytics for now, if you require you can turn it on afterward.

4. Installing Firebase CLI

We will need Firebase CLI to communicate with our firebase account from the terminal.

curl -sL https://firebase.tools | bash

To install Firebase CLI run the above script this will automatically detect your operating system and then download the latest version of the Firebase CLI release. This will also enable the globally available firebase so you can run the commands from anywhere.

After installing the CLI we need to log in with your account so that the CLI is authorized to modify the configuration in your firebase project.

  • Run the following common to login to your Firebase account using google login.
firebase login

This command will connect your local machine to firebase and grant access to your Firebase projects.

  • After login into the test, we have properly installed the CLI and authorized it, we will try to list all the projects from your firebase account.
firebase projects:list

It will display a list of your firebase project same as the one listed in the Firebase Console

4. Installing FlutterFire CLI

The FlutterFire CLI depends on Firebase CLI to function. So if you have skipped the third step I recommend you complete the installation of Firebase CLI and do not forget to log in with your Firebase account.

Let’s install FlutterFire CLI by running the following command

dart pub global activate flutterfire_cli

once installed, the flutterfire command will be available globally.

Now, it’s time we configure our project with firebase using flutterfire.

flutterfire configure

Run the command and it will show you a list of projects that are present on your account, choose the project that you want to connect with your app. After the selection of the project, it will ask for platforms for which you want to configure your project.

This will basically create all the configurations for your app for the platforms you have selected. To verify the app is configured open your project from Firebase Console, and you will find the platforms will be connected.

FlutterFire CLI used the organization name to make the configuration, this is the reason I was emphasizing selecting your organization name wisely.

Conclusion

If you have followed along you will be able to connect your project with Firebase using FlutterFire CLI. The process of installing FlutterFire CLI is somewhat lengthy but once you have invested your time then it will save you a ton of time that you would have wasted on manually connecting your projects with Firebase.

I hope this article will help you to learn how to use FlutterFire CLI and save you a lot of time in the future.

If I got something wrong, Inform me on my social media accounts and feel free to contact me and help me to correct it, I would love to improve and rectify my mistake.

❤️❤️ Thanks for reading this article ❤️❤️

--

--

No responses yet