You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.2 KiB
40 lines
1.2 KiB
import 'dart:convert';
|
|
import 'package:http/http.dart' as http;
|
|
|
|
import '../main.dart';
|
|
import '../values/keys.dart';
|
|
|
|
class NotificationService {
|
|
sendPushMessage(String token, String title, String body) async {
|
|
try {
|
|
await http.post(Uri.parse('https://fcm.googleapis.com/fcm/send'),
|
|
headers: <String, String>{
|
|
'Content-Type': 'application/json',
|
|
'Authorization':
|
|
'key=$keyApiFirebase'
|
|
},
|
|
body: jsonEncode(<String, dynamic>{
|
|
'priority': 'high',
|
|
'data': <String, dynamic>{
|
|
'click_action': 'FLUTTER_NOTIFICATION_CLICK',
|
|
'status': 'done',
|
|
'body': body,
|
|
'title': title
|
|
},
|
|
"notification": <String, dynamic>{
|
|
"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 de $pseudo", "$text\".");
|
|
}
|
|
}
|