Created
July 1, 2021 16:09
-
-
Save zeeshan-mehdi/68d7993805a71a24fbad1eac9012948c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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