65 lines
1.6 KiB
Dart
65 lines
1.6 KiB
Dart
import 'dart:convert';
|
|
|
|
import 'package:get/get.dart';
|
|
import 'package:Tripz/controller/firebase/firbase_messge.dart';
|
|
|
|
import '../../constant/box_name.dart';
|
|
import '../../constant/links.dart';
|
|
import '../../main.dart';
|
|
import '../../views/widgets/mydialoug.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,
|
|
});
|
|
FirebaseMessagesController().sendNotificationToPassengerToken(
|
|
title,
|
|
body,
|
|
'token',
|
|
[],
|
|
'iphone_ringtone.wav',
|
|
);
|
|
}
|
|
|
|
@override
|
|
void onInit() {
|
|
getNotifications();
|
|
super.onInit();
|
|
}
|
|
}
|