|
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'; |
@@ -94,26 +95,19 @@ class OneSignalPushNotificationClient implements IPushNotificationClient { |
94 | 95 | // app_dependencies.dart. The final URL will be: `https://onesignal.com/api/v1/notifications` |
95 | 96 | const url = 'notifications'; |
96 | 97 |
|
97 | | - // Construct the OneSignal API request body. |
98 | | - final requestBody = { |
99 | | - 'app_id': appId, |
100 | | - 'include_player_ids': deviceTokens, |
101 | | - 'headings': {'en': payload.title}, |
102 | | - 'contents': {'en': payload.title}, |
103 | | - if (payload.imageUrl != null) 'big_picture': payload.imageUrl, |
104 | | - // Reconstruct the data payload from the explicit fields |
105 | | - 'data': { |
106 | | - 'notificationId': payload.notificationId, |
107 | | - 'notificationType': payload.notificationType.name, |
108 | | - 'contentType': payload.contentType.name, |
109 | | - 'contentId': payload.contentId, |
110 | | - }, |
111 | | - }; |
112 | | - |
113 | 98 | _log.finer( |
114 | 99 | 'Sending OneSignal batch of ${deviceTokens.length} notifications.', |
115 | 100 | ); |
116 | 101 |
|
| 102 | + final requestBody = OneSignalRequestBody( |
| 103 | + appId: appId, |
| 104 | + includePlayerIds: deviceTokens, |
| 105 | + headings: {'en': payload.title}, |
| 106 | + contents: {'en': payload.title}, |
| 107 | + bigPicture: payload.imageUrl, |
| 108 | + data: payload, |
| 109 | + ); |
| 110 | + |
117 | 111 | try { |
118 | 112 | // The OneSignal API returns a JSON object with details about the send, |
119 | 113 | // including errors for invalid player IDs. |
|
0 commit comments