Firebase integration in Flutter apps

Tanmoy karmakar
GYTWorkz
Published in
3 min readJun 30, 2022

When it comes to backend or authentication or any other requirement be it cloud messaging or easy storage the one thing that comes to mind is Firebase.

Flutter and firebase is like match made in heaven 💙💙💙.

But, for a new developer it a quite easy but sometimes a challenging process when it comes to the integration of the service.

Thus, I come to the rescue….

In this blog we will see how one can easily integrate firebase using the Firebase CLI.

Lets start…

I will list down steps one by one so that we don't miss any minute details.

Step 1

Create a flutter project.

I am naming my project firebasedemo.

Step 2

Create firebase project

Create your firebase account and create a project. Firebase has a great UI which will help you easily create project without any hiccups.

You will be greeted with the above screen.

Step 3

Lets integrate firebase with our flutter project.

Select flutter icon in the get started by adding firebase to your app section.

Install firebase CLI using the following command in your terminal,

for Mac user,

curl -sL https://firebase.tools | bash

for Windows user, make sure you have npm installed. and then download the exe file from this link.

next, login to your account using,

firebase login

Run the following command, to active flutter fire_cli

dart pub global activate flutterfire_cli

and finally run,

[here fir-demo-ff04d is the project id your will be different]

flutterfire configure --project=fir-demo-ff04d

you will be greeted with the option to choose which platform to initialize,

use arrows and space to toggle selection and press enter.

you need to press enter again to make changes to the gradle and appdelegate files.

It will automatically add required code into your project and you are good to go.

Step 4

In your pubspec.yaml file add firebase_core package.

firebase_core: ^1.18.0

In your main.dart file,

Initialize firebase using,

import 'package:firebase_core/firebase_core.dart';
import 'firebase_options.dart';

// ...

await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);

Finally it should look like this,

import 'package:flutter/material.dart';import 'package:firebase_core/firebase_core.dart';import 'firebase_options.dart';void main() async {await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform,);runApp(const MyApp());}

Wallahhh!!!!

You are all set.

--

--