postMessage method
Implementation
Future<RequestFcmModel> postMessage({
required List<String?> listtokens,
required MessageModel notification,
Map<String, String>? data,
}) async {
listtokens.removeWhere((element) => element == null || element.isEmpty);
if (listtokens.isEmpty) {
throw Exception('Empty id list');
}
var result = await http.post(
Uri.parse('$url/send'),
body: jsonEncode({
'registration_ids': listtokens,
'notification': notification.toMap(),
'data': data,
"android": {
"notification": {"image": notification.image}
},
"apns": {
"payload": {
"aps": {"mutable-content": 1}
},
"fcm_options": {"image": notification.image}
},
}),
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
'Authorization': 'Bearer $tokenServer'
},
);
return RequestFcmModel(
body: result.body,
isSend: result.statusCode == 200,
);
}