Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/firebase_messaging/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 5.1.2

* Updates to README and example with explanations of differences in data format.

## 5.1.1

* Update README with more detailed integration instructions.
Expand Down
15 changes: 15 additions & 0 deletions packages/firebase_messaging/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,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 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:

````dart
Future<void> _handleNotification (Map<dynamic, dynamic> 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.

Expand Down
5 changes: 3 additions & 2 deletions packages/firebase_messaging/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import 'package:flutter/material.dart';

final Map<String, Item> _items = <String, Item>{};
Item _itemForMessage(Map<String, dynamic> message) {
final String itemId = message['data']['id'];
final dynamic 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;
}

Expand Down
3 changes: 2 additions & 1 deletion packages/firebase_messaging/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ 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 <[email protected]>
homepage: https://github.com/flutter/plugins/tree/master/packages/firebase_messaging
version: 5.1.1

version: 5.1.2

flutter:
plugin:
Expand Down