9/19/2
This commit is contained in:
@@ -134,10 +134,10 @@ class FirebaseMessagesController extends GetxController {
|
||||
'body': message.notification!.body
|
||||
});
|
||||
} else if (message.notification!.title == 'Cancel Trip') {
|
||||
// if (Platform.isAndroid) {
|
||||
// NotificationController().showNotification(
|
||||
// 'Cancel Trip'.tr, 'Passenger Cancel Trip'.tr, 'cancel', '');
|
||||
// }
|
||||
if (Platform.isAndroid) {
|
||||
NotificationController().showNotification(
|
||||
'Cancel Trip'.tr, 'Passenger Cancel Trip'.tr, 'cancel', '');
|
||||
}
|
||||
cancelTripDialog();
|
||||
} else if (message.notification!.title == 'VIP Order') {
|
||||
var myListString = message.data['DriverList'];
|
||||
@@ -166,7 +166,7 @@ class FirebaseMessagesController extends GetxController {
|
||||
} else if (message.notification!.title! == 'message From passenger') {
|
||||
if (Platform.isAndroid) {
|
||||
NotificationController()
|
||||
.showNotification('message From passenger', ''.tr, 'tone2', '');
|
||||
.showNotification('message From passenger'.tr, ''.tr, 'tone2', '');
|
||||
}
|
||||
passengerDialog(message.notification!.body!);
|
||||
|
||||
@@ -448,7 +448,7 @@ class FirebaseMessagesController extends GetxController {
|
||||
// ));
|
||||
// }
|
||||
|
||||
void sendNotificationAll(String title, body) async {
|
||||
void sendNotificationAll(String title, body, tone) async {
|
||||
// Get the token you want to subtract.
|
||||
String token = box.read(BoxName.tokenFCM);
|
||||
tokens = box.read(BoxName.tokens);
|
||||
@@ -483,26 +483,41 @@ class FirebaseMessagesController extends GetxController {
|
||||
// Send the notification
|
||||
final response = await http
|
||||
.post(
|
||||
Uri.parse(
|
||||
'https://fcm.googleapis.com/v1/projects/ride-b1bd8/messages:send'),
|
||||
headers: <String, String>{
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': 'Bearer $accessToken',
|
||||
},
|
||||
body: jsonEncode({
|
||||
'notification': <String, dynamic>{
|
||||
Uri.parse(
|
||||
'https://fcm.googleapis.com/v1/projects/ride-b1bd8/messages:send'),
|
||||
headers: <String, String>{
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': 'Bearer $accessToken',
|
||||
},
|
||||
body: jsonEncode({
|
||||
'message': {
|
||||
'token': token,
|
||||
'notification': {
|
||||
'title': title,
|
||||
'body': body,
|
||||
'sound': 'ding.wav'
|
||||
},
|
||||
'priority': 'high',
|
||||
'data': <String, dynamic>{
|
||||
'click_action': 'FLUTTER_NOTIFICATION_CLICK',
|
||||
'id': '1',
|
||||
'status': 'done'
|
||||
// 'data': {
|
||||
// 'DriverList': jsonEncode(data),
|
||||
// },
|
||||
'android': {
|
||||
'priority': 'high', // Set priority to high
|
||||
'notification': {
|
||||
'sound': tone,
|
||||
},
|
||||
},
|
||||
'to': tokens[i],
|
||||
}))
|
||||
'apns': {
|
||||
'headers': {
|
||||
'apns-priority': '10', // Set APNs priority to 10
|
||||
},
|
||||
'payload': {
|
||||
'aps': {
|
||||
'sound': tone,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
)
|
||||
.whenComplete(() {})
|
||||
.catchError((e) {});
|
||||
}
|
||||
@@ -568,16 +583,32 @@ class FirebaseMessagesController extends GetxController {
|
||||
'Authorization': 'Bearer $accessToken',
|
||||
},
|
||||
body: jsonEncode({
|
||||
'notification': <String, dynamic>{
|
||||
'title': title,
|
||||
'body': body,
|
||||
'sound': tone
|
||||
'message': {
|
||||
'token': token,
|
||||
'notification': {
|
||||
'title': title,
|
||||
'body': body,
|
||||
},
|
||||
'data': {
|
||||
'passengerList': map,
|
||||
},
|
||||
'android': {
|
||||
'priority': 'high', // Set priority to high
|
||||
'notification': {
|
||||
'sound': tone,
|
||||
},
|
||||
},
|
||||
'apns': {
|
||||
'headers': {
|
||||
'apns-priority': '10', // Set APNs priority to 10
|
||||
},
|
||||
'payload': {
|
||||
'aps': {
|
||||
'sound': tone,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
'data': {
|
||||
'passengerList': map,
|
||||
},
|
||||
'priority': 'high',
|
||||
'to': token,
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -593,7 +624,7 @@ class FirebaseMessagesController extends GetxController {
|
||||
}
|
||||
|
||||
void sendNotificationToPassengerTokenCALL(
|
||||
String title, body, token, List<String> map) async {
|
||||
String title, body, token, List<String> map, String tone) async {
|
||||
try {
|
||||
String serviceAccountKeyJson = '''{
|
||||
"type": "service_account",
|
||||
@@ -635,14 +666,18 @@ class FirebaseMessagesController extends GetxController {
|
||||
'passengerList': jsonEncode(map),
|
||||
},
|
||||
'android': {
|
||||
'priority': 'high', // Set priority to high
|
||||
'notification': {
|
||||
'sound': 'iphone_ringtone.wav',
|
||||
'sound': tone,
|
||||
},
|
||||
},
|
||||
'apns': {
|
||||
'headers': {
|
||||
'apns-priority': '10', // Set APNs priority to 10
|
||||
},
|
||||
'payload': {
|
||||
'aps': {
|
||||
'sound': 'iphone_ringtone.wav',
|
||||
'sound': tone,
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -707,11 +742,15 @@ class FirebaseMessagesController extends GetxController {
|
||||
'DriverList': jsonEncode([]),
|
||||
},
|
||||
'android': {
|
||||
'priority': 'high', // Set priority to high
|
||||
'notification': {
|
||||
'sound': tone,
|
||||
},
|
||||
},
|
||||
'apns': {
|
||||
'headers': {
|
||||
'apns-priority': '10', // Set APNs priority to 10
|
||||
},
|
||||
'payload': {
|
||||
'aps': {
|
||||
'sound': tone,
|
||||
@@ -779,11 +818,15 @@ class FirebaseMessagesController extends GetxController {
|
||||
'DriverList': jsonEncode(data),
|
||||
},
|
||||
'android': {
|
||||
'priority': 'high', // Set priority to high
|
||||
'notification': {
|
||||
'sound': tone,
|
||||
},
|
||||
},
|
||||
'apns': {
|
||||
'headers': {
|
||||
'apns-priority': '10', // Set APNs priority to 10
|
||||
},
|
||||
'payload': {
|
||||
'aps': {
|
||||
'sound': tone,
|
||||
@@ -809,7 +852,7 @@ class FirebaseMessagesController extends GetxController {
|
||||
}
|
||||
|
||||
void sendNotificationToDriverMapPolyline(String title, String body,
|
||||
String token, List<String> data, String polylineJson) async {
|
||||
String token, List<String> data, String polylineJson, String tone) async {
|
||||
try {
|
||||
String serviceAccountKeyJson = '''{
|
||||
"type": "service_account",
|
||||
@@ -841,18 +884,32 @@ class FirebaseMessagesController extends GetxController {
|
||||
'Authorization': 'Bearer $accessToken',
|
||||
},
|
||||
body: jsonEncode({
|
||||
'notification': <String, dynamic>{
|
||||
'title': title,
|
||||
'body': body,
|
||||
// 'sound': 'tone2.wav',
|
||||
'sound': 'order.wav'
|
||||
'message': {
|
||||
'token': token,
|
||||
'notification': {
|
||||
'title': title,
|
||||
'body': body,
|
||||
},
|
||||
'data': {
|
||||
'DriverList': jsonEncode(data),
|
||||
},
|
||||
'android': {
|
||||
'priority': 'high', // Set priority to high
|
||||
'notification': {
|
||||
'sound': tone,
|
||||
},
|
||||
},
|
||||
'apns': {
|
||||
'headers': {
|
||||
'apns-priority': '10', // Set APNs priority to 10
|
||||
},
|
||||
'payload': {
|
||||
'aps': {
|
||||
'sound': tone,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
'data': {
|
||||
'DriverList': data,
|
||||
'PolylineJson': polylineJson,
|
||||
},
|
||||
'priority': 'high',
|
||||
'to': token,
|
||||
}),
|
||||
);
|
||||
|
||||
|
||||
@@ -14,11 +14,10 @@ import '../home/captin/home_captain_controller.dart';
|
||||
class NotificationController extends GetxController {
|
||||
final FlutterLocalNotificationsPlugin _flutterLocalNotificationsPlugin =
|
||||
FlutterLocalNotificationsPlugin();
|
||||
|
||||
// Initializes the local notifications plugin
|
||||
Future<void> initNotifications() async {
|
||||
const AndroidInitializationSettings android =
|
||||
AndroidInitializationSettings('app_icon');
|
||||
AndroidInitializationSettings('@mipmap/launcher_icon');
|
||||
|
||||
const InitializationSettings initializationSettings =
|
||||
InitializationSettings(android: android);
|
||||
@@ -175,3 +174,67 @@ class NotificationController extends GetxController {
|
||||
// display a dialog with the notification details, tap ok to go to another page
|
||||
}
|
||||
}
|
||||
// import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
||||
// import 'package:get/get.dart';
|
||||
// import 'package:timezone/data/latest.dart' as tz;
|
||||
// import 'package:timezone/timezone.dart' as tz;
|
||||
|
||||
// class NotificationController extends GetxController {
|
||||
// final FlutterLocalNotificationsPlugin _flutterLocalNotificationsPlugin =
|
||||
// FlutterLocalNotificationsPlugin();
|
||||
|
||||
// @override
|
||||
// void onInit() {
|
||||
// super.onInit();
|
||||
// initNotifications();
|
||||
// tz.initializeTimeZones();
|
||||
// }
|
||||
|
||||
// // Initializes the local notifications plugin
|
||||
// Future<void> initNotifications() async {
|
||||
// const AndroidInitializationSettings android =
|
||||
// AndroidInitializationSettings('@mipmap/launcher_icon');
|
||||
// const InitializationSettings initializationSettings =
|
||||
// InitializationSettings(android: android);
|
||||
// await _flutterLocalNotificationsPlugin.initialize(initializationSettings);
|
||||
// }
|
||||
|
||||
// // Displays a notification with the given title and message
|
||||
// void showNotification(
|
||||
// String title, String message, String tone, String payLoad) async {
|
||||
// AndroidNotificationDetails android = AndroidNotificationDetails(
|
||||
// 'your channel id', 'your channel name',
|
||||
// importance: Importance.max,
|
||||
// priority: Priority.high,
|
||||
// showWhen: false,
|
||||
// sound: RawResourceAndroidNotificationSound(tone));
|
||||
|
||||
// NotificationDetails details = NotificationDetails(android: android);
|
||||
// await _flutterLocalNotificationsPlugin.show(0, title, message, details);
|
||||
// }
|
||||
|
||||
// // Schedules a notification for a specific time
|
||||
// Future<void> scheduleNotification(
|
||||
// String title, String body, DateTime scheduledTime) async {
|
||||
// await _flutterLocalNotificationsPlugin.zonedSchedule(
|
||||
// 0,
|
||||
// title,
|
||||
// body,
|
||||
// tz.TZDateTime.from(scheduledTime, tz.local),
|
||||
// const NotificationDetails(
|
||||
// android: AndroidNotificationDetails(
|
||||
// 'your_channel_id',
|
||||
// 'your_channel_name',
|
||||
// channelDescription: 'your_channel_description',
|
||||
// importance: Importance.max,
|
||||
// priority: Priority.high,
|
||||
// showWhen: false,
|
||||
// ),
|
||||
// ),
|
||||
// androidAllowWhileIdle: true,
|
||||
// uiLocalNotificationDateInterpretation:
|
||||
// UILocalNotificationDateInterpretation.absoluteTime,
|
||||
// matchDateTimeComponents: DateTimeComponents.time,
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
|
||||
Reference in New Issue
Block a user