Firebase + Flutter Setup In Simplest Way (Windows)

Om VastreOm Vastre
3 min read

There are ways to add firebase to your project but the simplest way is to use FirebaseCLI, I tries with adding domain name to firebase apps then downloading json file and adding it in android app folder and adding library, but there is a cath when er try to add those libraries in that gradle.build files the gradle file structure and the structure shown in firebase add apps step don't match so beginner gets confused so simplest way to add firebase in flutter is to use Firebase CLI. Let's see how to do it:

  1. Download Firebase CLI from here: Download FirebaseCLI

    or direct link to start download : Direct download

  2. Then and run command firebase login and login with required account.

  3. Then need to install 'fireflutter' and add it to path, for that

    1. run command : dart pub global activate flutterfire_cli

    2. Then you will get to see a warning msg like :

      "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."

    3. Add path given in msg in Path variable in Environmental Variables. If you don't add to path you may face 'flutterfire not recognized' error

  4. Then close FirebaseCLI window and open your flutter project.

  5. Now need to add required firebase libraries in flutter project for that open terminal and run command :

    1. Firebase Core Lib : flutter pub add firebase_core

    2. Firebase Auth lib : flutter pub add firebase_auth

    3. Firebase Realtime DB Lib : flutter pub add firebase_database

    4. All other libraries are listed here : Fireflutter Official Site

  6. Then run command flutterfire configure and choose project and apps you want to add to firebase project. After that this command will generate a file 'firebase_options.dart' which contains configuration and now go to firebase there you will get to see apps are added to firebase and setup is completed.

Resources : Official Guide, Official Guide Video, FireFlutter

Summary :

The simplest way to integrate Firebase into your Flutter project is through Firebase CLI. Start by downloading Firebase CLI and logging in. Next, install 'flutterfire_cli' and configure your system's PATH by running the command:

dart pub global activate flutterfire_cli

Add the path given in the message to the Path variable in Environmental Variables. You will see a warning message like:

"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."

Then, close the Firebase CLI window and open your Flutter project. Add the required Firebase libraries to your Flutter project by opening the terminal and running the following commands:

Firebase Core Library:

flutter pub add firebase_core

Firebase Auth Library:

flutter pub add firebase_auth

Firebase Realtime Database Library:

flutter pub add firebase_database

All other libraries are listed on the Fireflutter Official Site.

Then run the command:

flutterfire configure

Choose the project and apps you want to add to the Firebase project. This command will generate a file 'firebase_options.dart' which contains the configuration. Now, go to Firebase, and you will see the apps added to Firebase, completing the setup.

1
Subscribe to my newsletter

Read articles from Om Vastre directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Om Vastre
Om Vastre