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(); 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) { FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) {
@@ -209,184 +318,104 @@ class FirebaseMessagesController extends GetxController {
RemoteNotification? notification = message.notification; RemoteNotification? notification = message.notification;
if (message.data.isNotEmpty) { if (message.data.isNotEmpty) {
if (message.notification!.title!.contains('Order')) { 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>; var myList = jsonDecode(myListString) as List<dynamic>;
Get.defaultDialog( driverToken = myList[14].toString();
barrierDismissible: true, update();
title: message.notification!.title.toString(), print('driverToken==============$driverToken');
content: Column( Get.to(() => OrderRequestPage(), arguments: {
crossAxisAlignment: CrossAxisAlignment.start, 'myListString': myListString,
children: [ 'DriverList': myList,
// Text(message.notification!.body.toString()), 'body': message.notification!.body
Padding( });
padding: const EdgeInsets.all(8.0), } else if (message.notification!.title!.contains('Apply Ride')) {
child: TextButton.icon( var passengerList = message.data['passengerList'];
onPressed: () { print(passengerList);
String mapUrl = print('9999999999999my Apply Ride 999999999999999');
'https://www.google.com/maps/dir/${myList[0]}/${myList[1]}/'; var myList = jsonDecode(passengerList) as List<dynamic>;
// print(mapUrl); driverID = myList[2].toString();
launchUrl1(mapUrl);
},
icon: const Icon(Icons.map),
label: Text('Routs of Trip'.tr)),
),
Padding( Get.snackbar(
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(
'Captain Applied the Ride for You'.tr, 'Captain Applied the Ride for You'.tr,
style: AppStyle.title, 'message',
), colorText: AppColor.greenColor,
icon: const Icon(Icons.approval), duration: const Duration(seconds: 11),
shouldIconPulse: true, instantInit: true,
maxWidth: double.infinity, snackPosition: SnackPosition.TOP,
margin: const EdgeInsets.all(16), titleText: Text(
padding: const EdgeInsets.all(16), 'Applied'.tr,
borderRadius: 8, style: const TextStyle(color: AppColor.redColor),
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),
), ),
], messageText: Text(
backgroundGradient: const LinearGradient( 'Captain Applied the Ride for You'.tr,
colors: [AppColor.greenColor, AppColor.accentColor], style: AppStyle.title,
begin: Alignment.topLeft, ),
end: Alignment.bottomRight, icon: const Icon(Icons.approval),
), shouldIconPulse: true,
onTap: (GetSnackBar snackBar) { maxWidth: double.infinity,
// Do something when the snackbar is tapped. margin: const EdgeInsets.all(16),
// MapController().rideConfirm = false; padding: const EdgeInsets.all(16),
// update(); borderRadius: 8,
}, borderColor: AppColor.primaryColor,
isDismissible: true, borderWidth: 2,
showProgressIndicator: false, backgroundColor: AppColor.secondaryColor,
dismissDirection: DismissDirection.up, leftBarIndicatorColor: AppColor.greenColor,
progressIndicatorController: null, boxShadows: [
progressIndicatorBackgroundColor: Colors.transparent, BoxShadow(
progressIndicatorValueColor: null, color: Colors.black.withOpacity(0.25),
snackStyle: SnackStyle.GROUNDED, blurRadius: 4,
forwardAnimationCurve: Curves.easeInToLinear, spreadRadius: 2,
reverseAnimationCurve: Curves.easeInOut, offset: const Offset(0, 4),
animationDuration: const Duration(milliseconds: 4000), ),
barBlur: 8, ],
overlayBlur: 0, backgroundGradient: const LinearGradient(
snackbarStatus: null, colors: [AppColor.greenColor, AppColor.accentColor],
overlayColor: AppColor.primaryColor.withOpacity(0.5), begin: Alignment.topLeft,
userInputForm: null, end: Alignment.bottomRight,
); ),
} else if (message.notification!.title!.contains('Promo')) { onTap: (GetSnackBar snackBar) {
Get.to(const PromosPassengerPage()); // Do something when the snackbar is tapped.
} else if (message.notification!.title!.contains('RideIsBegin')) { // MapController().rideConfirm = false;
// MapDirection mapDirection = Get.find<MapDirection>(); // update();
// mapDirection.clearPolyline(); },
print('jjjjjjjjjjjjjjjjjjjjjjjjjjj'); isDismissible: true,
Get.defaultDialog( showProgressIndicator: false,
title: 'The Ride is Begin'.tr, dismissDirection: DismissDirection.up,
backgroundColor: AppColor.greenColor, progressIndicatorController: null,
); progressIndicatorBackgroundColor: Colors.transparent,
MapDriverController().clearPolyline(); 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: [ children: [
const Icon(Icons.social_distance), const Icon(Icons.social_distance),
Text( Text(
mapDriverController.distance.toString() + '${mapDriverController.distance} ${'KM'.tr}',
' ' +
'KM'.tr,
style: AppStyle.title, style: AppStyle.title,
), ),
], ],
@@ -46,9 +44,7 @@ GetBuilder<MapDriverController> driverEndRideBar() {
children: [ children: [
const Icon(Icons.timelapse), const Icon(Icons.timelapse),
Text( Text(
mapDriverController.duration.toString() + '${mapDriverController.duration} ${'Minute'.tr}',
' ' +
'Minute'.tr,
style: AppStyle.title), style: AppStyle.title),
], ],
), ),