Home / Programming / How to connect Firebase databse with a Flutter project.

How to connect Firebase databse with a Flutter project.

connect flutter project with firebase database

Why is the Firebase database becoming so popular among developers recently?

Nowadays, Firebase plays a vital role in the development of projects. There are many benefits to using the Firebase database instead of other databases. On one platform, we take multiple positive outcomes like saving our huge data, providing us opportunity of real real-time database, social logins, and mobile authentications, etc. Let’s connect our Flutter project with Firebase.

First, open the Firebase console, and click on Create a Firebase project.

how to get started to creating a firebase project.

Write the project name, keep in mind that letters must be small, don’t use spaces in the project name, and you can use dashes between the words.

write a name for firebase project

Just click on Continue. This screen is just asking for the connection to Gemini.

creating firebase project

Just Click on Continue. This screen is asking to add Google Analytics to your Firebase project. It helps you to show the analytics of your complete project.

just asking permission for adding google analytics

On this screen, just select the default account for Firebase.

Configure google analytics with the firebase

Just click on Continue, and you have successfully created a project.

project is ready to connect with firebase

Once your project has been created, you just need to connect it with your Flutter project, so click on the Flutter icon. Furthermore, you will see that we will connect our project with both Android and iOS devices.

firebase dashboad need to select flutter icon.

Just click on next. This is just asking for permission to prepare your workspace.

add firebase to your flutter app

We will connect firebase with our project with the help of CLI command, This is an simplest way to create connection between the project and firebase, i have also configured CLI in my system, if you dont have, so please first install CLI and configured in your system Additionally, must be assure that login with the same email in the flutter and firebase. Now you are open to run these commands in your Flutter code terminal. Copy the First command and go to your project terminal.

Add these lines in a code

Here, we just run the first command.

running cli command in flutter terminal

Here we run the second command.

run this command in flutter terminal

You can see that we have options to connect Firebase with multiple devices. We will select these options according to our requirements. Now, I am going to add a project with Android and iOS, but you have an option to connect with more devices like macOS, web, and Windows. Just press down and up for moving, and use the tab button to select and deselect options

selecting the options of multiple platforms, ex android, ios, etc

Our Firebase project has successfully connected with Firebase. Moreover, we just need to add some code in our Flutter project to complete the configuration.

sucessfully connected project in terminal

We need to add these lines of code to our project. We will explore this further below.

 

Add these lines in a code

We use this code here, which we copied from the last screen. Furthermore, we need to make some small changes, like converting the main function into async, so it starts to demonstrate an error after converting the function. Now, we will install the Firebase Core package in our pubspec.YAML file.

add some line of code in the main function

This is our pubSpec.YAML file. Here we install our project packages, and then don’t forget to pub get and pub grade.

add plugin in pub spec yaml file

This is our home screen of the Firebase project. You can see that we successfully showed our project.

Firebase dashbooard,project has sucessfully created

Leave a Reply

Your email address will not be published. Required fields are marked *