You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Under dependencies, add the Firebase Analytics package firebase_analytics: ^6.0.0
Run flutter pub get to retrieve the package
Configure Android app in Firebase console
Begin by adding an Android app.
Set your Android package name, found in android/app/build.gradle under defaultConfig/applicationId
Set the app nickname to something appropriate, e.g. 'Android App'
Generate your debug signing certificate SHA-1
Right click on android/app_android.iml and choose Flutter > Open for editing in Android Studio
In the gradle inspection window expand Android / {$APP_NAME} / Tasks / android and open SigningReport
Copy the SHA1 from the debugAndroidTest variant
Paste this into Firebase console
Hit next
Download the generated google-services.json and paste into the android/app directory
Add Google Services SDK to android/build.gradle
Within the buildscript / dependencies object, add classpath 'com.google.gms:google-services:4.3.3'
Add plugins to android/app/build.gradle
After plugins are being applied (look for apply plugin:), add apply plugin: 'com.google.gms.google-services'
Within the dependencies object, add implementation 'com.google.firebase:firebase-analytics:17.5.0'
Run your Android app to talk with Firebase!
iOS
Given that you've already pre-configured Android, iOS setup is fairly straightforward.
Configure iOS app in Firebase console
Begin by adding an iOS app
Enter your package name as the bundle ID, found in android/app/build.gradle under defaultConfig/applicationId
Give it a nickname, e.g. 'iOS App'
Download the configuration file
Configure your iOS application
Open the ios/Runner.xcodeproj project in Xcode
Drag the GoogleService-Info.plist file into the root of your application
Check Copy items if needed and add to all targets
Run your iOS app to talk with Firebase!
Tracking PageRoute Transitions
To track PageRoute transitions, add a FirebaseAnalyticsObserver to the list of NavigatorObservers on your
Navigator, e.g. if you're using a MaterialApp:
You can also track transitions within your PageRoute (e.g. when the user switches from one tab to another) by
implementing RouteAware and subscribing it to FirebaseAnalyticsObserver. See [example/lib/tabs_page.dart][tabs_page]
for an example of how to wire that up.
This section assumes you have already run through the Analytics phase of the app and have Google services implemented.
Full documentation can be found here, but this is a summary to quickly
implement cloud messaging.
Android
Add package to pubspec.yaml
Under dependencies add the Firebase Cloud Messaging package firebase_messaging: ^7.0.0
Run flutter pub get to retrieve the package
Configure AndroidManifest.xml
Within android/app/src/main/AndroidManifest.xml under Manifest / Application / Activity node, add the following:
You may need to reinstall the application entirely to get notifications working.
Once complete, send a test notification
Configure background messaging (optional)
Within android/app/build.gradle add implementation 'com.google.firebase:firebase-messaging:20.2.4' to the dependencies node
Create a new file called Application.kt underneath android/app/src/main/kotlin/${PACKAGE_ID}/
Insert the below:
package com.example.app // change me
import io.flutter.app.FlutterApplication
import io.flutter.plugin.common.PluginRegistry
import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback
import io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin
import io.flutter.view.FlutterMain
import io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService
class Application : FlutterApplication(), PluginRegistrantCallback {
override fun onCreate() {
super.onCreate()
FlutterFirebaseMessagingService.setPluginRegistrant(this);
FlutterMain.startInitialization(this)
}
override fun registerWith(registry: PluginRegistry?) {
if (!registry!!.hasPlugin("io.flutter.plugins.firebasemessaging")) {
FirebaseMessagingPlugin.registerWith(registry!!.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin"));
}
}
}
Modify the android:name property within android/app/src/main/AndroidManifest.xml on the
Manifest / Application / Activity node from .MainActivity to .Application
iOS
Configure application within Xcode
You will need a signing request which can be easily generated using the documentation here. Make sure to keep a copy of any certificates / APN's generated.
You can use this CSR as many times as needed. I'd recommend your certificate name is the same as your app bundle, to avoid confusion.
Open ios/Runner.xcodeproj within Xcode.
Make sure the Runner application is selected in the left hand pane
Go to 'Signing & Capabilities'
Make sure the Automatically manage signing option is checked
Choose the appropriate team you want to generate certificates using.
Click the '+' underneath 'Signing & Capabilities' and double click 'Push notifications'
Click the '+' again and chose 'Background Modes'. Within background modes, enable 'Background fetch' and 'Remote notifications'
The eventual bundle ID will be the org value appended by a dot and then project-name.
For example, if you had a domain example.com and you wanted to create an eventual package id of com.example.myspecialapp you'd use the build options --project-name=myspecialapp --org=com.example