This commit is contained in:
Hamza-Ayed
2024-07-31 21:19:19 +03:00
parent dea83d970c
commit 2bc71355c3
106 changed files with 4600 additions and 727 deletions

View File

@@ -1,7 +1,6 @@
import 'dart:convert';
import 'dart:io';
import 'package:SEFER/controller/home/captin/home_captain_controller.dart';
import 'package:SEFER/views/home/Captin/home_captain/widget/call_page.dart';
import 'package:SEFER/views/widgets/mydialoug.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/material.dart';
@@ -79,9 +78,27 @@ class FirebaseMessagesController extends GetxController {
}
});
FirebaseMessaging.onBackgroundMessage((RemoteMessage message) async {
// Handle background message
if (message.data.isNotEmpty && message.notification != null) {
fireBaseTitles(message);
if (message.notification!.title! == 'Order'.tr) {
if (Platform.isAndroid) {
NotificationController()
.showNotification('Order'.tr, '', 'order', 'order_page_payload');
}
// await FirebaseMessagesController().showOverlayNotification(message);
var myListString = message.data['DriverList'];
// var points = message.data['PolylineJson'];
var myList = jsonDecode(myListString) as List<dynamic>;
// var myPoints = jsonDecode(points) as List<dynamic>;
driverToken = myList[14].toString();
// This is for location using and uploading status
Get.put(HomeCaptainController()).changeRideId();
update();
Get.to(() => OrderRequestPage(), arguments: {
'myListString': myListString,
'DriverList': myList,
// 'PolylineJson': myPoints,
'body': message.notification!.body
});
}
});
@@ -95,8 +112,9 @@ class FirebaseMessagesController extends GetxController {
Future<void> fireBaseTitles(RemoteMessage message) async {
if (message.notification!.title! == 'Order'.tr) {
if (Platform.isAndroid) {
NotificationController().showNotification('Order'.tr, '', 'order');
NotificationController().showNotification('Order'.tr, '', 'order', '');
}
// await FirebaseMessagesController().showOverlayNotification(message);
var myListString = message.data['DriverList'];
// var points = message.data['PolylineJson'];
@@ -113,8 +131,10 @@ class FirebaseMessagesController extends GetxController {
'body': message.notification!.body
});
} else if (message.notification!.title == 'Cancel Trip') {
NotificationController().showNotification(
'Cancel Trip'.tr, 'Passenger Cancel Trip'.tr, 'cancel');
// if (Platform.isAndroid) {
// NotificationController().showNotification(
// 'Cancel Trip'.tr, 'Passenger Cancel Trip'.tr, 'cancel', '');
// }
cancelTripDialog();
} else if (message.notification!.title! == 'token change') {
// NotificationController()
@@ -122,14 +142,18 @@ class FirebaseMessagesController extends GetxController {
// GoogleSignInHelper.signOut();
GoogleSignInHelper.signOut();
} else if (message.notification!.title! == 'message From passenger') {
NotificationController()
.showNotification('message From passenger', ''.tr, 'tone2');
if (Platform.isAndroid) {
NotificationController()
.showNotification('message From passenger', ''.tr, 'tone2', '');
}
passengerDialog(message.notification!.body!);
update();
} else if (message.notification!.title! == 'face detect') {
NotificationController()
.showNotification('face detect'.tr, ''.tr, 'tone2');
if (Platform.isAndroid) {
NotificationController()
.showNotification('face detect'.tr, ''.tr, 'tone2', '');
}
String result0 = await faceDetector();
// Handle the result here, e.g., show a dialog or update the UI
var result = jsonDecode(result0);
@@ -156,19 +180,20 @@ class FirebaseMessagesController extends GetxController {
} else if (message.notification!.title! == 'Hi ,I will go now') {
// 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! == 'Call Income'.tr) {
try {
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(
@@ -183,11 +208,10 @@ 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(() => CallPage(
@@ -198,11 +222,13 @@ class FirebaseMessagesController extends GetxController {
} catch (e) {}
} else if (message.notification!.title! ==
"Criminal Document Required".tr) {
NotificationController().showNotification(
"Criminal Document Required".tr,
message.notification!.body!,
'tone2',
);
if (Platform.isAndroid) {
NotificationController().showNotification(
"Criminal Document Required".tr,
message.notification!.body!,
'tone2',
'');
}
MyDialog().getDialog(
"Criminal Document Required".tr, 'You should have upload it .'.tr,
() {
@@ -215,10 +241,7 @@ class FirebaseMessagesController extends GetxController {
var driverList = jsonDecode(myListString) as List<dynamic>;
if (Platform.isAndroid) {
NotificationController().showNotification(
'Call End'.tr,
message.notification!.body!,
'tone2',
);
'Call End'.tr, message.notification!.body!, 'tone2', '');
}
// Assuming GetMaterialApp is initialized and context is valid for navigation
// Get.off(const CallPage());
@@ -247,11 +270,14 @@ class FirebaseMessagesController extends GetxController {
'body': message.notification!.body
});
} 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',
'');
}
}
}
@@ -623,3 +649,34 @@ class FirebaseMessagesController extends GetxController {
}
}
}
class OverlayContent extends StatelessWidget {
final String title;
final String body;
OverlayContent(this.title, this.body);
@override
Widget build(BuildContext context) {
return Material(
child: Container(
padding: EdgeInsets.all(16.0),
color: Colors.white,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
title,
style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
),
SizedBox(height: 8.0),
Text(
body,
style: TextStyle(fontSize: 16),
),
],
),
),
);
}
}