From c2b020080df33d9071a797bb3909ef8f16bee068 Mon Sep 17 00:00:00 2001 From: ehhc Date: Wed, 12 Jun 2019 13:13:39 +0200 Subject: [PATCH 1/5] firebase_messaging: add additional documentation for the data in notifications --- packages/firebase_messaging/README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/packages/firebase_messaging/README.md b/packages/firebase_messaging/README.md index e692ef3346ba..478f0d290d97 100644 --- a/packages/firebase_messaging/README.md +++ b/packages/firebase_messaging/README.md @@ -68,6 +68,21 @@ Messages are sent to your Flutter app via the `onMessage`, `onLaunch`, and `onRe Additional reading: Firebase's [About FCM Messages](https://firebase.google.com/docs/cloud-messaging/concept-options). +## Notification messages with additional data +It is possible to include additional data in notificiation messages by adding them to the `"data"`-field of the message (see the following section). +Receiving this additional data is different on Android and iOS: + +Android: The message contains an additional field `data` containing the data +iOS: The data is directly appended to the message and the additional `data`-field is omitted. +To receive the data on both platforms the following can be done: +````dart +Future _handleNotification (Map message, bool dialog) async { + var data = message['data'] ?? message; + String expectedAttribute = data['expectedAttribute']; + /// [...] +} +```` + ## Sending Messages Refer to the [Firebase documentation](https://firebase.google.com/docs/cloud-messaging/) about FCM for all the details about sending messages to your app. When sending a notification message to an Android device, you need to make sure to set the `click_action` property of the message to `FLUTTER_NOTIFICATION_CLICK`. Otherwise the plugin will be unable to deliver the notification to your app when the users clicks on it in the system tray. From ca599cc4ab4e595235b830d1e40213fc2e2994ee Mon Sep 17 00:00:00 2001 From: Collin Jackson Date: Fri, 14 Jun 2019 17:52:56 -0700 Subject: [PATCH 2/5] Update pubspec.yaml and CHANGELOG for release --- packages/firebase_messaging/CHANGELOG.md | 4 ++++ packages/firebase_messaging/pubspec.yaml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/firebase_messaging/CHANGELOG.md b/packages/firebase_messaging/CHANGELOG.md index 620aeccacb67..8c835c690715 100644 --- a/packages/firebase_messaging/CHANGELOG.md +++ b/packages/firebase_messaging/CHANGELOG.md @@ -1,3 +1,7 @@ +## 5.0.4 + +* Update to README with explanation of differences in data format. + ## 5.0.3 * Update Dart code to conform to current Dart formatter. diff --git a/packages/firebase_messaging/pubspec.yaml b/packages/firebase_messaging/pubspec.yaml index baf0284bed23..10d2f8e2eae5 100644 --- a/packages/firebase_messaging/pubspec.yaml +++ b/packages/firebase_messaging/pubspec.yaml @@ -3,7 +3,7 @@ description: Flutter plugin for Firebase Cloud Messaging, a cross-platform messaging solution that lets you reliably deliver messages on Android and iOS. author: Flutter Team homepage: https://github.com/flutter/plugins/tree/master/packages/firebase_messaging -version: 5.0.3 +version: 5.0.4 flutter: plugin: From 880542dec269f84475be3863f2b7542ed48f7f85 Mon Sep 17 00:00:00 2001 From: Collin Jackson Date: Sun, 16 Jun 2019 11:26:02 -0700 Subject: [PATCH 3/5] Some tweaks to the firebase_messaging README --- packages/firebase_messaging/README.md | 10 +++++----- packages/firebase_messaging/example/lib/main.dart | 5 +++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/packages/firebase_messaging/README.md b/packages/firebase_messaging/README.md index 478f0d290d97..cbac7025b4cf 100644 --- a/packages/firebase_messaging/README.md +++ b/packages/firebase_messaging/README.md @@ -69,12 +69,12 @@ Messages are sent to your Flutter app via the `onMessage`, `onLaunch`, and `onRe Additional reading: Firebase's [About FCM Messages](https://firebase.google.com/docs/cloud-messaging/concept-options). ## Notification messages with additional data -It is possible to include additional data in notificiation messages by adding them to the `"data"`-field of the message (see the following section). -Receiving this additional data is different on Android and iOS: +It is possible to include additional data in notification messages by adding them to the `"data"`-field of the message. + +On Android, the message contains an additional field `data` containing the data. On iOS, the data is directly appended to the message and the additional `data`-field is omitted. + +To receive the data on both platforms: -Android: The message contains an additional field `data` containing the data -iOS: The data is directly appended to the message and the additional `data`-field is omitted. -To receive the data on both platforms the following can be done: ````dart Future _handleNotification (Map message, bool dialog) async { var data = message['data'] ?? message; diff --git a/packages/firebase_messaging/example/lib/main.dart b/packages/firebase_messaging/example/lib/main.dart index cf8e64347bed..3280b59f357b 100644 --- a/packages/firebase_messaging/example/lib/main.dart +++ b/packages/firebase_messaging/example/lib/main.dart @@ -9,9 +9,10 @@ import 'package:flutter/material.dart'; final Map _items = {}; Item _itemForMessage(Map message) { - final String itemId = message['data']['id']; + var data = message['data'] ?? message; + final String itemId = data['id']; final Item item = _items.putIfAbsent(itemId, () => Item(itemId: itemId)) - ..status = message['data']['status']; + ..status = data['status']; return item; } From adedac0602c3a2007490e8db5042daf99b26c1ad Mon Sep 17 00:00:00 2001 From: Collin Jackson Date: Sun, 16 Jun 2019 11:45:54 -0700 Subject: [PATCH 4/5] Update CHANGELOG --- packages/firebase_messaging/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/firebase_messaging/CHANGELOG.md b/packages/firebase_messaging/CHANGELOG.md index 8c835c690715..8404514c5d95 100644 --- a/packages/firebase_messaging/CHANGELOG.md +++ b/packages/firebase_messaging/CHANGELOG.md @@ -1,6 +1,6 @@ ## 5.0.4 -* Update to README with explanation of differences in data format. +* Updates to README and example with explanations of differences in data format. ## 5.0.3 From 370729472238e50de5bc614fc865de750f67e2b6 Mon Sep 17 00:00:00 2001 From: ehhc Date: Wed, 17 Jul 2019 09:08:58 +0200 Subject: [PATCH 5/5] firebase_messaging: fix the analyser issue --- packages/firebase_messaging/example/lib/main.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/firebase_messaging/example/lib/main.dart b/packages/firebase_messaging/example/lib/main.dart index 3280b59f357b..36de611f8bd3 100644 --- a/packages/firebase_messaging/example/lib/main.dart +++ b/packages/firebase_messaging/example/lib/main.dart @@ -9,7 +9,7 @@ import 'package:flutter/material.dart'; final Map _items = {}; Item _itemForMessage(Map message) { - var data = message['data'] ?? message; + final dynamic data = message['data'] ?? message; final String itemId = data['id']; final Item item = _items.putIfAbsent(itemId, () => Item(itemId: itemId)) ..status = data['status'];