Add Firebase to your Flutter app
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.
Create a Firebase project
Step 2: Register your app with Firebase
In the center of the Firebase console's project overview page, click the iOS icon ( ) 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.
Click 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)
.
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 Cloud 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.
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.
Add the FlutterFire plugins for the Firebase products that you want to use in your app.
Run
flutter packages get
.
For more information about managing packages and plugins, refer to Using Packages.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
Run your Flutter app.
Go to your app's Firebase project in the Firebase console, then click Analytics in the left-nav.
For more information about setting up Analytics, visit the getting started guides for iOS and for Android.
Next steps
Review the list of FlutterFire plugins.
Get hands-on experience with the Firebase Flutter Codelab.
Prepare to launch your app:
- Set up budget alerts for your project in the Google Cloud Console.
- Monitor the Usage and billing dashboard in the Firebase console to get an overall picture of your project's usage across multiple Firebase services.
- Review the Firebase launch checklist.