12/18/1
This commit is contained in:
@@ -3,9 +3,9 @@ import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:SEFER/constant/colors.dart';
|
||||
import 'package:SEFER/views/home/Captin/orderCaptin/order_request_page.dart';
|
||||
import 'package:SEFER/views/home/Captin/orderCaptin/order_speed_request.dart';
|
||||
import 'package:sefer_driver/constant/colors.dart';
|
||||
import 'package:sefer_driver/views/home/Captin/orderCaptin/order_request_page.dart';
|
||||
import 'package:sefer_driver/views/home/Captin/orderCaptin/order_speed_request.dart';
|
||||
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
@@ -66,38 +66,46 @@ class NotificationController extends GetxController {
|
||||
htmlFormatContent: true,
|
||||
htmlFormatContentTitle: true,
|
||||
);
|
||||
|
||||
AndroidNotificationDetails android = AndroidNotificationDetails(
|
||||
'high_importance_channel', // Use the same ID as before
|
||||
'high_importance_channel',
|
||||
'High Importance Notifications',
|
||||
importance: Importance.high,
|
||||
importance: Importance.max,
|
||||
priority: Priority.high,
|
||||
styleInformation: bigTextStyleInformation,
|
||||
playSound: true,
|
||||
sound: RawResourceAndroidNotificationSound(tone),
|
||||
// audioAttributesUsage: AudioAttributesUsage.alarm,
|
||||
visibility: NotificationVisibility.public,
|
||||
autoCancel: false,
|
||||
color: AppColor.primaryColor,
|
||||
showProgress: true,
|
||||
showWhen: true,
|
||||
ongoing: true,
|
||||
enableVibration: true,
|
||||
vibrationPattern: Int64List.fromList([0, 1000, 500, 1000]),
|
||||
timeoutAfter: 14500,
|
||||
setAsGroupSummary: true,
|
||||
subText: message, fullScreenIntent: true,
|
||||
actions: [
|
||||
AndroidNotificationAction(
|
||||
allowGeneratedReplies: true,
|
||||
'id',
|
||||
title.tr,
|
||||
titleColor: AppColor.bronze,
|
||||
showsUserInterface: true,
|
||||
)
|
||||
],
|
||||
category: AndroidNotificationCategory.progress,
|
||||
);
|
||||
|
||||
// AndroidNotificationDetails android = AndroidNotificationDetails(
|
||||
// 'high_importance_channel', // Use the same ID as before
|
||||
// 'High Importance Notifications',
|
||||
// importance: Importance.high,
|
||||
// priority: Priority.high,
|
||||
// styleInformation: bigTextStyleInformation,
|
||||
// playSound: true,
|
||||
// sound: RawResourceAndroidNotificationSound(tone),
|
||||
// // audioAttributesUsage: AudioAttributesUsage.alarm,
|
||||
// visibility: NotificationVisibility.public,
|
||||
// autoCancel: false,
|
||||
// color: AppColor.primaryColor,
|
||||
// showProgress: true,
|
||||
// showWhen: true,
|
||||
// ongoing: true,
|
||||
// enableVibration: true,
|
||||
// vibrationPattern: Int64List.fromList([0, 1000, 500, 1000]),
|
||||
// timeoutAfter: 14500,
|
||||
// setAsGroupSummary: true,
|
||||
// subText: message, fullScreenIntent: true,
|
||||
// actions: [
|
||||
// AndroidNotificationAction(
|
||||
// allowGeneratedReplies: true,
|
||||
// 'id',
|
||||
// title.tr,
|
||||
// titleColor: AppColor.blueColor,
|
||||
// showsUserInterface: true,
|
||||
// )
|
||||
// ],
|
||||
// category: AndroidNotificationCategory.message,
|
||||
// );
|
||||
|
||||
DarwinNotificationDetails ios = const DarwinNotificationDetails(
|
||||
sound: 'default',
|
||||
presentAlert: true,
|
||||
@@ -221,7 +229,6 @@ class NotificationController extends GetxController {
|
||||
message,
|
||||
scheduledTime,
|
||||
details,
|
||||
androidAllowWhileIdle: true,
|
||||
uiLocalNotificationDateInterpretation:
|
||||
UILocalNotificationDateInterpretation.absoluteTime,
|
||||
matchDateTimeComponents: DateTimeComponents.time,
|
||||
@@ -264,20 +271,37 @@ class NotificationController extends GetxController {
|
||||
|
||||
// Schedule notifications for the next 7 days
|
||||
for (int day = 0; day < 7; day++) {
|
||||
// Schedule for 8:00 AM
|
||||
await _scheduleNotificationForTime(
|
||||
day, 7, 0, title, message, details, day * 1000 + 1); // Unique ID
|
||||
// List of notification times
|
||||
final notificationTimes = [
|
||||
{'hour': 8, 'minute': 0, 'id': day * 1000 + 1}, // 8:00 AM
|
||||
{'hour': 15, 'minute': 0, 'id': day * 1000 + 2}, // 3:00 PM
|
||||
{'hour': 20, 'minute': 0, 'id': day * 1000 + 3}, // 8:00 PM
|
||||
];
|
||||
|
||||
await _scheduleNotificationForTime(
|
||||
day, 10, 14, title, message, details, day * 1000 + 2); // Unique ID
|
||||
for (var time in notificationTimes) {
|
||||
final notificationId = time['id'] as int;
|
||||
|
||||
// Schedule for 3:00 PM
|
||||
await _scheduleNotificationForTime(
|
||||
day, 13, 0, title, message, details, day * 1000 + 3); // Unique ID
|
||||
// Check if this notification ID is already stored
|
||||
bool isScheduled = box.read('notification_$notificationId') ?? false;
|
||||
|
||||
// Schedule for 8:00 PM
|
||||
await _scheduleNotificationForTime(
|
||||
day, 20, 0, title, message, details, day * 1000 + 4); // Unique ID
|
||||
if (!isScheduled) {
|
||||
// Schedule the notification if not already scheduled
|
||||
await _scheduleNotificationForTime(
|
||||
day,
|
||||
time['hour'] as int,
|
||||
time['minute'] as int,
|
||||
title,
|
||||
message,
|
||||
details,
|
||||
notificationId,
|
||||
);
|
||||
|
||||
// Mark this notification ID as scheduled in GetStorage
|
||||
box.write('notification_$notificationId', true);
|
||||
} else {
|
||||
print('Notification with ID $notificationId is already scheduled.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
print('Notifications scheduled successfully for the next 7 days');
|
||||
|
||||
Reference in New Issue
Block a user