Firebase + Flutter Setup In Simplest Way (Windows)
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:
Download Firebase CLI from here: Download FirebaseCLI
or direct link to start download : Direct download
Then and run command firebase login and login with required account.
Then need to install 'fireflutter' and add it to path, for that
run command : dart pub global activate flutterfire_cli
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."
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
Then close FirebaseCLI window and open your flutter project.
Now need to add required firebase libraries in flutter project for that open terminal and run command :
Firebase Core Lib : flutter pub add firebase_core
Firebase Auth lib : flutter pub add firebase_auth
Firebase Realtime DB Lib : flutter pub add firebase_database
All other libraries are listed here : Fireflutter Official Site
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.
Subscribe to my newsletter
Read articles from Om Vastre directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by