Files
intaleq/lib/controller/firebase/firbase_messge.dart
Hamza-Ayed 11dfe94bbb 25-12-1/1
2025-12-01 07:53:52 +03:00

793 lines
31 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import 'dart:convert';
import 'dart:io';
import 'package:Intaleq/views/home/HomePage/trip_monitor/trip_link_monitor.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:Intaleq/controller/functions/toast.dart';
import 'package:Intaleq/views/widgets/elevated_btn.dart';
import '../../constant/box_name.dart';
import '../../constant/colors.dart';
import '../../constant/style.dart';
import '../../main.dart';
import '../../print.dart';
import '../../views/Rate/rate_captain.dart';
import '../../views/home/map_page_passenger.dart';
import '../../views/home/profile/promos_passenger_page.dart';
import '../auth/google_sign.dart';
import '../functions/audio_record1.dart';
import '../home/map_passenger_controller.dart';
import 'local_notification.dart';
class FirebaseMessagesController extends GetxController {
final fcmToken = FirebaseMessaging.instance;
List<String> tokens = [];
List dataTokens = [];
late String driverID;
late String driverToken;
NotificationSettings? notificationSettings;
Future<void> getNotificationSettings() async {
// Get the current notification settings
NotificationSettings? notificationSettings =
await FirebaseMessaging.instance.getNotificationSettings();
'Notification authorization status: ${notificationSettings.authorizationStatus}';
// Call the update function if needed
update();
}
Future<void> requestFirebaseMessagingPermission() async {
FirebaseMessaging messaging = FirebaseMessaging.instance;
// Check if the platform is Android
if (Platform.isAndroid) {
// Request permission for Android
await messaging.requestPermission();
} else if (Platform.isIOS) {
// Request permission for iOS
NotificationSettings settings = await messaging.requestPermission(
alert: true,
announcement: true,
badge: true,
carPlay: true,
criticalAlert: true,
provisional: false,
sound: true,
);
messaging.setForegroundNotificationPresentationOptions(
alert: true, badge: true, sound: true);
}
}
NotificationController notificationController =
Get.isRegistered<NotificationController>()
? Get.find<NotificationController>()
: Get.put(NotificationController());
Future getToken() async {
fcmToken.getToken().then((token) {
Log.print('fcmToken: ${token}');
box.write(BoxName.tokenFCM, (token.toString()));
});
// 🔹 الاشتراك في topic
await fcmToken
.subscribeToTopic("passengers"); // أو "users" حسب نوع المستخدم
print("Subscribed to 'passengers' topic ✅");
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
// If the app is in the background or terminated, show a system tray message
RemoteNotification? notification = message.notification;
AndroidNotification? android = notification?.android;
// if (notification != null && android != null) {
if (message.data.isNotEmpty && message.notification != null) {
fireBaseTitles(message);
}
});
FirebaseMessaging.onBackgroundMessage((RemoteMessage message) async {
// Handle background message
if (message.data.isNotEmpty && message.notification != null) {
fireBaseTitles(message);
}
});
FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) {
if (message.data.isNotEmpty && message.notification != null) {
fireBaseTitles(message);
}
});
}
Future<void> fireBaseTitles(RemoteMessage message) async {
// [!! تعديل !!]
// اقرأ "النوع" من حمولة البيانات، وليس من العنوان
String category = message.data['category'] ?? '';
// اقرأ العنوان (للعرض)
String title = message.notification?.title ?? '';
String body = message.notification?.body ?? '';
if (category == 'ORDER') {
// <-- مثال: كان 'Order'.tr
Log.print('message: ${message}');
if (Platform.isAndroid) {
notificationController.showNotification(title, body, 'Order');
}
}
// ... داخل معالج الإشعارات في تطبيق الراكب ...
else if (category == 'Accepted Ride') {
// <-- كان 'Accepted Ride'
var driverListJson = message.data['driverList'];
if (driverListJson != null) {
var myList = jsonDecode(driverListJson) as List<dynamic>;
final controller = Get.find<MapPassengerController>();
// controller.currentRideState.value = RideState.driverApplied;
await controller.processRideAcceptance(
driverIdFromFCM: myList[0].toString(),
rideIdFromFCM: myList[3].toString());
} else {
Log.print('❌ خطأ: RIDE_ACCEPTED وصل بدون driverList');
}
} else if (category == 'Promo') {
// <-- كان 'Promo'.tr
if (Platform.isAndroid) {
notificationController.showNotification(title, body, 'promo');
}
Get.to(const PromosPassengerPage());
} else if (category == 'Trip Monitoring') {
// <-- كان 'Trip Monitoring'.tr
if (Platform.isAndroid) {
notificationController.showNotification(title, body, 'iphone_ringtone');
}
var myListString = message.data['DriverList'];
var myList = jsonDecode(myListString) as List<dynamic>;
Get.to(() => TripMonitor(), arguments: {
'rideId': myList[0].toString(),
'driverId': myList[1].toString(),
});
} else if (category == 'token change') {
// <-- كان 'token change'.tr
if (Platform.isAndroid) {
notificationController.showNotification(title, body, 'cancel');
}
GoogleSignInHelper.signOut();
} else if (category == 'Driver Is Going To Passenger') {
// <-- كان 'Driver Is Going To Passenger'
Get.find<MapPassengerController>().isDriverInPassengerWay = true;
Get.find<MapPassengerController>().update();
if (Platform.isAndroid) {
notificationController.showNotification(title, body, 'tone1');
}
} else if (category == 'message From passenger') {
// <-- كان 'message From passenger'
if (Platform.isAndroid) {
notificationController.showNotification(title, body, 'ding');
}
passengerDialog(body);
update();
} else if (category == 'message From Driver') {
// <-- كان 'message From Driver'
if (Platform.isAndroid) {
notificationController.showNotification(title, body, 'ding');
}
passengerDialog(body);
update();
} else if (category == 'Trip is Begin') {
// <-- كان 'Trip is Begin'
Log.print('[FCM] استقبل إشعار "TRIP_BEGUN".');
final controller = Get.find<MapPassengerController>();
controller.processRideBegin();
} else if (category == 'Hi ,I will go now') {
// <-- كان 'Hi ,I will go now'.tr
if (Platform.isAndroid) {
notificationController.showNotification(title, body, 'ding');
}
update();
} else if (category == 'Hi ,I Arrive your site') {
// <-- كان 'Hi ,I Arrive your site'.tr
final controller = Get.find<MapPassengerController>();
// if (controller.currentRideState.value == RideState.driverApplied) {
Log.print('[FCM] السائق وصل. تغيير الحالة إلى driverArrived');
controller.currentRideState.value = RideState.driverArrived;
// }
} else if (category == 'Cancel Trip from driver') {
// <-- كان "Cancel Trip from driver"
Get.back();
if (Platform.isAndroid) {
notificationController.showNotification(title, body, 'cancel');
}
Get.defaultDialog(
title: "The driver canceled your ride.".tr, // العنوان المترجم للعرض
middleText: "We will look for a new driver.\nPlease wait.".tr,
confirm: MyElevatedButton(
kolor: AppColor.greenColor,
title: 'Ok'.tr,
onPressed: () async {
Get.back();
await Get.find<MapPassengerController>()
.reSearchAfterCanceledFromDriver();
},
),
cancel: MyElevatedButton(
title: 'Cancel'.tr,
kolor: AppColor.redColor,
onPressed: () {
Get.offAll(() => const MapPagePassenger());
},
));
} else if (category == 'Driver Finish Trip') {
// <-- كان 'Driver Finish Trip'.tr
final rawData = message.data['DriverList'];
List<dynamic> driverList = [];
if (rawData != null && rawData is String) {
try {
driverList = jsonDecode(rawData);
} catch (e) {
Log.print('Error decoding DriverList JSON: $e');
}
} else {
Log.print('Error: DriverList data is null or not a String.');
}
if (driverList.length >= 3) {
if (Platform.isAndroid) {
notificationController.showNotification(
title,
'${'you will pay to Driver'.tr} ${driverList[3].toString()} \$',
'tone1');
}
Get.find<AudioRecorderController>().stopRecording();
// ... (باقي كود المحفظة) ...
Get.find<MapPassengerController>().tripFinishedFromDriver();
// ... (إشعار "لا تنسى متعلقاتك") ...
Get.to(() => RateDriverFromPassenger(), arguments: {
'driverId': driverList[0].toString(),
'rideId': driverList[1].toString(),
'price': driverList[3].toString()
});
} else {
Log.print('Error: TRIP_FINISHED decoded list error.');
}
} else if (category == 'Finish Monitor') {
// <-- كان "Finish Monitor".tr
Get.defaultDialog(
titleStyle: AppStyle.title,
title: 'Trip finished '.tr,
middleText: '',
confirm: MyElevatedButton(
title: 'Ok'.tr,
onPressed: () {
Get.offAll(() => const MapPagePassenger());
}));
} else if (category == 'Driver Cancelled Your Trip') {
if (Platform.isAndroid) {
notificationController.showNotification(
'Driver Cancelled Your Trip'.tr,
'you will pay to Driver you will be pay the cost of driver time look to your Intaleq Wallet'
.tr,
'cancel');
}
box.write(BoxName.parentTripSelected, false);
box.remove(BoxName.tokenParent);
Get.find<MapPassengerController>().restCounter();
Get.offAll(() => const MapPagePassenger());
}
// ... (باقي الحالات مثل Call Income, Call End, إلخ) ...
// ... بنفس الطريقة ...
else if (category == 'Order Applied') {
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');
}
}
}
// Future<void> fireBaseTitles(RemoteMessage message) async {
// if (message.notification!.title! == 'Order'.tr) {
// Log.print('message: ${message}');
// if (Platform.isAndroid) {
// notificationController.showNotification(
// 'Order'.tr, message.notification!.body!, 'Order');
// }
// } else // ... داخل معالج الإشعارات في تطبيق الراكب ...
// if (message.notification!.title! == 'Accepted Ride') {
// // ...
// // انظر هنا: قمنا بتغيير "passengerList" إلى "driverList"
// var driverListJson = message.data['driverList'];
// // تأكد من أن البيانات ليست null قبل المتابعة
// if (driverListJson != null) {
// var myList = jsonDecode(driverListJson) as List<dynamic>;
// Log.print('myList: ${myList}');
// final controller = Get.find<MapPassengerController>();
// // استدعاء الدالة الموحدة الجديدة التي أنشأناها
// await controller.processRideAcceptance(
// driverIdFromFCM: myList[0].toString(),
// rideIdFromFCM: myList[3].toString());
// } else {
// Log.print(
// '❌ خطأ فادح: إشعار "Accepted Ride" وصل بدون بيانات (driverList is null)');
// }
// } else if (message.notification!.title! == 'Promo'.tr) {
// if (Platform.isAndroid) {
// notificationController.showNotification(
// 'Promo', 'Show latest promo'.tr, 'promo');
// }
// Get.to(const PromosPassengerPage());
// } else if (message.notification!.title! == 'Trip Monitoring'.tr) {
// if (Platform.isAndroid) {
// notificationController.showNotification(
// 'Trip Monitoring'.tr, '', 'iphone_ringtone');
// }
// var myListString = message.data['DriverList'];
// var myList = jsonDecode(myListString) as List<dynamic>;
// Get.toNamed('/tripmonitor', arguments: {
// 'rideId': myList[0].toString(),
// 'driverId': myList[1].toString(),
// });
// } else if (message.notification!.title! == 'token change'.tr) {
// if (Platform.isAndroid) {
// notificationController.showNotification(
// 'token change'.tr, 'token change'.tr, 'cancel');
// }
// GoogleSignInHelper.signOut();
// } else if (message.notification!.title! == 'Driver Is Going To Passenger') {
// Get.find<MapPassengerController>().isDriverInPassengerWay = true;
// Get.find<MapPassengerController>().update();
// 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') {
// if (Platform.isAndroid) {
// notificationController.showNotification(
// 'message From passenger'.tr, ''.tr, 'ding');
// }
// passengerDialog(message.notification!.body!);
// update();
// } else if (message.notification!.title! == 'message From Driver') {
// if (Platform.isAndroid) {
// notificationController.showNotification(
// 'message From Driver'.tr, ''.tr, 'ding');
// }
// passengerDialog(message.notification!.body!);
// update();
// } else // (هذا الكود في معالج الإشعارات لديك)
// if (message.notification!.title! == 'Trip is Begin') {
// Log.print('[FCM] استقبل إشعار "Trip is Begin".');
// // (تم حذف الإشعار المحلي من هنا، نُقل إلى الدالة الموحدة)
// final controller = Get.find<MapPassengerController>();
// // استدعاء حارس البوابة الجديد والآمن
// controller.processRideBegin();
// // (تم حذف كل الأوامر التالية من هنا)
// // Get.find<MapPassengerController>().getBeginRideFromDriver();
// // box.write(BoxName.passengerWalletTotal, '0');
// // update();
// } else if (message.notification!.title! == 'Hi ,I will go now'.tr) {
// // Get.snackbar('Hi ,I will go now', '',
// // backgroundColor: AppColor.greenColor);
// if (Platform.isAndroid) {
// notificationController.showNotification(
// 'Passenger come to you'.tr, 'Hi ,I will go now'.tr, 'ding');
// }
// update();
// } // ... داخل معالج الإشعارات (FCM Handler) ...
// if (message.notification!.title! == 'Hi ,I Arrive your site'.tr) {
// final controller = Get.find<MapPassengerController>();
// // 1. التأكد أننا في الحالة الصحيحة (السائق كان في الطريق)
// if (controller.currentRideState.value == RideState.driverApplied) {
// Log.print('[FCM] السائق وصل. تغيير الحالة إلى driverArrived');
// // 2. تغيير الحالة فقط!
// controller.currentRideState.value = RideState.driverArrived;
// }
// } else if (message.notification!.title! == "Cancel Trip from driver") {
// Get.back();
// if (Platform.isAndroid) {
// notificationController.showNotification("Cancel Trip from driver".tr,
// "We will look for a new driver.\nPlease wait.".tr, 'cancel');
// }
// Get.defaultDialog(
// title: "The driver canceled your ride.".tr,
// middleText: "We will look for a new driver.\nPlease wait.".tr,
// confirm: MyElevatedButton(
// kolor: AppColor.greenColor,
// title: 'Ok'.tr,
// onPressed: () async {
// Get.back();
// await Get.find<MapPassengerController>()
// .reSearchAfterCanceledFromDriver();
// },
// ),
// cancel: MyElevatedButton(
// title: 'Cancel'.tr,
// kolor: AppColor.redColor,
// onPressed: () {
// Get.offAll(() => const MapPagePassenger());
// },
// )
// // Get.find<MapPassengerController>()
// // .searchNewDriverAfterRejectingFromDriver();
// );
// } else if (message.notification!.title! == 'Driver Finish Trip'.tr) {
// // الخطوة 1: استقبل البيانات وتحقق من وجودها
// final rawData = message.data['DriverList'];
// List<dynamic> driverList = []; // ابدأ بقائمة فارغة كإجراء وقائي
// // الخطوة 2: قم بفك تشفير البيانات بأمان
// if (rawData != null && rawData is String) {
// try {
// driverList = jsonDecode(rawData);
// Log.print('Successfully decoded DriverList: $driverList');
// } catch (e) {
// Log.print('Error decoding DriverList JSON: $e');
// // اترك القائمة فارغة في حالة حدوث خطأ
// }
// } else {
// Log.print('Error: DriverList data is null or not a String.');
// }
// // الخطوة 3: استخدم البيانات فقط إذا كانت القائمة تحتوي على العناصر المطلوبة
// // هذا يمنع خطأ "RangeError" إذا كانت القائمة أقصر من المتوقع
// if (driverList.length >= 4) {
// if (Platform.isAndroid) {
// notificationController.showNotification(
// "Driver Finish Trip".tr,
// '${'you will pay to Driver'.tr} ${driverList[3].toString()} \$', // تم تحسين طريقة عرض النص
// 'tone1');
// }
// Get.find<AudioRecorderController>().stopRecording();
// if ((double.tryParse(
// box.read(BoxName.passengerWalletTotal).toString()) ??
// 0) <
// 0) {
// box.write(BoxName.passengerWalletTotal, 0);
// }
// Get.find<MapPassengerController>().tripFinishedFromDriver();
// NotificationController().showNotification(
// 'Dont forget your personal belongings.'.tr,
// 'Please make sure you have all your personal belongings and that any remaining fare, if applicable, has been added to your wallet before leaving. Thank you for choosing the Intaleq app'
// .tr,
// 'ding');
// Get.to(() => RateDriverFromPassenger(), arguments: {
// 'driverId': driverList[0].toString(),
// 'rideId': driverList[1].toString(),
// 'price': driverList[3].toString()
// });
// } else {
// Log.print(
// 'Error: Decoded driverList does not have enough elements. Received: $driverList');
// // هنا يمكنك عرض رسالة خطأ للمستخدم إذا لزم الأمر
// }
// } else if (message.notification!.title! == "Finish Monitor".tr) {
// Get.defaultDialog(
// titleStyle: AppStyle.title,
// title: 'Trip finished '.tr,
// middleText: '',
// confirm: MyElevatedButton(
// title: 'Ok'.tr,
// onPressed: () {
// Get.offAll(() => const MapPagePassenger());
// }));
// }
// // else if (message.notification!.title! == "Trip Monitoring".tr) {
// // Get.to(() => const TripMonitor());
// // }
// else if (message.notification!.title! == 'Call Income') {
// try {
// var myListString = message.data['DriverList'];
// var driverList = jsonDecode(myListString) as List<dynamic>;
// // if (Platform.isAndroid) {
// 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(),
// // token: driverList[0].toString(),
// // remoteID: driverList[2].toString(),
// // ));
// } catch (e) {}
// } else if (message.notification!.title! == 'Call Income from Driver'.tr) {
// try {
// var myListString = message.data['DriverList'];
// var driverList = jsonDecode(myListString) as List<dynamic>;
// // if (Platform.isAndroid) {
// 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(),
// // token: driverList[0].toString(),
// // remoteID: driverList[2].toString(),
// // ));
// } catch (e) {}
// } else if (message.notification!.title! == 'Call End'.tr) {
// try {
// var myListString = message.data['DriverList'];
// var driverList = jsonDecode(myListString) as List<dynamic>;
// if (Platform.isAndroid) {
// notificationController.showNotification(
// 'Call End'.tr,
// message.notification!.body!,
// 'ding',
// );
// }
// // Assuming GetMaterialApp is initialized and context is valid for navigation
// // Get.off(const CallPage());
// } catch (e) {}
// } else if (message.notification!.title! == 'Driver Cancelled Your Trip') {
// // Get.snackbar(
// // 'You will be pay the cost to driver or we will get it from you on next trip'
// // .tr,
// // 'message',
// // backgroundColor: AppColor.redColor);
// if (Platform.isAndroid) {
// notificationController.showNotification(
// 'Driver Cancelled Your Trip'.tr,
// 'you will pay to Driver you will be pay the cost of driver time look to your Intaleq Wallet'
// .tr,
// 'cancel');
// }
// box.write(BoxName.parentTripSelected, false);
// box.remove(BoxName.tokenParent);
// Get.find<MapPassengerController>().restCounter();
// Get.offAll(() => const MapPagePassenger());
// }
// // else if (message.notification!.title! == 'Order Applied') {
// // Get.snackbar(
// // "The order has been accepted by another driver."
// // .tr, // Corrected grammar
// // "Be more mindful next time to avoid dropping orders."
// // .tr, // Improved sentence structure
// // backgroundColor: AppColor.yellowColor,
// // snackPosition: SnackPosition.BOTTOM,
// // );
// // }
// else if (message.notification!.title! == 'Order Applied'.tr) {
// 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');
// }
// }
// }
SnackbarController driverAppliedTripSnakBar() {
return Get.snackbar(
'Driver Applied the Ride for You'.tr,
'',
colorText: AppColor.greenColor,
duration: const Duration(seconds: 3),
snackPosition: SnackPosition.TOP,
titleText: Text(
'Applied'.tr,
style: const TextStyle(color: AppColor.redColor),
),
messageText: Text(
'Driver Applied the Ride for You'.tr,
style: AppStyle.title,
),
icon: const Icon(Icons.approval),
shouldIconPulse: true,
margin: const EdgeInsets.all(16),
padding: const EdgeInsets.all(16),
);
}
Future<dynamic> passengerDialog(String message) {
return Get.defaultDialog(
barrierDismissible: false,
title: 'message From Driver'.tr,
titleStyle: AppStyle.title,
middleTextStyle: AppStyle.title,
middleText: message.tr,
confirm: MyElevatedButton(
title: 'Ok'.tr,
onPressed: () {
// Get.find<FirebaseMessagesController>().sendNotificationToPassengerToken(
// 'Hi ,I will go now'.tr,
// 'I will go now'.tr,
// Get.find<MapPassengerController>().driverToken, []);
// Get.find<MapPassengerController>()
// .startTimerDriverWaitPassenger5Minute();
Get.back();
}));
}
Future<dynamic> driverFinishTripDialoge(List<dynamic> driverList) {
return Get.defaultDialog(
title: 'Driver Finish Trip'.tr,
content: const DriverTipWidget(),
confirm: MyElevatedButton(
title: 'Yes'.tr,
onPressed: () async {
Get.to(() => RateDriverFromPassenger(), arguments: {
'driverId': driverList[0].toString(),
'rideId': driverList[1].toString(),
'price': driverList[3].toString()
});
},
kolor: AppColor.greenColor,
),
cancel: MyElevatedButton(
title: 'No,I want'.tr,
onPressed: () {
Get.to(() => RateDriverFromPassenger(), arguments: {
'driverId': driverList[0].toString(),
'rideId': driverList[1].toString(),
'price': driverList[3].toString()
});
},
kolor: AppColor.redColor,
));
}
}
class DriverTipWidget extends StatelessWidget {
const DriverTipWidget({
super.key,
});
@override
Widget build(BuildContext context) {
return GetBuilder<MapPassengerController>(builder: (controller) {
return Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
// Text(
// '${'Your fee is '.tr}${Get.find<MapPassengerController>().totalPassenger.toStringAsFixed(2)}'),
Text(
'Do you want to pay Tips for this Driver'.tr,
textAlign: TextAlign.center,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
InkWell(
onTap: () {
box.write(BoxName.tipPercentage, '0.05');
Toast.show(
context,
'${'Tip is '.tr}${(controller.totalPassenger) * (double.parse(box.read(BoxName.tipPercentage.toString())))}',
AppColor.blueColor);
controller.update();
},
child: Container(
decoration: BoxDecoration(border: Border.all()),
child: const Padding(
padding: EdgeInsets.all(4),
child: Center(
child: Text('5%'),
),
),
),
),
InkWell(
onTap: () {
box.write(BoxName.tipPercentage, '0.10');
Toast.show(
context,
'${'Tip is'.tr} ${(controller.totalPassenger) * (double.parse(box.read(BoxName.tipPercentage.toString())))}',
AppColor.blueColor);
controller.update();
},
child: Container(
decoration: BoxDecoration(border: Border.all()),
child: const Center(
child: Padding(
padding: EdgeInsets.all(5),
child: Text('10%'),
),
),
),
),
InkWell(
onTap: () {
box.write(BoxName.tipPercentage, '0.15');
Toast.show(
context,
'${'Tip is'.tr} ${(controller.totalPassenger) * (double.parse(box.read(BoxName.tipPercentage.toString())))}',
AppColor.blueColor);
controller.update();
},
child: Container(
decoration: BoxDecoration(border: Border.all()),
child: const Center(
child: Padding(
padding: EdgeInsets.all(5),
child: Text('15%'),
),
),
),
),
InkWell(
onTap: () {
box.write(BoxName.tipPercentage, '0.20');
Toast.show(
context,
'${'Tip is'.tr} ${(controller.totalPassenger) * (double.parse(box.read(BoxName.tipPercentage.toString())))}',
AppColor.blueColor);
controller.update();
},
child: Container(
decoration: BoxDecoration(border: Border.all()),
child: const Center(
child: Padding(
padding: EdgeInsets.all(5),
child: Text('20%'),
),
),
),
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
MyElevatedButton(
kolor: AppColor.redColor,
title: 'No i want'.tr,
onPressed: () {
box.write(BoxName.tipPercentage, '0');
controller.update();
}),
Container(
decoration: AppStyle.boxDecoration1,
child: Padding(
padding: const EdgeInsets.all(6),
child: Text(
'${(controller.totalPassenger) * (double.parse(box.read(BoxName.tipPercentage.toString())))} ${box.read(BoxName.countryCode) == 'Egypt' ? 'LE'.tr : 'JOD'.tr}',
style: AppStyle.title,
),
),
),
],
)
],
);
});
}
}