12345678910111213141516171819202122232425262728293031323334353637 |
- /// Packages used:
- /// firebase_messaging
- /// http
- ///
- /// Send push notification to device by [token]
- ///
- /// Get your token:
- /// await FirebaseMessaging.instance.getToken();
- Future<void> testFirebaseMessaging(String token) async {
- log('Testing cloud messaging');
-
- Map<String, String> headers = {
- HttpHeaders.authorizationHeader:
- 'key = YOUR SERVER KEY',
- HttpHeaders.contentTypeHeader: "application/json"
- };
- Map<String, dynamic> msg = {'mesgType': 'ACTION', 'action_id': '4664'};
- Map<String, dynamic> notification = {
- 'title': 'Title',
- 'body': 'body text',
- 'sound': 'default'
- };
- Map<String, dynamic> args = {
- 'registration_ids': [token],
- 'data': msg,
- 'notification': notification
- };
- final res = await post(
- Uri.parse('https://fcm.googleapis.com/fcm/send'),
- headers: headers,
- body: json.encode(args),
- );
- log('Code: ${res.statusCode} Body: ${res.body}');
- }
|