first commit
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:get/get.dart';
|
||||
import 'package:siro_rider/constant/style.dart';
|
||||
import 'package:siro_rider/views/widgets/elevated_btn.dart';
|
||||
|
||||
import '../../constant/box_name.dart';
|
||||
import '../../constant/links.dart';
|
||||
import '../../main.dart';
|
||||
import '../functions/crud.dart';
|
||||
|
||||
class NotificationCaptainController extends GetxController {
|
||||
bool isLoading = false;
|
||||
Map notificationData = {};
|
||||
|
||||
getNotifications() async {
|
||||
isLoading = true;
|
||||
update();
|
||||
var res = await CRUD().get(
|
||||
link: AppLink.getNotificationCaptain,
|
||||
payload: {'driverID': box.read(BoxName.driverID)});
|
||||
if (res == "failure") {
|
||||
Get.defaultDialog(
|
||||
title: 'There is no notification yet'.tr,
|
||||
titleStyle: AppStyle.title,
|
||||
middleText: '',
|
||||
confirm: MyElevatedButton(
|
||||
title: 'Back',
|
||||
onPressed: () {
|
||||
Get.back();
|
||||
Get.back();
|
||||
}));
|
||||
}
|
||||
notificationData = jsonDecode(res);
|
||||
// sql.insertData(notificationData['message'], TableName.captainNotification);
|
||||
|
||||
isLoading = false;
|
||||
update();
|
||||
}
|
||||
|
||||
updateNotification(String id) async {
|
||||
await CRUD().post(
|
||||
link: AppLink.updateNotificationCaptain,
|
||||
payload: {'isShown': true, 'id': id},
|
||||
);
|
||||
}
|
||||
|
||||
addNotificationCaptain(String driverId, title, body, isPin) async {
|
||||
await CRUD().post(link: AppLink.addNotificationCaptain, payload: {
|
||||
'driverID': driverId,
|
||||
'title': title,
|
||||
'body': body,
|
||||
'isPin': isPin
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
getNotifications();
|
||||
super.onInit();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:get/get.dart';
|
||||
import 'package:siro_rider/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" || res == "error") {
|
||||
MyDialog().getDialog('There is no notification yet'.tr, '', () {
|
||||
Get.back();
|
||||
Get.back();
|
||||
});
|
||||
} else {
|
||||
final decoded = jsonDecode(res);
|
||||
// التحقق من وجود البيانات في 'data' أو 'message'
|
||||
var rawData = decoded['data'] ?? decoded['message'];
|
||||
|
||||
if (decoded['status'] == 'error' || decoded['status'] == 'failure' || rawData == "No notification data found") {
|
||||
notificationData = {'status': 'success', 'message': []}; // قائمة فارغة لمنع الخطأ في UI
|
||||
} else {
|
||||
// التأكد أننا نخزن قائمة
|
||||
notificationData = {
|
||||
'status': 'success',
|
||||
'message': rawData is List ? rawData : [rawData]
|
||||
};
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:siro_rider/constant/style.dart';
|
||||
import 'package:siro_rider/views/widgets/elevated_btn.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
import '../../constant/links.dart';
|
||||
import '../functions/crud.dart';
|
||||
|
||||
class RideAvailableController extends GetxController {
|
||||
bool isLoading = false;
|
||||
Map rideAvailableMap = {};
|
||||
getRideAvailable() async {
|
||||
isLoading = true;
|
||||
var res = await CRUD().get(link: AppLink.getRideWaiting, payload: {});
|
||||
if (res != 'failure') {
|
||||
rideAvailableMap = jsonDecode(res);
|
||||
isLoading = false;
|
||||
update();
|
||||
} else {
|
||||
Get.defaultDialog(
|
||||
title: 'No Rides now!'.tr,
|
||||
middleText: '',
|
||||
titleStyle: AppStyle.title,
|
||||
confirm: MyElevatedButton(
|
||||
title: 'Ok'.tr,
|
||||
onPressed: () {
|
||||
Get.back();
|
||||
Get.back();
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
getRideAvailable();
|
||||
super.onInit();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user