9/8/1
This commit is contained in:
@@ -330,6 +330,33 @@ class FirebaseMessagesController extends GetxController {
|
||||
'We regret to inform you that another driver has accepted this order.'
|
||||
.tr,
|
||||
'order');
|
||||
} else if (message.notification!.title! == 'VIP Order Accepted'.tr) {
|
||||
var myListString = message.data['passengerList'];
|
||||
var driverList = jsonDecode(myListString) as List<dynamic>;
|
||||
|
||||
// Assuming driverList[1] contains a valid date string
|
||||
DateTime scheduledTime;
|
||||
try {
|
||||
scheduledTime = DateTime.parse(driverList[1]);
|
||||
} catch (e) {
|
||||
// Handle the error if the date format is incorrect
|
||||
Log.print('Error parsing date: $e');
|
||||
scheduledTime = DateTime.now()
|
||||
.add(const Duration(hours: 1)); // Fallback to 1 hour from now
|
||||
}
|
||||
|
||||
NotificationController()
|
||||
.showNotification('The driver accepted your trip'.tr, '', 'order');
|
||||
|
||||
MyDialog().getDialog(
|
||||
'VIP Order Accepted'.tr,
|
||||
'The driver accepted your trip'.tr,
|
||||
() {
|
||||
// Schedule a notification for the parsed date or fallback date
|
||||
NotificationController().scheduleNotification('VIP Order'.tr,
|
||||
'This is a scheduled notification.'.tr, scheduledTime);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,19 @@
|
||||
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 =
|
||||
@@ -26,4 +35,29 @@ class NotificationController extends GetxController {
|
||||
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