Set up Google Firebase in your Flutter project

Tiempo de lectura: 4 minutos

Today we are going to learn how we can set up Google Firebase in a Flutter project.

The first thing we need to do is create our Firebase project, for that we go to https://firebase.google.com/

And click on Go to Console:

Choose Add Project

Here is the HTML content translated to English:

Choose a name for the APP. We can choose whether we want to activate Google Analytics.

Wait for the project to be set up and click continue:

Now we install Firebase CLI: https://firebase.google.com/docs/cli?hl=en-419#setup_update_cli

We download the one we need according to the Operating System, in my case I use Windows:

Now, in Windows it has prevented me from installing it, we click that it is safe and let it run.

It will start installing:

Now it will ask us to authenticate with our Google account, we choose one and we’re done:

Once installed, we go to our project and use the following command:

dart pub global activate flutterfire_cli

We wait for it to configure.

We will see a Warning like this:

We have to add this Path it indicates, in the case of Windows, as follows:

Open the Start Menu:

System Configuration:

Environment Variables:

Edit the PATH Variable:

Add the Path:

Save and Close:

Close and Open Terminals Again:

On Mac:

export PATH="$PATH":"$HOME/.pub-cache/bin"

Now we add firebase_core (https://pub.dev/packages/firebase_core)

flutter pub add firebase_core

Returns only the HTML translated, without any additions.

flutterfire configure

If we encounter the following error:

https://firebase.google.com/docs/cli#install_the_firebase_cli

for how to install it.

We install the following:

npm install -g firebase-tools

*Remember to have nodejs installed: https://nodejs.org/en

And it will start configuring:

We select the project we created earlier.

We choose the platforms that interest us:

</p>

div class=”wp-block-image”>

In my case, I leave them as default.

And we wait for it to be configured.

Now, let’s move on to the code that will make the notifications work.

We create a class called FirebaseInitializer.dart

Once created, we have to go to our main class and add:

This initializes Firebase in our app.

If we encounter the following error:

Install the following:

npm install -g firebase-tools

*Remember to have nodejs installed: https://nodejs.org/en

And it will start configuring itself:

Now, we select the project that we created earlier.

We choose the platforms that interest us:

In my case, I leave them as default.

And we wait for it to be configured.

Now let’s go with the code that will make notifications work.

We create a class called FirebaseInitializer.dart

Once created, we have to go to our main class and add:

This initializes Firebase in our APP.

If we encounter the following error:

We install the following:

npm install -g firebase-tools

*Remember to have Node.js installed: https://nodejs.org/en

And it will start setting up:

Now, we select the project we created earlier.

We choose the platforms that interest us:

In my case, I leave them as default.

And we wait for it to be configured.

Now, let’s move on to the code that will make the notifications work.

We create a class called FirebaseInitializer.dart

Once created, we have to go to our main class and add:

Leave a Comment