11/17/1
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'package:SEFER/controller/home/captin/home_captain_controller.dart';
|
||||
import 'package:SEFER/env/env.dart';
|
||||
import 'package:SEFER/print.dart';
|
||||
import 'package:SEFER/views/widgets/error_snakbar.dart';
|
||||
import 'package:SEFER/views/widgets/mydialoug.dart';
|
||||
import 'package:firebase_messaging/firebase_messaging.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -10,7 +9,6 @@ import 'package:get/get.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:SEFER/views/widgets/elevated_btn.dart';
|
||||
|
||||
import '../../constant/api_key.dart';
|
||||
import '../../constant/box_name.dart';
|
||||
import '../../constant/colors.dart';
|
||||
import '../../constant/style.dart';
|
||||
@@ -208,8 +206,6 @@ class FirebaseMessagesController extends GetxController {
|
||||
|
||||
update();
|
||||
} else if (message.notification!.title! == 'Hi ,I will go now') {
|
||||
// Get.snackbar('Hi ,I will go now', '',
|
||||
// backgroundColor: AppColor.greenColor);
|
||||
if (Platform.isAndroid) {
|
||||
notificationController.showNotification(
|
||||
'Passenger come to you'.tr, 'Hi ,I will go now'.tr, 'tone2', '');
|
||||
@@ -274,14 +270,7 @@ class FirebaseMessagesController extends GetxController {
|
||||
// Get.off(const CallPage());
|
||||
} catch (e) {}
|
||||
} else if (message.notification!.title! == 'Order Applied'.tr) {
|
||||
Get.snackbar(
|
||||
"The order has been accepted by another driver."
|
||||
.tr, // Corrected grammar
|
||||
"Be more mindful next time to avoid dropping orders."
|
||||
.tr, // Improved sentence structure
|
||||
backgroundColor: AppColor.yellowColor,
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
);
|
||||
mySnackbarSuccess("The order has been accepted by another driver.".tr);
|
||||
} else if (message.notification!.title! == 'Order') {
|
||||
if (Platform.isAndroid) {
|
||||
notificationController.showNotification(
|
||||
|
||||
@@ -230,7 +230,7 @@ class NotificationController extends GetxController {
|
||||
});
|
||||
}
|
||||
|
||||
void scheduleDailyNotifications(
|
||||
void scheduleNotificationsForSevenDays(
|
||||
String title, String message, String tone) async {
|
||||
final AndroidNotificationDetails android = AndroidNotificationDetails(
|
||||
'high_importance_channel',
|
||||
@@ -262,47 +262,72 @@ class NotificationController extends GetxController {
|
||||
}
|
||||
}
|
||||
|
||||
// Schedule notifications for 10:00 AM and 3:00 PM daily
|
||||
await _scheduleNotificationForTime(7, 0, title, message, details);
|
||||
await _scheduleNotificationForTime(13, 0, title, message, details);
|
||||
await _scheduleNotificationForTime(18, 0, title, message, details);
|
||||
// await _scheduleNotificationForTime(0, 22, title, message, details);
|
||||
// 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
|
||||
|
||||
print('Daily notifications scheduled successfully');
|
||||
await _scheduleNotificationForTime(
|
||||
day, 10, 14, title, message, details, day * 1000 + 2); // Unique ID
|
||||
|
||||
// Schedule for 3:00 PM
|
||||
await _scheduleNotificationForTime(
|
||||
day, 13, 0, title, message, details, day * 1000 + 3); // Unique ID
|
||||
|
||||
// Schedule for 8:00 PM
|
||||
await _scheduleNotificationForTime(
|
||||
day, 20, 0, title, message, details, day * 1000 + 4); // Unique ID
|
||||
}
|
||||
|
||||
print('Notifications scheduled successfully for the next 7 days');
|
||||
}
|
||||
|
||||
// Helper function to get the next instance of a specific hour and minute
|
||||
Future<void> _scheduleNotificationForTime(int hour, int minute, String title,
|
||||
String message, NotificationDetails details) async {
|
||||
Future<void> _scheduleNotificationForTime(
|
||||
int dayOffset,
|
||||
int hour,
|
||||
int minute,
|
||||
String title,
|
||||
String message,
|
||||
NotificationDetails details,
|
||||
int notificationId,
|
||||
) async {
|
||||
// Initialize and set Cairo timezone
|
||||
tz.initializeTimeZones();
|
||||
final cairoLocation = tz.getLocation('Africa/Cairo'); // Set Cairo timezone
|
||||
var cairoLocation = tz.getLocation('Africa/Cairo');
|
||||
|
||||
final now = tz.TZDateTime.now(
|
||||
cairoLocation); // Use Cairo timezone for the current time
|
||||
final now = tz.TZDateTime.now(cairoLocation);
|
||||
tz.TZDateTime scheduledDate = tz.TZDateTime(
|
||||
cairoLocation, now.year, now.month, now.day, hour, minute);
|
||||
cairoLocation,
|
||||
now.year,
|
||||
now.month,
|
||||
now.day + dayOffset, // Add offset to schedule for the next days
|
||||
hour,
|
||||
minute,
|
||||
);
|
||||
|
||||
// If scheduled time is already past today, schedule it for the next day
|
||||
// If the scheduled time is in the past, move it to the next day
|
||||
if (scheduledDate.isBefore(now)) {
|
||||
scheduledDate = scheduledDate.add(const Duration(days: 1));
|
||||
scheduledDate = scheduledDate.add(Duration(days: 1));
|
||||
}
|
||||
|
||||
print('Current time (Cairo): $now');
|
||||
print('Scheduling notification for: $scheduledDate');
|
||||
|
||||
await _flutterLocalNotificationsPlugin.zonedSchedule(
|
||||
0, // Use unique IDs if you want to manage each notification separately
|
||||
notificationId, // Unique ID for each notification
|
||||
title,
|
||||
message,
|
||||
scheduledDate,
|
||||
details,
|
||||
androidAllowWhileIdle: true,
|
||||
androidScheduleMode: AndroidScheduleMode.exact,
|
||||
uiLocalNotificationDateInterpretation:
|
||||
UILocalNotificationDateInterpretation.absoluteTime,
|
||||
matchDateTimeComponents: DateTimeComponents.time,
|
||||
matchDateTimeComponents:
|
||||
null, // Don't repeat automatically; we handle 7 days manually
|
||||
);
|
||||
print('Notification scheduled successfully for Cairo timezone');
|
||||
|
||||
print('Notification scheduled successfully for: $scheduledDate');
|
||||
}
|
||||
|
||||
void scheduleNotificationEvery10Hours(
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import 'package:SEFER/constant/links.dart';
|
||||
import 'package:SEFER/controller/functions/crud.dart';
|
||||
import 'package:SEFER/views/home/Captin/home_captain/home_captin.dart';
|
||||
import 'package:SEFER/views/home/Captin/orderCaptin/order_request_page.dart';
|
||||
import 'package:SEFER/views/widgets/elevated_btn.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
class OverlayContent1 extends StatelessWidget {
|
||||
@override
|
||||
|
||||
Reference in New Issue
Block a user