This commit is contained in:
Hamza-Ayed
2024-12-01 10:17:23 +02:00
parent 5aeb3cf685
commit 0129162309
34 changed files with 1317 additions and 875 deletions

View File

@@ -383,6 +383,70 @@ class NotificationController extends GetxController {
print('Notifications scheduled every 5 seconds');
}
void showTimerNotification(String title, String message, String tone) async {
final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
FlutterLocalNotificationsPlugin();
// Setup Android notification
final AndroidNotificationDetails android = AndroidNotificationDetails(
'high_importance_channel',
'High Importance Notifications',
importance: Importance.max,
priority: Priority.high,
showWhen: false,
sound: RawResourceAndroidNotificationSound(
tone), // tone without the file extension
);
// Setup iOS notification
const DarwinNotificationDetails ios = DarwinNotificationDetails(
sound: 'default',
presentAlert: true,
presentBadge: true,
presentSound: true,
);
final NotificationDetails details =
NotificationDetails(android: android, iOS: ios);
// Request permission on Android
if (Platform.isAndroid) {
if (await Permission.scheduleExactAlarm.isDenied) {
if (await Permission.scheduleExactAlarm.request().isGranted) {
print('SCHEDULE_EXACT_ALARM permission granted');
} else {
print('SCHEDULE_EXACT_ALARM permission denied');
return;
}
}
}
// Timer duration (e.g., 120 seconds countdown)
int countdown = 12;
// Display the notification initially with the full countdown time
// Timer to update the notification every second
Timer.periodic(const Duration(seconds: 1), (timer) async {
// if (countdown > 0) {
// Update the existing notification with the updated countdown
// Decrease the countdown by 1
countdown--;
// } else {
// // Cancel the timer when the countdown reaches zero
// timer.cancel();
// }
});
await flutterLocalNotificationsPlugin.show(
0,
title,
'$message Remaining: $countdown seconds', // Initial message
details,
);
print('Notification will update every second');
}
// Callback when the notification is tapped
void onDidReceiveNotificationResponse(NotificationResponse response) {
handleNotificationResponse(response);
@@ -448,7 +512,7 @@ class NotificationController extends GetxController {
if (orderData is List && orderData.length == 34) {
closeOverLay();
Get.put(HomeCaptainController()).changeRideId();
Get.to(() => OrderSpeedRequest(), arguments: {'myListString': data});
Get.to(() => OrderRequestPage(), arguments: {'myListString': data});
} else {
Log.print('Invalid order data');
}