Add Firebase to your Flutter app
Note: Firebase supports frameworks like Flutter on a best-effort basis. These integrations are not covered by Firebase Support and may not have full feature parity with the official Firebase SDKs.
For iOS
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.
Create a Firebase project
Step 2: Register your app with Firebase
Important: If you’re releasing your Flutter app on both iOS and Android, register both the iOS and Android versions of your app with the same Firebase project.
- 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.
- 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
). - (Optional) Enter other app information as prompted by the setup workflow.
- App nickname: An internal, convenience identifier that is only visible to you in the Firebase console
- App Store ID: Used by Firebase Dynamic Links to redirect users to your App Store page and by Google Analytics to import conversion events into Google Ads. If your app doesn’t yet have an App Store ID, you can add the ID later in your Project Settings.
4. Click the Register app.
Step 3: Add a Firebase configuration file
- 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)
.
- Note: The Firebase config file contains unique, but non-secret identifiers for your project.
Visit Understand Firebase Projects to learn more about this config file. - Using XCode, move the file into the
Runner/Runner
directory of your Flutter app. - Back in the Firebase console-setup workflow, click Next to skip the remaining steps.
- 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.
Note: The steps in this section are an example of how to add Flutter-supported Firebase products) to your Flutter-Firebase app (both the iOS and Android versions).
- Ensure that your app is not currently running in your emulator or on your device.
- From the root directory of your Flutter app, open your
pubspec.yaml
file. - Add the FlutterFire plugin for the Firebase Core Flutter SDK.
Note: All Flutter-Firebase apps, both iOS and Android versions, require the firebase_core
plugin for Flutter.
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 Enable:
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.
- Open a Flutter app that you’ve already configured to use Firebase (see instructions on this page).
- Access the
lib
directory of the app, then delete the existingmain.dart
file. - 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.
For Android, you can read and more information check out below
Check out Google Analytics Integration