DEV Community

Dhiraj Chaurasiya
Dhiraj Chaurasiya

Posted on

1

Setup Firebase using Firebase CLI for Flutter

Firebase setup using Flutterfire cli has made the integration much easier than earlier minimizing the chance of gradle error in the setup process.

The installation process might skip asking for application id if you've created flutter project by flutter create projectname --org com.projectname
Below are the steps to follow while setting up flutterfire

Here we are going to install using npm.

1. Under prepare your workspace section

  • Install Node.js

    use npm --version to check installed version once installed or if it's already installed.

  • Install the Firebase CLI via npm by running the following command:

npm install -g firebase-tools
Enter fullscreen mode Exit fullscreen mode
  • This will add firebase CLI to your system. To confirm the installation use firebase --version.

  • If there shows an error of firebase command not foundor anything related to that. It is recommended to restart your terminal or command prompt

  • Login to firebase
firebase login
Enter fullscreen mode Exit fullscreen mode

This will navigate to browser choosing the email you want to link your local project with remote project.

2. Under Install and run the FlutterFire CLI

  • Check for the firebase projects with the following command:
firebase projects:list
Enter fullscreen mode Exit fullscreen mode

This will list all the firebase project made with your gmail account.

  • Now, activate the flutterfire cli
dart pub global activate flutterfire_cli
Enter fullscreen mode Exit fullscreen mode
  • In windows if you're installing the flutterfire cli for first time then you'll get a warning asking to add the path to your environment variables.
  • Just copy the path and add to environment variables for windows
  • For macos copy the export command and paste it to terminal.
  • Then, at the root of your Flutter project directory, run this command:
flutterfire configure
Enter fullscreen mode Exit fullscreen mode

This will show all the available projects and let you to choose the firebase project you want to integrate. use arrow keys to navigate and spacebar to select the project
choose the platform you want to build the project for.

** After registering the platform for which you're building the project, it will ask for the android application id.

  • GO TO android/app/build.gradle and search for android->namespace which might look like com.example.projectname
  • copy and paste it to your terminal providing the android application id.
  • This will add firebase_options.dart file to lib folder of your Flutter project.

3. Install firebase_core dependency.

flutter pub add firebase_core
Enter fullscreen mode Exit fullscreen mode

This will solve the error showing the missing of package.

Now you're good to go! You've linked your flutter project with firebase.

Image of Datadog

The Essential Toolkit for Front-end Developers

Take a user-centric approach to front-end monitoring that evolves alongside increasingly complex frameworks and single-page applications.

Get The Kit

Top comments (0)