Files
intaleq/lib/controller/notification/passenger_notification_controller.dart
Hamza-Ayed 11dfe94bbb 25-12-1/1
2025-12-01 07:53:52 +03:00

75 lines
1.9 KiB
Dart

import 'dart:convert';
import 'package:get/get.dart';
import 'package:Intaleq/controller/firebase/firbase_messge.dart';
import '../../constant/box_name.dart';
import '../../constant/links.dart';
import '../../main.dart';
import '../../views/widgets/mydialoug.dart';
import '../firebase/notification_service.dart';
import '../functions/crud.dart';
class PassengerNotificationController extends GetxController {
bool isloading = false;
Map notificationData = {};
getNotifications() async {
isloading = true;
update();
var res = await CRUD().get(
link: AppLink.getNotificationPassenger,
payload: {'passenger_id': box.read(BoxName.passengerID)});
if (res == "failure") {
MyDialog().getDialog('There is no notification yet'.tr, '', () {
Get.back();
Get.back();
});
} else {
notificationData = jsonDecode(res);
isloading = false;
update();
}
// sql.insertData(notificationData['message'], TableName.captainNotification);
}
updateNotification(String id) async {
await CRUD().post(
link: AppLink.updateNotificationPassenger,
payload: {'isShown': 'true', 'id': id},
);
Get.back();
getNotifications();
}
addNotificationToPassenger(String title, body) async {
var res = CRUD().post(link: AppLink.addNotificationPassenger, payload: {
'title': title,
'body': body,
});
// Get.find<FirebaseMessagesController>().sendNotificationToPassengerToken(
// title,
// body,
// 'token',
// [],
// 'iphone_ringtone',
// );
await NotificationService.sendNotification(
category: title,
target: 'token'.toString(),
title: title,
body: body.tr,
isTopic: false, // Important: this is a token
tone: 'cancel',
driverList: [],
);
}
@override
void onInit() {
getNotifications();
super.onInit();
}
}