Add Function sendPushMessage and fix error UserService
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
e4364cfb1e
commit
5ef83b3340
@ -1,18 +1,30 @@
|
|||||||
import 'package:firebase_messaging/firebase_messaging.dart';
|
import 'dart:convert';
|
||||||
|
import 'package:http/http.dart' as http;
|
||||||
|
|
||||||
class NotificationService {
|
class NotificationService {
|
||||||
final _firebaseMessaging = FirebaseMessaging.instance;
|
sendPushMessage(String token, String title, String body) async {
|
||||||
|
try {
|
||||||
Future<void> handleBackgroundMessage(RemoteMessage message) async {
|
await http.post(Uri.parse('https://fcm.googleapis.com/fcm/send'),
|
||||||
print('Title: ${message.notification?.title}');
|
headers: <String, String>{
|
||||||
print('Body: ${message.notification?.body}');
|
'Content-Type': 'application/json',
|
||||||
print('Payload: ${message.data}');
|
'Authorization': 'key='
|
||||||
|
},
|
||||||
|
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");
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> initNotifications() async {
|
|
||||||
await _firebaseMessaging.requestPermission();
|
|
||||||
final token = await _firebaseMessaging.getToken();
|
|
||||||
print("Grrrpaw:"+token!);
|
|
||||||
//FirebaseMessaging.onBackgroundMessage(handleBackgroundMessage);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in new issue