import 'dart:convert'; import 'package:http/http.dart' as http; import '../main.dart'; class NotificationService { sendPushMessage(String token, String title, String body) async { try { await http.post(Uri.parse('https://fcm.googleapis.com/fcm/send'), headers: { 'Content-Type': 'application/json', 'Authorization': 'key=AAAA56TmIPg:APA91bFeKMr_i6CbUuuUdFI1XkdaNE2A7OVHzxrPIsOSlDfhR6qzZwof7JNGxthWUKj1dRHQMheWNYaLbf3AtXUp9o4DX_gB2073yR4urqUEh9CjvnxVws_9g1cWMgmFS3EpaQEA3icC' }, body: jsonEncode({ 'priority': 'high', 'data': { 'click_action': 'FLUTTER_NOTIFICATION_CLICK', 'status': 'done', 'body': body, 'title': title }, "notification": { "title": title, "body": body, }, "to": token, })); } catch (e) { print("error push notification: ${e.toString()}"); } } sendNotifyComment(String token, String text) async { var pseudo = MyApp.userViewModel.userCurrent.pseudo; await sendPushMessage( token, "Nouveau message", "$pseudo à réagi à votre post,\"$text\"."); } }