How to Connect a Flutter Project to Firebase (Step-by-Step Guide)
Connect your Flutter app to Firebase on Android, iOS and web with the FlutterFire CLI: create a project, run flutterfire configure, initialize Firebase in main.dart, and fix the most common setup errors.
By Yaqoob Developer · · 7 min read
- #Flutter
- #Firebase
- #FlutterFire
- #Setup
- #Beginners
By the end of this guide your Flutter app will be connected to Firebase on Android, iOS and web, using the official FlutterFire CLI. No manual copying of config files, no guessing.
Firebase is Google's backend platform. Once your app is connected, you can add login (Firebase Authentication), a real-time database (Cloud Firestore), file uploads (Cloud Storage), push notifications and more, without writing your own server.
This guide is written for beginners. It works on Windows and macOS, and takes about 20 minutes.
In this post you will learn:
- What you need before you start
- How to create a Firebase project
- How to install the Firebase CLI and the FlutterFire CLI
- How to run
flutterfire configureand what it creates - How to initialize Firebase in
main.dart - How to check that the connection works
- How to fix the most common errors
Before you start: what you need
- Flutter installed and working. Run
flutter doctorin a terminal. If you have not installed Flutter yet, follow my Flutter installation guide for Windows and macOS first. - A Flutter project. Use an existing one, or create a new one:
flutter create my_firebase_app
cd my_firebase_app
- A Google account to sign in to the Firebase console.
- Node.js (only for the easiest way of installing the Firebase CLI). Download the LTS version from nodejs.org.
How the connection works (in one minute)
Your Flutter app needs to know which Firebase project to talk to. That information (project ID, API key, app ID and so on) is different for Android, iOS and web.
In the old days you downloaded google-services.json and GoogleService-Info.plist by hand and edited Gradle files. Today the FlutterFire CLI does all of that with one command and writes everything into a single Dart file, lib/firebase_options.dart. Your app reads that file when it starts.
Firebase project → flutterfire configure → lib/firebase_options.dart → Firebase.initializeApp()

Step 1: Create a Firebase project
- Go to the Firebase console and sign in with your Google account.
- Click Create a project (or Add project).
- Enter a project name, for example
my-firebase-app. Firebase creates a unique project ID from it. - Google Analytics is optional. You can turn it off for a learning project and enable it later.
- Click Create project and wait until it says your project is ready.
You do not need to click "Add app" for Android or iOS in the console. The FlutterFire CLI will register your apps for you in Step 4.
Step 2: Install the Firebase CLI
The Firebase CLI lets your computer talk to your Firebase account. Open a terminal (Command Prompt or PowerShell on Windows, Terminal on macOS) and run:
npm install -g firebase-tools
If you do not want to install Node.js, you can download the standalone Firebase CLI from the official Firebase CLI docs instead.
Now sign in:
firebase login
A browser window opens. Choose the same Google account you used in the Firebase console and allow access. To confirm it worked, list your projects:
firebase projects:list
You should see the project you created in Step 1.
Step 3: Install the FlutterFire CLI
The FlutterFire CLI is a small Dart tool that connects a Flutter project to Firebase. Install it once on your computer:
dart pub global activate flutterfire_cli
After it installs, test it:
flutterfire --version
If you get "flutterfire: command not found" (or "is not recognized" on Windows), the Dart pub cache folder is not on your PATH. Add it:
- Windows: add
%LOCALAPPDATA%\Pub\Cache\binto your userPathenvironment variable, then close and reopen the terminal. - macOS: add this line to
~/.zshrc, then runsource ~/.zshrc:
export PATH="$PATH:$HOME/.pub-cache/bin"
Step 4: Run flutterfire configure
Make sure your terminal is inside your Flutter project folder (the one with pubspec.yaml), then run:
flutterfire configure
The CLI asks you a few questions:
- Select a Firebase project. Use the arrow keys to pick the project from Step 1 and press Enter.
- Which platforms should your configuration support? Select the platforms you want (Android, iOS, web, macOS, Windows) with the Space bar, then press Enter.
- It may ask for your Android application ID or iOS bundle ID. It reads them from your project, so the defaults are usually correct.
When it finishes, it has done all of this for you:
- Registered an Android, iOS and/or web app in your Firebase project
- Created
lib/firebase_options.dartwith the settings for every platform - Added
android/app/google-services.jsonandios/Runner/GoogleService-Info.plistwhere needed - Added the Google services Gradle plugin to your Android project
Important: run flutterfire configure again whenever you add a new platform, add a new Firebase service that needs config, or change your app's package name or bundle ID. It safely updates the existing files.
Step 5: Add the firebase_core package
firebase_core is the package every other Firebase plugin depends on. Add it from your project folder:
flutter pub add firebase_core
This adds the latest version to the dependencies section of your pubspec.yaml.
Step 6: Initialize Firebase in main.dart
Firebase must be initialized before your app uses any Firebase service. Open lib/main.dart and update the top of the file:
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'firebase_options.dart';
Future<void> main() async {
// Needed because we call native code before runApp().
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
runApp(const MyApp());
}
Three things changed:
main()is nowasyncand returnsFuture<void>, so it canawaitFirebase.WidgetsFlutterBinding.ensureInitialized()must be called first. Without it you get a "Binding has not yet been initialized" error.DefaultFirebaseOptions.currentPlatformpicks the right settings fromfirebase_options.dartfor Android, iOS or web automatically.
Step 7: Check that Firebase is connected
The quickest test is to print the Firebase app name and project ID after initialization. Add this line right after Firebase.initializeApp(...):
debugPrint('Firebase connected: ${Firebase.app().options.projectId}');
Now run the app:
flutter run
In the debug console you should see:
Firebase connected: my-firebase-app
If you see your project ID and the app opens normally, Flutter is connected to Firebase. You can remove the print line now.
Platform-specific settings
Most projects work right away, but older projects sometimes need one of these changes.
Android: minimum SDK version
Recent Firebase versions need Android minSdk 23 or higher. If the build fails with a message about minSdkVersion, open android/app/build.gradle.kts (or build.gradle in older projects) and set it inside defaultConfig:
defaultConfig {
minSdk = 23
// ...
}
iOS: deployment target
If pod install fails with a message like "The Firebase pod requires a higher minimum iOS deployment target", open ios/Podfile, uncomment the platform line and set it to the version the error asks for:
platform :ios, '15.0'
Then, from the ios folder, run pod install --repo-update and build again.
Web
Nothing extra is needed. firebase_options.dart already contains your web settings, and Firebase.initializeApp uses them when you run flutter run -d chrome.
Your project after setup
my_firebase_app/
├── android/
│ └── app/
│ └── google-services.json # added by flutterfire configure
├── ios/
│ └── Runner/
│ └── GoogleService-Info.plist # added by flutterfire configure
├── lib/
│ ├── firebase_options.dart # generated, do not edit by hand
│ └── main.dart # initializes Firebase
├── firebase.json # FlutterFire CLI settings
└── pubspec.yaml # firebase_core added here
Is it safe to commit firebase_options.dart to GitHub? Yes, for most apps. The values in it (like the API key) identify your Firebase project; they are not passwords. What protects your data is Firebase Security Rules and App Check, so always set proper rules before you launch.
Common errors and how to fix them
"[core/no-app] No Firebase App '[DEFAULT]' has been created"
You used a Firebase service before calling Firebase.initializeApp(), or forgot to await it. Make sure main() awaits initialization before runApp(), exactly like Step 6.
"flutterfire: command not found"
The pub cache bin folder is not on your PATH. See the fix in Step 3, then open a new terminal window.
"Failed to fetch your Firebase projects" or "Firebase CLI not found"
The FlutterFire CLI uses the Firebase CLI behind the scenes. Run firebase login again, and check that firebase --version works in the same terminal.
"Target of URI doesn't exist: 'firebase_options.dart'"
You have not run flutterfire configure yet, or you ran it in a different folder. Run it from the project root (where pubspec.yaml is).
Android build fails after changing the package name
The package name in Firebase no longer matches your app. Run flutterfire configure again and select Android so a new app is registered with the new package name.
"MissingPluginException" after adding a Firebase package
Hot reload does not load new native plugins. Stop the app completely and run flutter run again. If it still fails, run flutter clean and then flutter pub get.
What to do next
Your app is now connected to Firebase. Every other Firebase feature follows the same pattern: add the package with flutter pub add, enable the service in the Firebase console, and use it in your code.
- Firebase Authentication: let users sign up and log in. Continue with my step-by-step guide: Flutter Firebase Authentication: Login and Sign Up.
- Cloud Firestore:
flutter pub add cloud_firestoreto save and read data in real time. - Cloud Storage:
flutter pub add firebase_storageto upload images and files.
Keep this checklist for every new project:
- Create the Firebase project
firebase login(once per computer)dart pub global activate flutterfire_cli(once per computer)flutterfire configureflutter pub add firebase_coreawait Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform)inmain()
Keep reading
More articles
· 9 min read
Dart Basics for Flutter Beginners: Variables, Functions and Classes
Learn the Dart you need for Flutter: variables, final and const, null safety, lists and maps, if and loops, functions with named parameters, classes, and async/await, with runnable examples.
· 9 min read
Flutter Row, Column and Stack Explained with Examples
Understand Flutter's core layout widgets: main and cross axis, mainAxisAlignment, crossAxisAlignment, Expanded, Flexible, Spacer, Stack and Positioned, plus a complete profile card example.
· 7 min read
Flutter Navigation: How to Move Between Screens
Learn Flutter navigation step by step: Navigator.push and pop, passing data to a screen, returning results, pushReplacement for login flows, named routes, and when to use go_router.