Initial commit

This commit is contained in:
Hamza-Ayed
2024-10-12 19:19:26 +03:00
parent 2e3ce78fe8
commit aca697578d
41 changed files with 2976 additions and 1188 deletions

View File

@@ -1,12 +1,8 @@
import 'dart:convert';
import 'dart:io';
import 'package:SEFER/env/env.dart';
import 'package:SEFER/views/widgets/my_dialog.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:googleapis_auth/auth_io.dart';
import 'package:googleapis_auth/googleapis_auth.dart';
import 'package:http/http.dart' as http;
import 'package:SEFER/controller/functions/toast.dart';
import 'package:SEFER/views/widgets/elevated_btn.dart';
@@ -131,16 +127,22 @@ class FirebaseMessagesController extends GetxController {
Get.find<MapPassengerController>().statusRide == 'Apply';
Get.find<MapPassengerController>().isSearchingWindow == false;
Get.find<MapPassengerController>().update();
NotificationController().showNotification(
'Apply Order'.tr, 'Driver Applied the Ride for You'.tr, 'order1');
if (Platform.isAndroid) {
NotificationController().showNotification(
'Apply Order'.tr, 'Driver Applied the Ride for You'.tr, 'order1');
}
// driverAppliedTripSnakBar();
} else if (message.notification!.title! == 'Promo'.tr) {
NotificationController()
.showNotification('Promo', 'Show latest promo'.tr, 'promo');
if (Platform.isAndroid) {
NotificationController()
.showNotification('Promo', 'Show latest promo'.tr, 'promo');
}
Get.to(const PromosPassengerPage());
} else if (message.notification!.title! == 'Trip Monitoring'.tr) {
NotificationController()
.showNotification('Trip Monitoring'.tr, '', 'iphone_ringtone');
if (Platform.isAndroid) {
NotificationController()
.showNotification('Trip Monitoring'.tr, '', 'iphone_ringtone');
}
var myListString = message.data['passengerList'];
var myList = jsonDecode(myListString) as List<dynamic>;
Get.toNamed('/tripmonitor', arguments: {
@@ -148,46 +150,59 @@ class FirebaseMessagesController extends GetxController {
'driverId': myList[1].toString(),
});
} else if (message.notification!.title! == 'token change'.tr) {
NotificationController()
.showNotification('token change'.tr, 'token change'.tr, 'cancel');
if (Platform.isAndroid) {
NotificationController()
.showNotification('token change'.tr, 'token change'.tr, 'cancel');
}
GoogleSignInHelper.signOut();
} else if (message.notification!.title! == 'DriverIsGoingToPassenger'.tr) {
Get.find<MapPassengerController>().isDriverInPassengerWay = true;
Get.find<MapPassengerController>().update();
NotificationController().showNotification('Driver is Going To You'.tr,
'Please stay on the picked point.'.tr, 'tone1');
if (Platform.isAndroid) {
NotificationController().showNotification('Driver is Going To You'.tr,
'Please stay on the picked point.'.tr, 'tone1');
}
// Get.snackbar('Driver is Going To Passenger', '',
// backgroundColor: AppColor.greenColor);
} else if (message.notification!.title! == 'message From passenger') {
NotificationController()
.showNotification('message From passenger'.tr, ''.tr, 'tone2');
if (Platform.isAndroid) {
NotificationController()
.showNotification('message From passenger'.tr, ''.tr, 'tone2');
}
passengerDialog(message.notification!.body!);
update();
} else if (message.notification!.title! == 'message From Driver') {
NotificationController()
.showNotification('message From passenger'.tr, ''.tr, 'tone2');
passengerDialog(message.notification!.body!);
if (Platform.isAndroid) {
NotificationController()
.showNotification('message From passenger'.tr, ''.tr, 'tone2');
}
update();
} else if (message.notification!.title! == 'RideIsBegin'.tr) {
Get.find<MapPassengerController>().getBeginRideFromDriver();
// Get.snackbar('RideIsBegin', '', backgroundColor: AppColor.greenColor);
box.write(BoxName.passengerWalletTotal, '0');
NotificationController()
.showNotification('Trip is Begin'.tr, ''.tr, 'start');
update();
if (Platform.isAndroid) {
NotificationController()
.showNotification('Trip is Begin'.tr, ''.tr, 'start');
}
} else if (message.notification!.title! == 'Hi ,I will go now'.tr) {
// Get.snackbar('Hi ,I will go now', '',
// backgroundColor: AppColor.greenColor);
NotificationController().showNotification(
'Passenger come to you'.tr, 'Hi ,I will go now'.tr, 'tone2');
if (Platform.isAndroid) {
NotificationController().showNotification(
'Passenger come to you'.tr, 'Hi ,I will go now'.tr, 'tone2');
}
update();
} else if (message.notification!.title! == 'Hi ,I Arrive your site'.tr) {
NotificationController()
.showNotification('Hi ,I Arrive your site'.tr, ''.tr, 'tone2');
driverArrivePassengerDialoge();
if (Platform.isAndroid) {
NotificationController()
.showNotification('Hi ,I Arrive your site'.tr, ''.tr, 'tone2');
}
update();
} else if (message.notification!.title! == "Cancel Trip from driver".tr) {
Get.back();
@@ -214,10 +229,12 @@ class FirebaseMessagesController extends GetxController {
} else if (message.notification!.title! == 'Driver Finish Trip'.tr) {
var myListString = message.data['passengerList'];
var driverList = jsonDecode(myListString) as List<dynamic>;
NotificationController().showNotification(
'Driver Finish Trip'.tr,
'you will pay to Driver'.tr + ' ${driverList[3].toString()} \$'.tr,
'tone1');
if (Platform.isAndroid) {
NotificationController().showNotification(
'Driver Finish Trip'.tr,
'you will pay to Driver'.tr + ' ${driverList[3].toString()} \$'.tr,
'tone1');
}
Get.find<AudioRecorderController>().stopRecording();
if (double.parse(box.read(BoxName.passengerWalletTotal)) < 0) {
box.write(BoxName.passengerWalletTotal, 0);
@@ -249,11 +266,13 @@ class FirebaseMessagesController extends GetxController {
var myListString = message.data['passengerList'];
var driverList = jsonDecode(myListString) as List<dynamic>;
// if (Platform.isAndroid) {
NotificationController().showNotification(
'Call Income'.tr,
message.notification!.body!,
'iphone_ringtone',
);
if (Platform.isAndroid) {
NotificationController().showNotification(
'Call Income'.tr,
message.notification!.body!,
'iphone_ringtone',
);
}
// }
// Assuming GetMaterialApp is initialized and context is valid for navigation
// Get.to(() => PassengerCallPage(
@@ -267,12 +286,13 @@ class FirebaseMessagesController extends GetxController {
var myListString = message.data['passengerList'];
var driverList = jsonDecode(myListString) as List<dynamic>;
// if (Platform.isAndroid) {
NotificationController().showNotification(
'Call Income'.tr,
message.notification!.body!,
'iphone_ringtone',
);
// }
if (Platform.isAndroid) {
NotificationController().showNotification(
'Call Income'.tr,
message.notification!.body!,
'iphone_ringtone',
);
}
// Assuming GetMaterialApp is initialized and context is valid for navigation
// Get.to(() => PassengerCallPage(
// channelName: driverList[1].toString(),
@@ -325,11 +345,13 @@ class FirebaseMessagesController extends GetxController {
// }
else if (message.notification!.title! == 'Order Applied'.tr) {
NotificationController().showNotification(
'The order Accepted by another Driver'.tr,
'We regret to inform you that another driver has accepted this order.'
.tr,
'order');
if (Platform.isAndroid) {
NotificationController().showNotification(
'The order Accepted by another Driver'.tr,
'We regret to inform you that another driver has accepted this order.'
.tr,
'order');
}
}
}
@@ -645,7 +667,7 @@ class FirebaseMessagesController extends GetxController {
if (response.statusCode == 200) {
print(
'Notification sent successfully. Status code: ${response.statusCode}');
print('Response body: ${response.body}');
print('Response token: ${token}');
} else {
print(
'Failed to send notification. Status code: ${response.statusCode}');
@@ -696,8 +718,9 @@ class FirebaseMessagesController extends GetxController {
// }
// }
Future<void> sendNotificationToDriverMAP(String title, String body,
String token, List<String> data, String tone) async {
Future<void> sendNotificationToDriverMAP(
String title, String body, String token, List<String> data, String tone,
{int retryCount = 2}) async {
try {
String serviceAccountKeyJson = '''{
"type": "service_account",
@@ -719,7 +742,7 @@ class FirebaseMessagesController extends GetxController {
// Obtain an OAuth 2.0 access token
final accessToken = await accessTokenManager.getAccessToken();
Log.print('accessToken: ${accessToken}');
// Log.print('accessToken: ${accessToken}');
// Send the notification
final response = await http.post(
@@ -762,14 +785,28 @@ class FirebaseMessagesController extends GetxController {
if (response.statusCode == 200) {
print(
'Notification sent successfully. Status code: ${response.statusCode}');
print('Response body: ${response.body}');
print('Response token: ${token}');
} else {
print(
'Failed to send notification. Status code: ${response.statusCode}');
print('Response body: ${response.body}');
if (retryCount > 0) {
print('Retrying... Attempts remaining: $retryCount');
await Future.delayed(
Duration(seconds: 2)); // Optional delay before retrying
return sendNotificationToDriverMAP(title, body, token, data, tone,
retryCount: retryCount - 1);
}
}
} catch (e) {
print('Error sending notification: $e');
if (retryCount > 0) {
print('Retrying... Attempts remaining: $retryCount');
await Future.delayed(
Duration(seconds: 2)); // Optional delay before retrying
return sendNotificationToDriverMAP(title, body, token, data, tone,
retryCount: retryCount - 1);
}
}
}

View File

@@ -17,7 +17,7 @@ class NotificationController extends GetxController {
// Displays a notification with the given title and message
void showNotification(String title, String message, String tone) async {
AndroidNotificationDetails android = AndroidNotificationDetails(
'your channel id', 'your channel name',
'high_importance_channel', 'High Importance Notifications',
importance: Importance.max,
priority: Priority.high,
showWhen: false,