Skip to content

Instantly share code, notes, and snippets.

@zeeshan-mehdi
Created July 1, 2021 16:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zeeshan-mehdi/68d7993805a71a24fbad1eac9012948c to your computer and use it in GitHub Desktop.
Save zeeshan-mehdi/68d7993805a71a24fbad1eac9012948c to your computer and use it in GitHub Desktop.
Future<void> sendNotification(String body, String title, User user) async {
final data = {
"notification": {"body": "$body", "title": "$title"},
"priority": "high",
"data": {"click_action": "FLUTTER_NOTIFICATION_CLICK", "id": "messages", "status": "done"},
"to": "${user.deviceToken}"
};
final String url = 'https://fcm.googleapis.com/fcm/send';
final client = new http.Client();
final response = await client.post(
url,
headers: {
HttpHeaders.contentTypeHeader: 'application/json',
HttpHeaders.authorizationHeader: "key=${setting.value.fcmKey}",
},
body: json.encode(data),
);
if (response.statusCode != 200) {
print('notification sending failed');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment