This commit is contained in:
Hamza-Ayed
2024-06-22 13:30:02 +03:00
parent 976e5dfa4d
commit 2bd242b28c
6 changed files with 21 additions and 175 deletions

View File

@@ -37,8 +37,7 @@ class FirebaseMessagesController extends GetxController {
// Get the current notification settings
NotificationSettings? notificationSettings =
await FirebaseMessaging.instance.getNotificationSettings();
print(
'Notification authorization status: ${notificationSettings.authorizationStatus}');
'Notification authorization status: ${notificationSettings.authorizationStatus}';
// Call the update function if needed
update();
@@ -62,7 +61,6 @@ class FirebaseMessagesController extends GetxController {
provisional: false,
sound: true,
);
print('User granted permission: ${settings.authorizationStatus}');
messaging.setForegroundNotificationPresentationOptions(
alert: true, badge: true, sound: true);
}
@@ -79,16 +77,13 @@ class FirebaseMessagesController extends GetxController {
},
body: {},
);
// print(res.body);
var jsonResponse = jsonDecode(res.body);
// print(jsonResponse);
if (jsonResponse['status'] == 'success') {
dataTokens = jsonResponse['data'];
for (var i = 0; i < dataTokens.length; i++) {
tokens.add(jsonResponse['data'][i]['token']);
}
box.write(BoxName.tokens, tokens);
print(box.read(BoxName.tokens));
} else {
Get.defaultDialog(title: "Warning", middleText: "Server Error");
}
@@ -111,14 +106,12 @@ class FirebaseMessagesController extends GetxController {
FirebaseMessaging.onBackgroundMessage((RemoteMessage message) async {
// Handle background message
if (message.data.isNotEmpty && message.notification != null) {
print(message.notification?.title);
fireBaseTitles(message);
}
});
FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) {
if (message.data.isNotEmpty && message.notification != null) {
print(message.notification?.title);
fireBaseTitles(message);
}
});
@@ -230,9 +223,7 @@ class FirebaseMessagesController extends GetxController {
token: driverList[0].toString(),
remoteID: driverList[2].toString(),
));
} catch (e) {
print('Error navigating to PassengerCallPage: $e');
}
} catch (e) {}
} else if (message.notification!.title! == 'Call Income from Driver') {
try {
var myListString = message.data['passengerList'];
@@ -250,9 +241,7 @@ class FirebaseMessagesController extends GetxController {
token: driverList[0].toString(),
remoteID: driverList[2].toString(),
));
} catch (e) {
print('Error navigating to PassengerCallPage: $e');
}
} catch (e) {}
} else if (message.notification!.title! == 'Call End') {
try {
var myListString = message.data['passengerList'];
@@ -266,9 +255,7 @@ class FirebaseMessagesController extends GetxController {
}
// Assuming GetMaterialApp is initialized and context is valid for navigation
// Get.off(const CallPage());
} catch (e) {
print('Error navigating to PassengerCallPage: $e');
}
} catch (e) {}
} else if (message.notification!.title! == 'Driver Cancel Your Trip') {
// Get.snackbar(
// 'You will be pay the cost to driver or we will get it from you on next trip'
@@ -412,7 +399,6 @@ class FirebaseMessagesController extends GetxController {
// Save the list of tokens back to the box.
// box.write(BoxName.tokens, tokens);
tokens = box.read(BoxName.tokens);
// print(tokens);
for (var i = 0; i < tokens.length; i++) {
http
.post(Uri.parse('https://fcm.googleapis.com/fcm/send'),
@@ -435,9 +421,7 @@ class FirebaseMessagesController extends GetxController {
'to': tokens[i],
}))
.whenComplete(() {})
.catchError((e) {
print('sendNotification() error: $e');
});
.catchError((e) {});
}
}
@@ -464,7 +448,6 @@ class FirebaseMessagesController extends GetxController {
// }))
// .whenComplete(() {})
// .catchError((e) {
// print('sendNotification() error: $e');
// });
// }
// }
@@ -494,15 +477,12 @@ class FirebaseMessagesController extends GetxController {
if (response.statusCode == 200) {
// Notification sent successfully
print('Notification sent successfully');
} else {
// Handle error response
print(
'Failed to send notification. Status code: ${response.statusCode}');
'Failed to send notification. Status code: ${response.statusCode}';
}
} catch (e) {
// Handle other exceptions
print('sendNotification() error: $e');
}
}
@@ -533,15 +513,12 @@ class FirebaseMessagesController extends GetxController {
if (response.statusCode == 200) {
// Notification sent successfully
print('Notification sent successfully');
} else {
// Handle error response
print(
'Failed to send notification. Status code: ${response.statusCode}');
'Failed to send notification. Status code: ${response.statusCode}';
}
} catch (e) {
// Handle other exceptions
print('sendNotification() error: $e');
}
}
@@ -571,15 +548,12 @@ class FirebaseMessagesController extends GetxController {
if (response.statusCode == 200) {
// Notification sent successfully
print('Notification sent successfully');
} else {
// Handle error response
print(
'Failed to send notification. Status code: ${response.statusCode}');
'Failed to send notification. Status code: ${response.statusCode}';
}
} catch (e) {
// Handle other exceptions
print('sendNotification() error: $e');
}
}
@@ -610,15 +584,12 @@ class FirebaseMessagesController extends GetxController {
if (response.statusCode == 200) {
// Notification sent successfully
print('Notification sent successfully');
} else {
// Handle error response
print(
'Failed to send notification. Status code: ${response.statusCode}');
'Failed to send notification. Status code: ${response.statusCode}';
}
} catch (e) {
// Handle other exceptions
print('sendNotification() error: $e');
}
}
}