
I made a dart function to send push notification to users whena doc is created in the db, but its not working, the function it self doesnt work when it gets to the post request
TypeScript
Future<void> sendFeeNotification(
String token, String lang, String amount) async {
try {
const String url = "https://fcm.googleapis.com/v1/projects/$projectName/messages:send";
// Create the notification payload
Map<String, dynamic> notificationPayload = {
"message": {
"token": token,
"notification": {
"title": lang == 'en'
? 'A new pending fee has been added to your account for $amount'
: 'Une nouvelle redevance en attente a été ajoutée à votre compte pour $amount',
"body": lang == 'en'
? 'Please check your account for more details'
: 'Veuillez vérifier votre compte pour plus de détails',
},
}
};
try {
print('Sending notification...');
print(serverKey);
//when it gets here nothing happens
final response = await http.post(
Uri.parse(url),
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer $serverKey",
},
body: jsonEncode(notificationPayload),
);
print('Response: ${response.body}');
if (response.statusCode == 200) {
print('Notification sent successfully');
} else {
print('Failed to send notification: ${response.body}');
}
} catch (e) {
print('Error sending notification: $e');
}
} catch (e) {
print('Error sending notification: $e');
}
}
TL;DR
Developers are encountering issues with a Dart function for push notifications. The function fails at the HTTP POST request part, with no response. The potential solution is to check the validity of the server key and the correct construction of the notification payload.Recommended threads
- 503 Timeout when Updating or Upserting D...
Hey I’m running into an issue when trying to update or upsert a row in Appwrite. The request hangs for a while and then throws this error: ``` AppwriteException...
- Hola equipo de soporte,
Hola equipo de soporte, Estoy desarrollando una Function en Appwrite Cloud con Node.js 22 y el siguiente package.json: { "name": "upload-whitelist", "type"...
- Sites 30MB limit from GitHub
I’m deploying a site from github as Other type on the Hobby plan. It is actually a Flutter web app but it’s in a subdirectory with the root being an html landin...
