Add Firebase to your Flutter app
Prerequisites
Install your preferrededitor or IDE.
Install Flutter for your specificoperating system, including the following:
- Flutter SDK
- Supporting libraries
- Platform-specific software and SDKs
Sign into Firebase using your Googleaccount.
If you don't already have a Flutter app, you can complete theGetStarted: Test Drive tocreate a new Flutter app using your preferred editor or IDE.
Step 1: Install the required command line tools
If you haven't already,install theFirebase CLI.
Log into Firebase using your Google account by running the followingcommand:
firebaseloginInstall the FlutterFire CLI by running the following command from anydirectory:
dartpubglobalactivateflutterfire_cli
Step 2: Configure your apps to use Firebase
Use the FlutterFire CLI to configure your Flutter apps to connect to Firebase.
From your Flutter project directory, run the following command to start theapp configuration workflow:
flutterfireconfigureWhat does thisflutterfire configure workflow do?
The
flutterfire configureworkflow does the following:
Asks you to select the platforms (iOS, Android, Web) supported in yourFlutter app. For each selected platform, the FlutterFire CLI creates a newFirebase app in your Firebase project.
You can select either to use an existing Firebase project or to create anew Firebase project. If you already have apps registered in an existingFirebase project, the FlutterFire CLI will attempt to match them based onyour current Flutter project configuration.
Note: Here are some tips about setting up andmanaging your Firebase project:
- Check out ourbest practices for adding apps to a Firebase project, including how to handle multiple variants.
- EnableGoogle Analytics in your project, which enables you to have an optimal experience using many Firebase products, likeCrashlytics andRemote Config.
Creates a Firebase configuration file (
Note: This Firebase config file contains unique, but non-secretidentifiers for each platform you selected.firebase_options.dart) and adds itto yourlib/directory.
VisitUnderstandFirebase Projects tolearn more about this config file.(forCrashlytics orPerformance Monitoring on Android) Adds the requiredproduct-specific Gradle plugins to your Flutter app.
Note: For the FlutterFire CLI to add the appropriate Gradle plugin, theproduct's Flutter plugin must already be imported into your Flutter app.
flutterfire configure, you need to re-run the command any time that you:- Start supporting a new platform in your Flutter app.
- Start using a new Firebase service or product in your Flutter app, especially if you start using sign-in with Google,Crashlytics,Performance Monitoring, orRealtime Database.
Re-running the command ensures that your Flutter app's Firebase configuration is up-to-date and (for Android) automatically adds any required Gradle plugins to your app.
Step 3: Initialize Firebase in your app
From your Flutter project directory, run the following command to installthe core plugin:
flutterpubaddfirebase_coreFrom your Flutter project directory, run the following command to ensurethat your Flutter app's Firebase configuration is up-to-date:
flutterfireconfigureIn your
lib/main.dartfile, import the Firebase core plugin and theconfiguration file you generated earlier:import'package:firebase_core/firebase_core.dart';import'firebase_options.dart';Also in your
lib/main.dartfile, initialize Firebase using theDefaultFirebaseOptionsobject exported by the configuration file:WidgetsFlutterBinding.ensureInitialized();awaitFirebase.initializeApp(options:DefaultFirebaseOptions.currentPlatform,);runApp(constMyApp());Rebuild your Flutter application:
flutterrun
If you would rather use a demo project, you can start theFirebase Emulator andin yourlib/main.dart file initialize Firebase usingdemoProjectId (it should start withdemo-):
awaitFirebase.initializeApp(demoProjectId:"demo-project-id",);Step 4: Add Firebase plugins
You access Firebase in your Flutter app through the variousFirebase Flutter plugins, one for each Firebase product(for example:Cloud Firestore,Authentication,Analytics, etc.).
Since Flutter is a multi-platform framework, each Firebase plugin is applicablefor Apple, Android, and web platforms. So, if you add any Firebase plugin toyour Flutter app, it will be used by the Apple, Android, and web versions ofyour app.
Here's how to add a Firebase Flutter plugin:
From your Flutter project directory, run the following command:
flutter pub addPLUGIN_NAME
From your Flutter project directory, run the following command:
flutterfireconfigureRunning this command ensures that your Flutter app's Firebase configurationis up-to-date and, forCrashlytics andPerformance Monitoring on Android, adds therequired Gradle plugins to your app.
Once complete, rebuild your Flutter project:
flutterrun
You're all set! Your Flutter apps are registered and configured to use Firebase.
Available plugins
| Product | Plugin name | iOS | Android | Web | Other Apple (macOS, etc.) | Windows |
|---|---|---|---|---|---|---|
| Firebase AI Logic1 | firebase_ai | beta | ||||
| Analytics | firebase_analytics | beta | ||||
| App Check | firebase_app_check | beta | ||||
| Authentication | firebase_auth | beta | beta | |||
| Cloud Firestore | cloud_firestore | beta | beta | |||
| Cloud Functions | cloud_functions | beta | ||||
| Cloud Messaging | firebase_messaging | beta | ||||
| Cloud Storage | firebase_storage | beta | beta | |||
| Crashlytics | firebase_crashlytics | beta | ||||
| Data Connect | firebase_data_connect | |||||
| Dynamic Links | firebase_dynamic_links | |||||
| In-App Messaging | firebase_in_app_messaging | |||||
| Firebase installations | firebase_app_installations | beta | ||||
| ML Model Downloader | firebase_ml_model_downloader | beta | ||||
| Performance Monitoring | firebase_performance | |||||
| Realtime Database | firebase_database | beta | ||||
| Remote Config | firebase_remote_config | beta |
1Firebase AI Logic was formerly called "Vertex AI in Firebase" with the pluginfirebase_vertexai.
Try out an example app withAnalytics
Like all packages, thefirebase_analytics plugin comes with anexample program.
Open a Flutter app that you've already configured to use Firebase (seeinstructions on this page).
Access the
libdirectory of the app, then delete the existingmain.dartfile.From theGoogle Analyticsexample program repository,copy-paste the following two files into your app's
libdirectory:main.darttabs_page.dart
Run your Flutter app.
Go to your app's Firebase project in theFirebase console, then clickAnalytics in the left-nav.
For more information about setting upAnalytics, visit the getting startedguides foriOS+,Android, andweb.
Next steps
Get hands-on experience with theFirebase Flutter Codelab.
Prepare to launch your app:
- Set upbudgetalertsfor your project in theGoogle Cloud console.
- Monitor theUsage and billingdashboard in theFirebase console to get an overall picture of your project'susage across multiple Firebase services.
- Review theFirebase launch checklist.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-12-16 UTC.