|
1 | 1 | import 'package:core/core.dart'; |
| 2 | +import 'package:flutter_news_app_api_server_full_source_code/src/models/models.dart'; |
2 | 3 | import 'package:flutter_news_app_api_server_full_source_code/src/services/push_notification_client.dart'; |
3 | 4 | import 'package:http_client/http_client.dart'; |
4 | 5 | import 'package:logging/logging.dart'; |
@@ -110,23 +111,17 @@ class FirebasePushNotificationClient implements IPushNotificationClient { |
110 | 111 |
|
111 | 112 | // Create a list of futures, one for each notification to be sent. |
112 | 113 | final sendFutures = deviceTokens.map((token) { |
113 | | - final requestBody = { |
114 | | - 'message': { |
115 | | - 'token': token, |
116 | | - 'notification': { |
117 | | - 'title': payload.title, |
118 | | - 'body': payload.title, |
119 | | - if (payload.imageUrl != null) 'image': payload.imageUrl, |
120 | | - }, |
121 | | - // Reconstruct the data payload from the explicit fields |
122 | | - 'data': { |
123 | | - 'notificationId': payload.notificationId, |
124 | | - 'notificationType': payload.notificationType.name, |
125 | | - 'contentType': payload.contentType.name, |
126 | | - 'contentId': payload.contentId, |
127 | | - }, |
128 | | - }, |
129 | | - }; |
| 114 | + final requestBody = FirebaseRequestBody( |
| 115 | + message: FirebaseMessage( |
| 116 | + token: token, |
| 117 | + notification: FirebaseNotification( |
| 118 | + title: payload.title, |
| 119 | + body: payload.title, |
| 120 | + image: payload.imageUrl, |
| 121 | + ), |
| 122 | + data: payload, |
| 123 | + ), |
| 124 | + ); |
130 | 125 |
|
131 | 126 | // Return the future from the post request. |
132 | 127 | return _httpClient.post<void>(url, data: requestBody); |
|
0 commit comments