This commit is contained in:
Hamza-Ayed
2023-12-03 10:52:56 +03:00
parent 2501292424
commit db3123320b
2 changed files with 205 additions and 180 deletions

View File

@@ -201,6 +201,115 @@ class FirebaseMessagesController extends GetxController {
update();
}
}
// If the app is in the background or terminated, show a system tray message
RemoteNotification? notification = message.notification;
AndroidNotification? android = message.notification?.android;
// if (notification != null && android != null) {
if (notification != null && android != null) {
print('onMessageOpenedApp: ${notification.title} ${notification.body}');
if (message.data.isNotEmpty) {
if (message.notification!.title!.contains('Order')) {
var myListString = message.data['DriverList'];
print(myListString);
print('9999999999999myListString999999999999999');
var myList = jsonDecode(myListString) as List<dynamic>;
driverToken = myList[14].toString();
update();
print('driverToken==============$driverToken');
Get.to(() => OrderRequestPage(), arguments: {
'myListString': myListString,
'DriverList': myList,
'body': message.notification!.body
});
} else if (message.notification!.title!.contains('Apply Ride')) {
var passengerList = message.data['passengerList'];
print(passengerList);
print('9999999999999my Apply Ride 999999999999999');
var myList = jsonDecode(passengerList) as List<dynamic>;
driverID = myList[2].toString();
Get.snackbar(
'Captain Applied the Ride for You'.tr,
'message',
colorText: AppColor.greenColor,
duration: const Duration(seconds: 11),
instantInit: true,
snackPosition: SnackPosition.TOP,
titleText: Text(
'Applied'.tr,
style: const TextStyle(color: AppColor.redColor),
),
messageText: Text(
'Captain Applied the Ride for You'.tr,
style: AppStyle.title,
),
icon: const Icon(Icons.approval),
shouldIconPulse: true,
maxWidth: double.infinity,
margin: const EdgeInsets.all(16),
padding: const EdgeInsets.all(16),
borderRadius: 8,
borderColor: AppColor.primaryColor,
borderWidth: 2,
backgroundColor: AppColor.secondaryColor,
leftBarIndicatorColor: AppColor.greenColor,
boxShadows: [
BoxShadow(
color: Colors.black.withOpacity(0.25),
blurRadius: 4,
spreadRadius: 2,
offset: const Offset(0, 4),
),
],
backgroundGradient: const LinearGradient(
colors: [AppColor.greenColor, AppColor.accentColor],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
),
onTap: (GetSnackBar snackBar) {
// Do something when the snackbar is tapped.
// MapController().rideConfirm = false;
// update();
},
isDismissible: true,
showProgressIndicator: false,
dismissDirection: DismissDirection.up,
progressIndicatorController: null,
progressIndicatorBackgroundColor: Colors.transparent,
progressIndicatorValueColor: null,
snackStyle: SnackStyle.GROUNDED,
forwardAnimationCurve: Curves.easeInToLinear,
reverseAnimationCurve: Curves.easeInOut,
animationDuration: const Duration(milliseconds: 4000),
barBlur: 8,
overlayBlur: 0,
snackbarStatus: null,
overlayColor: AppColor.primaryColor.withOpacity(0.5),
userInputForm: null,
);
} else if (message.notification!.title!.contains('Promo')) {
Get.to(const PromosPassengerPage());
} else if (message.notification!.title!
.contains('DriverIsGoingToPassenger')) {
Get.snackbar('Driver is Going To Passenger', '',
backgroundColor: AppColor.greenColor);
} else if (message.notification!.title!.contains('RideIsBegin')) {
// MapPassengerController mapController = Get.put(MapPassengerController());
Get.snackbar('RideIsBegin', '',
backgroundColor: AppColor.greenColor);
// mapController.driverArrivePassenger();
update();
} else if (message.notification!.title!
.contains('Captain Finish Trip')) {
// MapPassengerController mapController =
// Get.find<MapPassengerController>();
Get.snackbar('Ride Finished'.tr, '',
backgroundColor: AppColor.greenColor);
// mapController.isRideFinished = true;//todo fix that for dfinish ride in passenger app
update();
}
}
}
});
FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) {
@@ -209,184 +318,104 @@ class FirebaseMessagesController extends GetxController {
RemoteNotification? notification = message.notification;
if (message.data.isNotEmpty) {
if (message.notification!.title!.contains('Order')) {
var myListString = message.data['myList'];
var myListString = message.data['DriverList'];
print(myListString);
print('9999999999999myListString999999999999999');
var myList = jsonDecode(myListString) as List<dynamic>;
Get.defaultDialog(
barrierDismissible: true,
title: message.notification!.title.toString(),
content: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Text(message.notification!.body.toString()),
Padding(
padding: const EdgeInsets.all(8.0),
child: TextButton.icon(
onPressed: () {
String mapUrl =
'https://www.google.com/maps/dir/${myList[0]}/${myList[1]}/';
// print(mapUrl);
launchUrl1(mapUrl);
},
icon: const Icon(Icons.map),
label: Text('Routs of Trip'.tr)),
),
driverToken = myList[14].toString();
update();
print('driverToken==============$driverToken');
Get.to(() => OrderRequestPage(), arguments: {
'myListString': myListString,
'DriverList': myList,
'body': message.notification!.body
});
} else if (message.notification!.title!.contains('Apply Ride')) {
var passengerList = message.data['passengerList'];
print(passengerList);
print('9999999999999my Apply Ride 999999999999999');
var myList = jsonDecode(passengerList) as List<dynamic>;
driverID = myList[2].toString();
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
'Total From Passenger is '.tr +
double.parse(myList[2]).toStringAsFixed(2),
style: AppStyle.title,
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
'Total For You is '.tr +
double.parse(myList[3]).toStringAsFixed(2),
style: AppStyle.title,
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
'Distance is '.tr + myList[5].toString() + ' KM'.tr,
style: AppStyle.title,
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
'Duration of Trip is '.tr +
myList[4].toString() +
' Minutes'.tr,
style: AppStyle.title,
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
MyElevatedButton(
title: 'Apply Order'.tr,
onPressed: () async {
await CRUD().postFromDialogue(
link: AppLink.addDriverOrder,
payload: {
'driver_id': myList[6].toString(),
// box.read(BoxName.driverID).toString(),
'order_id':
message.notification!.body.toString(),
'status': 'Apply'
});
},
),
MyElevatedButton(
title: 'Refuse Order'.tr,
onPressed: () async {
await CRUD().postFromDialogue(
link: AppLink.addDriverOrder,
payload: {
'driver_id': myList[6].toString(),
// box.read(BoxName.driverID).toString(),
'order_id':
message.notification!.body.toString(),
'status': 'Refused'
});
},
kolor: AppColor.redColor,
),
],
),
)
],
));
}
} else if (message.notification!.title!.contains('Apply Ride')) {
// MapController().rideConfirm = true;
var passengerList = message.data['passengerList'];
print(passengerList);
print('9999999999999my Apply Ride 999999999999999');
MapPassengerController mapController =
Get.find<MapPassengerController>();
mapController.rideConfirm = false;
update();
print(
'-----------------------------rideConfirm===${mapController.rideConfirm}');
var myList = jsonDecode(passengerList) as List<dynamic>;
driverID = myList[2].toString();
Get.snackbar(
'Captain Applied the Ride for You'.tr,
'message',
colorText: AppColor.greenColor,
duration: const Duration(seconds: 11),
instantInit: true,
snackPosition: SnackPosition.TOP,
titleText: Text(
'Applied'.tr,
style: const TextStyle(color: AppColor.redColor),
),
messageText: Text(
Get.snackbar(
'Captain Applied the Ride for You'.tr,
style: AppStyle.title,
),
icon: const Icon(Icons.approval),
shouldIconPulse: true,
maxWidth: double.infinity,
margin: const EdgeInsets.all(16),
padding: const EdgeInsets.all(16),
borderRadius: 8,
borderColor: AppColor.primaryColor,
borderWidth: 2,
backgroundColor: AppColor.secondaryColor,
leftBarIndicatorColor: AppColor.greenColor,
boxShadows: [
BoxShadow(
color: Colors.black.withOpacity(0.25),
blurRadius: 4,
spreadRadius: 2,
offset: const Offset(0, 4),
'message',
colorText: AppColor.greenColor,
duration: const Duration(seconds: 11),
instantInit: true,
snackPosition: SnackPosition.TOP,
titleText: Text(
'Applied'.tr,
style: const TextStyle(color: AppColor.redColor),
),
],
backgroundGradient: const LinearGradient(
colors: [AppColor.greenColor, AppColor.accentColor],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
),
onTap: (GetSnackBar snackBar) {
// Do something when the snackbar is tapped.
// MapController().rideConfirm = false;
// update();
},
isDismissible: true,
showProgressIndicator: false,
dismissDirection: DismissDirection.up,
progressIndicatorController: null,
progressIndicatorBackgroundColor: Colors.transparent,
progressIndicatorValueColor: null,
snackStyle: SnackStyle.GROUNDED,
forwardAnimationCurve: Curves.easeInToLinear,
reverseAnimationCurve: Curves.easeInOut,
animationDuration: const Duration(milliseconds: 4000),
barBlur: 8,
overlayBlur: 0,
snackbarStatus: null,
overlayColor: AppColor.primaryColor.withOpacity(0.5),
userInputForm: null,
);
} else if (message.notification!.title!.contains('Promo')) {
Get.to(const PromosPassengerPage());
} else if (message.notification!.title!.contains('RideIsBegin')) {
// MapDirection mapDirection = Get.find<MapDirection>();
// mapDirection.clearPolyline();
print('jjjjjjjjjjjjjjjjjjjjjjjjjjj');
Get.defaultDialog(
title: 'The Ride is Begin'.tr,
backgroundColor: AppColor.greenColor,
);
MapDriverController().clearPolyline();
messageText: Text(
'Captain Applied the Ride for You'.tr,
style: AppStyle.title,
),
icon: const Icon(Icons.approval),
shouldIconPulse: true,
maxWidth: double.infinity,
margin: const EdgeInsets.all(16),
padding: const EdgeInsets.all(16),
borderRadius: 8,
borderColor: AppColor.primaryColor,
borderWidth: 2,
backgroundColor: AppColor.secondaryColor,
leftBarIndicatorColor: AppColor.greenColor,
boxShadows: [
BoxShadow(
color: Colors.black.withOpacity(0.25),
blurRadius: 4,
spreadRadius: 2,
offset: const Offset(0, 4),
),
],
backgroundGradient: const LinearGradient(
colors: [AppColor.greenColor, AppColor.accentColor],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
),
onTap: (GetSnackBar snackBar) {
// Do something when the snackbar is tapped.
// MapController().rideConfirm = false;
// update();
},
isDismissible: true,
showProgressIndicator: false,
dismissDirection: DismissDirection.up,
progressIndicatorController: null,
progressIndicatorBackgroundColor: Colors.transparent,
progressIndicatorValueColor: null,
snackStyle: SnackStyle.GROUNDED,
forwardAnimationCurve: Curves.easeInToLinear,
reverseAnimationCurve: Curves.easeInOut,
animationDuration: const Duration(milliseconds: 4000),
barBlur: 8,
overlayBlur: 0,
snackbarStatus: null,
overlayColor: AppColor.primaryColor.withOpacity(0.5),
userInputForm: null,
);
} else if (message.notification!.title!.contains('Promo')) {
Get.to(const PromosPassengerPage());
} else if (message.notification!.title!
.contains('DriverIsGoingToPassenger')) {
Get.snackbar('Driver is Going To Passenger', '',
backgroundColor: AppColor.greenColor);
} else if (message.notification!.title!.contains('RideIsBegin')) {
// MapPassengerController mapController = Get.put(MapPassengerController());
Get.snackbar('RideIsBegin', '', backgroundColor: AppColor.greenColor);
// mapController.driverArrivePassenger();
update();
} else if (message.notification!.title!
.contains('Captain Finish Trip')) {
// MapPassengerController mapController =
// Get.find<MapPassengerController>();
Get.snackbar('Ride Finished'.tr, '',
backgroundColor: AppColor.greenColor);
// mapController.isRideFinished = true;//todo fix that for dfinish ride in passenger app
update();
}
}
});
}

View File

@@ -26,9 +26,7 @@ GetBuilder<MapDriverController> driverEndRideBar() {
children: [
const Icon(Icons.social_distance),
Text(
mapDriverController.distance.toString() +
' ' +
'KM'.tr,
'${mapDriverController.distance} ${'KM'.tr}',
style: AppStyle.title,
),
],
@@ -46,9 +44,7 @@ GetBuilder<MapDriverController> driverEndRideBar() {
children: [
const Icon(Icons.timelapse),
Text(
mapDriverController.duration.toString() +
' ' +
'Minute'.tr,
'${mapDriverController.duration} ${'Minute'.tr}',
style: AppStyle.title),
],
),