Flutter | Firebase | Connect: Android, IOS & Web (2022)

Mohammed Waseem
2 min readMay 23, 2022

Requirements before following mentioned steps:

> Firebase CLI

Install from the below link:

Then, run the below command in your terminal to activate flutterfire. It makes the connection to firebase simpler.

dart pub global activate flutterfire_cli

NOTE: The above commands are not required to do again if you want to connect to another project. Only follow what is mentioned below.

Now run in the command line :

flutterfire configure

You will be asked to select a project you create in firebase, so select the one you want to use using the ENTER button

After that, you will be asked which platforms you want to connect to? All the platforms will be mentioned select/deselect them by pressing SPACE BAR and when click press ENTER.

After it's done you will receive the following message in the command line:

A file firebase_options.dart will be generated having the data to connect to firebase for the platforms you selected.

Next:

Have the following imports in main.dart:

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

Next under void main… copy and paste the below code to your file.

WidgetsFlutterBinding.ensureInitialized();
await
Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform);

Now just run your app on any platform you selected and it should work.🙂

--

--