Skip to content

Commit d15de37

Browse files
committed
refactor(push-notification): use FirebaseRequestBody model for notification
- Replace manual JSON map construction with FirebaseRequestBody model - Simplify requestBody creation by using FirebaseMessage and FirebaseNotification models - Remove redundant fields and improve code readability
1 parent ecde6b6 commit d15de37

File tree

1 file changed

+12
-17
lines changed

1 file changed

+12
-17
lines changed

lib/src/services/firebase_push_notification_client.dart

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:core/core.dart';
2+
import 'package:flutter_news_app_api_server_full_source_code/src/models/models.dart';
23
import 'package:flutter_news_app_api_server_full_source_code/src/services/push_notification_client.dart';
34
import 'package:http_client/http_client.dart';
45
import 'package:logging/logging.dart';
@@ -110,23 +111,17 @@ class FirebasePushNotificationClient implements IPushNotificationClient {
110111

111112
// Create a list of futures, one for each notification to be sent.
112113
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+
);
130125

131126
// Return the future from the post request.
132127
return _httpClient.post<void>(url, data: requestBody);

0 commit comments

Comments
 (0)