Add Firebase to your Flutter app


Prerequisites

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

  1. If you haven't already,install theFirebase CLI.

  2. Log into Firebase using your Google account by running the followingcommand:

    firebaselogin
  3. Install 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:

flutterfireconfigure

What does thisflutterfire configure workflow do?

Theflutterfire configure workflow does the following:


After this initial running offlutterfire 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

  1. From your Flutter project directory, run the following command to installthe core plugin:

    flutterpubaddfirebase_core
  2. From your Flutter project directory, run the following command to ensurethat your Flutter app's Firebase configuration is up-to-date:

    flutterfireconfigure
  3. In yourlib/main.dart file, import the Firebase core plugin and theconfiguration file you generated earlier:

    import'package:firebase_core/firebase_core.dart';import'firebase_options.dart';
  4. Also in yourlib/main.dart file, initialize Firebase using theDefaultFirebaseOptions object exported by the configuration file:

    WidgetsFlutterBinding.ensureInitialized();awaitFirebase.initializeApp(options:DefaultFirebaseOptions.currentPlatform,);runApp(constMyApp());
  5. 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:

  1. From your Flutter project directory, run the following command:

    flutter pub addPLUGIN_NAME
  2. From your Flutter project directory, run the following command:

    flutterfireconfigure

    Running 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.

  3. Once complete, rebuild your Flutter project:

    flutterrun

You're all set! Your Flutter apps are registered and configured to use Firebase.

Available plugins

ProductPlugin nameiOSAndroidWebOther Apple
(macOS, etc.)
Windows
Firebase AI Logic1firebase_ai
beta
Analyticsfirebase_analytics
beta
App Checkfirebase_app_check
beta
Authenticationfirebase_auth
betabeta
Cloud Firestorecloud_firestore
betabeta
Cloud Functionscloud_functions
beta
Cloud Messagingfirebase_messaging
beta
Cloud Storagefirebase_storage
betabeta
Crashlyticsfirebase_crashlytics
beta
Data Connectfirebase_data_connect
Dynamic Linksfirebase_dynamic_links
In-App Messagingfirebase_in_app_messaging
Firebase installationsfirebase_app_installations
beta
ML Model Downloaderfirebase_ml_model_downloader
beta
Performance Monitoringfirebase_performance
Realtime Databasefirebase_database
beta
Remote Configfirebase_remote_config
beta

1Firebase AI Logic was formerly called "Vertex AI in Firebase" with the pluginfirebase_vertexai.

Caution: Firebase on Windows is not intended for production use cases, only local development workflows.

Try out an example app withAnalytics

Like all packages, thefirebase_analytics plugin comes with anexample program.

  1. Open a Flutter app that you've already configured to use Firebase (seeinstructions on this page).

  2. Access thelib directory of the app, then delete the existingmain.dartfile.

  3. From theGoogle Analyticsexample program repository,copy-paste the following two files into your app'slib directory:

    • main.dart
    • tabs_page.dart
  4. Run your Flutter app.

  5. Go to your app's Firebase project in theFirebase console, then clickAnalytics in the left-nav.

    1. ClickDashboard.IfAnalytics is working properly, the dashboard shows an active userin the "Users active in the last 30 minutes" panel (this might taketime to populate this panel).

    2. ClickDebugView. Enable the feature tosee all the events generated by the example program.

For more information about setting upAnalytics, visit the getting startedguides foriOS+,Android, andweb.

Next steps

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.