Firebase Cloud Messaging
What does it do?#
Firebase Cloud Messaging (FCM) is a cross-platform messaging solution that lets you reliably send messages at no cost.
Using FCM, you can notify a client app that new email or other data is available to sync. You can send notification messages to drive user re-engagement and retention. For use cases such as instant messaging, a message can transfer a payload of up to 4 KB to a client app.
Installation#
1. Make sure to initialize Firebase#
Follow this guide to install firebase_core and initialize Firebase if you haven't already.
2. Add dependency#
On the root of your Flutter project, run the following command to install the plugin:
3. Android Integration#
If you are using Flutter Android Embedding V2 (Flutter Version >= 1.12) then no additional integration steps are required for Android.
Flutter Android Embedding V1#
For the Flutter Android Embedding V1, the background service must be provided a callback to register plugins with the
background isolate. This is done by giving the FlutterFirebaseMessagingBackgroundService a callback to call your
application's onCreate method.
In particular, its Application class:
Which is usually reflected in the application's AndroidManifest.xml. E.g.:
Note: Not calling
FlutterFirebaseMessagingBackgroundService.setPluginRegistrantwill result in an exception being thrown when a message eventually comes through.
4. Apple Integration#
caution
Firebase Messaging plugin will not work if you disable method swizzling. Please remove or set to true the FirebaseAppDelegateProxyEnabled in your Info.plist file if it exists.
iOS & macOS require additional configuration before you can start receiving messages through Firebase. Read the integration documentation on how to setup iOS or macOS with Firebase Cloud Messaging.
5. Rebuild your app#
Once complete, rebuild your Flutter application:
Next Steps#
Once installed, you're ready to start using Firebase Cloud Messaging in your Flutter Project.
View the Usage documentation to get started.