Go to console

Add Firebase to your Flutter appplat_iosplat_android

Follow this guide to add Firebase products to a Flutter app.

Prerequisites

  • Install your preferred editor or IDE.

  • Make sure that your Flutter app targets iOS 8 or later.

  • Set up a physical iOS device or the iOS simulator for running your app.

    • For Cloud Messaging, complete the following tasks:

      • Set up a physical iOS device.
      • Obtain an Apple Push Notification Authentication Key for your Apple Developer account.
      • Enable Push Notifications in XCode under App > Capabilities.
    • For all other Firebase products, you can use either a physical iOS device or the iOS simulator.

  • Install Flutter for your specific operating system, including the following:

    • Flutter SDK
    • Supporting libraries
    • Platform-specific software and SDKs
  • Sign into Firebase using your Google account.

If you don't already have a Flutter app, you can complete the Get Started: Test Drive to create a new Flutter app using your preferred editor or IDE.

Step 1: Create a Firebase project

Before you can add Firebase to your Flutter app, you need to create a Firebase project to connect to your app. Visit Understand Firebase Projects to learn more about Firebase projects.

Step 2: Register your app with Firebase

  1. In the center of the Firebase console's project overview page, click the iOS icon (plat_ios) to launch the setup workflow.

    If you've already added an app to your Firebase project, click Add app to display the platform options.

  2. Enter your app’s bundle ID in the iOS bundle ID field.

    Find this bundle ID from your open project in XCode. Select the top-level app in the project navigator, then access the General tab. The Bundle Identifier value is the iOS bundle ID (for example, com.yourcompany.ios-app-name).

  3. (Optional) Enter other app information as prompted by the setup workflow.

  4. Click Register app.

Step 3: Add a Firebase configuration file

  1. Click Download GoogleService-Info.plist to obtain your Firebase iOS config file (GoogleService-Info.plist).

    • You can download your Firebase iOS config file again at any time.
    • Make sure the config file is not appended with additional characters, like (2).
  2. Using XCode, move the file into the Runner/Runner directory of your Flutter app.

  3. Back in the Firebase console setup workflow, click Next to skip the remaining steps.

  4. Continue to Add FlutterFire plugins.

Step 4: Add FlutterFire plugins

Flutter uses plugins to provide access to a wide range of platform-specific services, such as Firebase APIs. Plugins include platform-specific code to access services and APIs on each platform.

Firebase is accessed through a number of different libraries, one for each Firebase product (for example: Realtime Database, Authentication, Analytics, or Storage). Flutter provides a set of Firebase plugins, which are collectively called FlutterFire.

Since Flutter is a multi-platform SDK, each FlutterFire plugin is applicable for both iOS and Android. So, if you add any FlutterFire plugin to your Flutter app, it will be used by both the iOS and Android versions of your Firebase app.

Be sure to check the FlutterFire docs for the most up-to-date list of FlutterFire plugins.

  1. Ensure that your app is not currently running in your emulator or on your device.

  2. From the root directory of your Flutter app, open your pubspec.yaml file.

  3. Add the FlutterFire plugin for the Firebase Core Flutter SDK.

    dependencies:
      flutter:
        sdk: flutter
      # Add the dependency for the Firebase Core Flutter SDK
      firebase_core: ^0.4.0+9
    
  4. Add the FlutterFire plugins for the Firebase products that you want to use in your app.

    Analytics enabled

    dependencies:
      flutter:
        sdk: flutter
      # Check that you have this dependency (added in the previous step)
      firebase_core: ^0.4.0+9
    # Add the dependency for the FlutterFire plugin for Google Analytics firebase_analytics: ^5.0.2
    # Add the dependencies for any other Firebase products you want to use in your app # For example, to use Firebase Authentication and Cloud Firestore firebase_auth: ^0.14.0+5 cloud_firestore: ^0.12.9+5

    Analytics not enabled

    dependencies:
      flutter:
        sdk: flutter
      # Check that you have this dependency (added in the previous step)
      firebase_core: ^0.4.0+9
    # Add the dependencies for the Firebase products you want to use in your app # For example, to use Firebase Authentication and Cloud Firestore firebase_auth: ^0.14.0+5 cloud_firestore: ^0.12.9+5
  5. Run flutter packages get.
    For more information about managing packages and plugins, refer to Using Packages.

  6. If you added Analytics, run your app to send verification to Firebase that you've successfully integrated Firebase. Otherwise, you can skip the verification step.

You’re all set! Your Flutter app is registered and configured to use Firebase.

Try out an example app with Analytics

Like all packages, the firebase_analytics plugin comes with an example program.

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

  2. Access the lib directory of the app, then delete the existing main.dart file.

  3. From the Google Analytics example program repository, copy-paste the following two files into your app's lib directory:

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

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

    • Click Dashboard. If Analytics is working properly, the dashboard shows an active user in the "Users active in the last 30 minutes" panel (this might take time to populate this panel).

    • Click DebugView. Enable the feature to see all the events generated by the example program.

For more information about setting up Analytics, visit the getting started guides for iOS and for Android.

Next steps