26-1-20/1
This commit is contained in:
@@ -1,261 +1,89 @@
|
||||
// import 'dart:io';
|
||||
|
||||
// import 'package:bubble_head/bubble.dart';
|
||||
// import 'package:flutter/material.dart';
|
||||
// import 'package:flutter_font_icons/flutter_font_icons.dart';
|
||||
// import 'package:get/get.dart';
|
||||
// import 'package:sefer_driver/constant/info.dart';
|
||||
// import 'package:sefer_driver/controller/functions/location_controller.dart';
|
||||
// import 'package:sefer_driver/views/widgets/elevated_btn.dart';
|
||||
// import 'package:sefer_driver/views/widgets/my_textField.dart';
|
||||
// import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
// import '../../../../constant/box_name.dart';
|
||||
// import '../../../../constant/colors.dart';
|
||||
// import '../../../../constant/style.dart';
|
||||
// import '../../../../controller/functions/launch.dart';
|
||||
// import '../../../../controller/home/captin/map_driver_controller.dart';
|
||||
// import '../../../../main.dart';
|
||||
|
||||
// class SosConnect extends StatelessWidget {
|
||||
// const SosConnect({super.key});
|
||||
|
||||
// @override
|
||||
// Widget build(BuildContext context) {
|
||||
// return GetBuilder<MapDriverController>(
|
||||
// builder: (mapDriverController) => mapDriverController.isRideStarted
|
||||
// ? Positioned(
|
||||
// left: 16,
|
||||
// bottom: 16,
|
||||
// child: Card(
|
||||
// elevation: 4,
|
||||
// shape: RoundedRectangleBorder(
|
||||
// borderRadius: BorderRadius.circular(12),
|
||||
// ),
|
||||
// child: SizedBox(
|
||||
// height: 60,
|
||||
// width: 180,
|
||||
// child: Row(
|
||||
// mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
// children: [
|
||||
// IconButton(
|
||||
// onPressed: () {
|
||||
// _handleSosCall(mapDriverController);
|
||||
// },
|
||||
// icon: const Icon(
|
||||
// Icons.sos_sharp,
|
||||
// size: 32,
|
||||
// color: AppColor.redColor,
|
||||
// ),
|
||||
// tooltip: 'SOS - Call Emergency',
|
||||
// ),
|
||||
// VerticalDivider(
|
||||
// color: Colors.grey[300],
|
||||
// thickness: 1,
|
||||
// ),
|
||||
// IconButton(
|
||||
// onPressed: () {
|
||||
// _handleWhatsApp(mapDriverController);
|
||||
// },
|
||||
// icon: const Icon(
|
||||
// FontAwesome.whatsapp,
|
||||
// color: AppColor.greenColor,
|
||||
// size: 32,
|
||||
// ),
|
||||
// tooltip: 'SOS - Send WhatsApp Message',
|
||||
// ),
|
||||
// VerticalDivider(
|
||||
// color: Colors.grey[300],
|
||||
// thickness: 1,
|
||||
// ),
|
||||
// IconButton(
|
||||
// onPressed: () {
|
||||
// _handleGoogleMap(mapDriverController);
|
||||
// },
|
||||
// icon: const Icon(
|
||||
// MaterialCommunityIcons.map_marker_radius,
|
||||
// color: AppColor.primaryColor,
|
||||
// size: 32,
|
||||
// ),
|
||||
// tooltip: 'Google Maps - Navigate',
|
||||
// ),
|
||||
// ],
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// )
|
||||
// : const SizedBox(),
|
||||
// );
|
||||
// }
|
||||
|
||||
// void _handleSosCall(MapDriverController mapDriverController) {
|
||||
// if (box.read(BoxName.sosPhoneDriver) == null) {
|
||||
// Get.defaultDialog(
|
||||
// title: 'Insert Emergency Number'.tr,
|
||||
// content: Form(
|
||||
// key: mapDriverController.formKey1,
|
||||
// child: MyTextForm(
|
||||
// controller: mapDriverController.sosEmergincyNumberCotroller,
|
||||
// label: 'Emergency Number'.tr,
|
||||
// hint: 'Enter phone number'.tr,
|
||||
// type: TextInputType.phone,
|
||||
// ),
|
||||
// ),
|
||||
// confirm: MyElevatedButton(
|
||||
// title: 'Save'.tr,
|
||||
// onPressed: () {
|
||||
// if (mapDriverController.formKey1.currentState!.validate()) {
|
||||
// box.write(BoxName.sosPhoneDriver,
|
||||
// mapDriverController.sosEmergincyNumberCotroller.text);
|
||||
// Get.back(); // Close the dialog
|
||||
// launchCommunication(
|
||||
// 'phone', box.read(BoxName.sosPhoneDriver), '');
|
||||
// }
|
||||
// },
|
||||
// ),
|
||||
// );
|
||||
// } else {
|
||||
// launchCommunication('phone', box.read(BoxName.sosPhoneDriver), '');
|
||||
// }
|
||||
// }
|
||||
|
||||
// void _handleWhatsApp(MapDriverController mapDriverController) {
|
||||
// if (box.read(BoxName.sosPhoneDriver) == null) {
|
||||
// Get.defaultDialog(
|
||||
// title: 'Insert Emergency Number'.tr,
|
||||
// content: Form(
|
||||
// key: mapDriverController.formKey1,
|
||||
// child: MyTextForm(
|
||||
// controller: mapDriverController.sosEmergincyNumberCotroller,
|
||||
// label: 'Emergency Number'.tr,
|
||||
// hint: 'Enter phone number'.tr,
|
||||
// type: TextInputType.phone,
|
||||
// ),
|
||||
// ),
|
||||
// confirm: MyElevatedButton(
|
||||
// title: 'Save'.tr,
|
||||
// onPressed: () {
|
||||
// if (mapDriverController.formKey1.currentState!.validate()) {
|
||||
// box.write(BoxName.sosPhoneDriver,
|
||||
// mapDriverController.sosEmergincyNumberCotroller.text);
|
||||
// Get.back(); // Close the dialog
|
||||
// _sendWhatsAppMessage(mapDriverController);
|
||||
// }
|
||||
// },
|
||||
// ),
|
||||
// );
|
||||
// } else {
|
||||
// _sendWhatsAppMessage(mapDriverController);
|
||||
// }
|
||||
// }
|
||||
|
||||
// void _handleGoogleMap(MapDriverController mapDriverController) {
|
||||
// () async {
|
||||
// if (Platform.isAndroid) {
|
||||
// Bubble().startBubbleHead(sendAppToBackground: true);
|
||||
// }
|
||||
// var startLat =
|
||||
// Get.find<MapDriverController>().latLngPassengerLocation.latitude;
|
||||
// var startLng =
|
||||
// Get.find<MapDriverController>().latLngPassengerLocation.longitude;
|
||||
|
||||
// var endLat =
|
||||
// Get.find<MapDriverController>().latLngPassengerDestination.latitude;
|
||||
// var endLng =
|
||||
// Get.find<MapDriverController>().latLngPassengerDestination.longitude;
|
||||
|
||||
// String url =
|
||||
// 'https://www.google.com/maps/dir/$startLat,$startLng/$endLat,$endLng/&directionsmode=driving';
|
||||
// if (await canLaunchUrl(Uri.parse(url))) {
|
||||
// await launchUrl(Uri.parse(url));
|
||||
// } else {
|
||||
// throw 'Could not launch google maps';
|
||||
// }
|
||||
// }();
|
||||
// }
|
||||
|
||||
// void _sendWhatsAppMessage(MapDriverController mapDriverController) {
|
||||
// final sosNumber = box.read(BoxName.sosPhoneDriver);
|
||||
// if (sosNumber != null) {
|
||||
// launchCommunication(
|
||||
// 'whatsapp',
|
||||
// '+2$sosNumber', // Consider international format
|
||||
// "${"Hello, this is Driver".tr} ${box.read(BoxName.nameDriver)}. "
|
||||
// "${"My current location is:".tr} "
|
||||
// "https://www.google.com/maps/place/"
|
||||
// "${Get.find<LocationController>().myLocation.latitude},"
|
||||
// "${Get.find<LocationController>().myLocation.longitude} "
|
||||
// "${"\nI have a trip on".tr} ${AppInformation.appName} "
|
||||
// "${"app with passenger".tr} ${mapDriverController.passengerName}.",
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:sefer_driver/views/widgets/elevated_btn.dart';
|
||||
import 'package:sefer_driver/views/widgets/error_snakbar.dart';
|
||||
import 'package:sefer_driver/views/widgets/my_textField.dart';
|
||||
import 'package:sefer_driver/views/widgets/elevated_btn.dart'; // Checked import
|
||||
import 'package:flutter_font_icons/flutter_font_icons.dart';
|
||||
|
||||
import '../../../../constant/box_name.dart';
|
||||
import '../../../../constant/colors.dart';
|
||||
import '../../../../constant/style.dart';
|
||||
import '../../../../controller/firebase/firbase_messge.dart';
|
||||
import '../../../../controller/firebase/notification_service.dart';
|
||||
import '../../../../controller/functions/launch.dart';
|
||||
import '../../../../controller/home/captin/map_driver_controller.dart';
|
||||
import '../../../../main.dart';
|
||||
|
||||
// Changed: إعادة تصميم وتغيير موضع أزرار التواصل والطوارئ
|
||||
class SosConnect extends StatelessWidget {
|
||||
SosConnect({super.key});
|
||||
final fcm = Get.isRegistered<FirebaseMessagesController>()
|
||||
? Get.find<FirebaseMessagesController>()
|
||||
: Get.put(FirebaseMessagesController());
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GetBuilder<MapDriverController>(
|
||||
id: 'SosConnect', // Keep ID for updates
|
||||
builder: (controller) {
|
||||
// New: تجميع الأزرار في عمود واحد على الجانب الأيمن
|
||||
return Positioned(
|
||||
bottom: 110, // New: فوق عداد السرعة
|
||||
right: 16,
|
||||
// Check visibility logic
|
||||
bool showPassengerContact =
|
||||
!controller.isRideBegin && controller.isPassengerInfoWindow;
|
||||
bool showSos = controller.isRideStarted;
|
||||
|
||||
if (!showPassengerContact && !showSos) return const SizedBox();
|
||||
|
||||
// REMOVED: Positioned widget
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(8),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withOpacity(0.95),
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.1),
|
||||
blurRadius: 10,
|
||||
offset: const Offset(0, 4),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
// زر الاتصال بالراكب (يظهر قبل بدء الرحلة)
|
||||
if (!controller.isRideBegin && controller.isPassengerInfoWindow)
|
||||
_buildSocialButton(
|
||||
icon: Icons.phone,
|
||||
color: AppColor.blueColor,
|
||||
// === Call Button ===
|
||||
if (showPassengerContact)
|
||||
_buildModernActionButton(
|
||||
icon: Icons.phone_in_talk,
|
||||
color: Colors.white,
|
||||
bgColor: AppColor.blueColor,
|
||||
tooltip: 'Call Passenger',
|
||||
onPressed: () async {
|
||||
onTap: () async {
|
||||
controller.isSocialPressed = true;
|
||||
await controller.driverCallPassenger();
|
||||
makePhoneCall(controller.passengerPhone.toString());
|
||||
bool canCall = await controller.driverCallPassenger();
|
||||
if (canCall) {
|
||||
makePhoneCall(controller.passengerPhone.toString());
|
||||
} else {
|
||||
mySnackeBarError("Policy restriction on calls".tr);
|
||||
}
|
||||
},
|
||||
),
|
||||
|
||||
// زر الرسائل للراكب (يظهر قبل بدء الرحلة)
|
||||
if (!controller.isRideBegin && controller.isPassengerInfoWindow)
|
||||
const SizedBox(height: 12),
|
||||
if (!controller.isRideBegin && controller.isPassengerInfoWindow)
|
||||
_buildSocialButton(
|
||||
icon: Icons.message,
|
||||
color: AppColor.greenColor,
|
||||
tooltip: 'Send Message',
|
||||
onPressed: () {
|
||||
// الكود الخاص بنافذة الرسائل السريعة
|
||||
_showMessageOptions(context, controller);
|
||||
},
|
||||
if (showPassengerContact) const SizedBox(height: 12),
|
||||
|
||||
// === Message Button ===
|
||||
if (showPassengerContact)
|
||||
_buildModernActionButton(
|
||||
icon: MaterialCommunityIcons.message_text_outline,
|
||||
color: AppColor.primaryColor,
|
||||
bgColor: Colors.grey.shade100,
|
||||
tooltip: 'Message Passenger',
|
||||
onTap: () => _showMessageOptions(context, controller),
|
||||
),
|
||||
|
||||
// زر الطوارئ (SOS) (يظهر بعد بدء الرحلة)
|
||||
if (controller.isRideStarted)
|
||||
_buildSocialButton(
|
||||
icon: Icons.sos_sharp,
|
||||
color: AppColor.redColor,
|
||||
tooltip: 'SOS - Call Emergency',
|
||||
onPressed: () => _handleSosCall(controller),
|
||||
// === SOS Button ===
|
||||
if (showSos)
|
||||
_buildModernActionButton(
|
||||
icon: MaterialIcons.warning,
|
||||
color: Colors.white,
|
||||
bgColor: AppColor.redColor,
|
||||
tooltip: 'EMERGENCY SOS',
|
||||
isPulsing: true,
|
||||
onTap: () => _handleSosCall(controller),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -264,42 +92,62 @@ class SosConnect extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
// New: ودجت منفصل لبناء أزرار التواصل
|
||||
Widget _buildSocialButton(
|
||||
{required IconData icon,
|
||||
required Color color,
|
||||
required String tooltip,
|
||||
required VoidCallback onPressed}) {
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: Colors.white,
|
||||
boxShadow: [BoxShadow(blurRadius: 5, color: Colors.black26)],
|
||||
),
|
||||
child: IconButton(
|
||||
icon: Icon(icon, color: color, size: 28),
|
||||
tooltip: tooltip,
|
||||
onPressed: onPressed,
|
||||
Widget _buildModernActionButton({
|
||||
required IconData icon,
|
||||
required Color color,
|
||||
required Color bgColor,
|
||||
required String tooltip,
|
||||
required VoidCallback onTap,
|
||||
bool isPulsing = false,
|
||||
}) {
|
||||
return Material(
|
||||
color: Colors.transparent,
|
||||
child: InkWell(
|
||||
onTap: onTap,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
child: Container(
|
||||
width: 48,
|
||||
height: 48,
|
||||
decoration: BoxDecoration(
|
||||
color: bgColor,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
boxShadow: isPulsing
|
||||
? [
|
||||
BoxShadow(
|
||||
color: bgColor.withOpacity(0.4),
|
||||
blurRadius: 12,
|
||||
spreadRadius: 2,
|
||||
)
|
||||
]
|
||||
: [],
|
||||
),
|
||||
child: Icon(icon, color: color, size: 24),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// الكود الخاص بنافذة إدخال رقم الطوارئ
|
||||
// --- Logic Functions ---
|
||||
void _handleSosCall(MapDriverController mapDriverController) {
|
||||
if (box.read(BoxName.sosPhoneDriver) == null) {
|
||||
Get.defaultDialog(
|
||||
title: 'Insert Emergency Number'.tr,
|
||||
content: Form(
|
||||
key: mapDriverController.formKey1,
|
||||
child: MyTextForm(
|
||||
controller: mapDriverController.sosEmergincyNumberCotroller,
|
||||
label: 'Emergency Number'.tr,
|
||||
hint: 'Enter phone number'.tr,
|
||||
type: TextInputType.phone,
|
||||
),
|
||||
title: 'Emergency Contact'.tr,
|
||||
content: Column(
|
||||
children: [
|
||||
Text('Please enter the emergency number.'.tr),
|
||||
Form(
|
||||
key: mapDriverController.formKey1,
|
||||
child: MyTextForm(
|
||||
controller: mapDriverController.sosEmergincyNumberCotroller,
|
||||
label: 'Phone Number'.tr,
|
||||
hint: '01xxxxxxxxx',
|
||||
type: TextInputType.phone,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
confirm: MyElevatedButton(
|
||||
title: 'Save'.tr,
|
||||
title: 'Save & Call'.tr,
|
||||
onPressed: () {
|
||||
if (mapDriverController.formKey1.currentState!.validate()) {
|
||||
box.write(BoxName.sosPhoneDriver,
|
||||
@@ -316,120 +164,70 @@ class SosConnect extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
// New: الكود الخاص بنافذة الرسائل السريعة (مستخرج من passenger_info_window.dart)
|
||||
void _showMessageOptions(
|
||||
BuildContext context, MapDriverController controller) {
|
||||
Get.bottomSheet(
|
||||
backgroundColor: Colors.white,
|
||||
shape: const RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.vertical(top: Radius.circular(20)),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: _buildMessageOptions(controller),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildMessageOptions(MapDriverController controller) {
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text('Select a quick message'.tr, style: AppStyle.title),
|
||||
const SizedBox(height: 16),
|
||||
_buildMessageTile(
|
||||
text: "Where are you, sir?".tr,
|
||||
onTap: () {
|
||||
// fcm.sendNotificationToDriverMAP(
|
||||
// 'message From Driver',
|
||||
// "Where are you, sir?".tr,
|
||||
// controller.tokenPassenger,
|
||||
// [],
|
||||
// 'ding');
|
||||
NotificationService.sendNotification(
|
||||
target: controller.tokenPassenger.toString(),
|
||||
title: 'message From Driver'.tr,
|
||||
body: "Where are you, sir?".tr,
|
||||
isTopic: false, // Important: this is a token
|
||||
tone: 'ding',
|
||||
driverList: [], category: 'message From Driver',
|
||||
);
|
||||
Get.back();
|
||||
}),
|
||||
_buildMessageTile(
|
||||
text: "I've been trying to reach you but your phone is off.".tr,
|
||||
onTap: () {
|
||||
// fcm.sendNotificationToDriverMAP(
|
||||
// 'message From Driver',
|
||||
// "I've been trying to reach you but your phone is off.".tr,
|
||||
// controller.tokenPassenger,
|
||||
// [],
|
||||
// 'ding');
|
||||
NotificationService.sendNotification(
|
||||
target: controller.tokenPassenger.toString(),
|
||||
title: 'message From Driver'.tr,
|
||||
body: "I've been trying to reach you but your phone is off.".tr,
|
||||
isTopic: false, // Important: this is a token
|
||||
tone: 'ding',
|
||||
driverList: [], category: 'message From Driver',
|
||||
);
|
||||
Get.back();
|
||||
}),
|
||||
const SizedBox(height: 16),
|
||||
Row(
|
||||
Container(
|
||||
padding: const EdgeInsets.all(20),
|
||||
decoration: const BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.vertical(top: Radius.circular(25)),
|
||||
),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Form(
|
||||
key: controller.formKey2,
|
||||
child: MyTextForm(
|
||||
controller: controller.messageToPassenger,
|
||||
label: 'Type something'.tr,
|
||||
hint: 'Type something'.tr,
|
||||
type: TextInputType.text,
|
||||
Text('Quick Messages'.tr,
|
||||
style:
|
||||
const TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
|
||||
const SizedBox(height: 15),
|
||||
_buildQuickMessageItem("Where are you, sir?".tr, controller),
|
||||
_buildQuickMessageItem("I've arrived.".tr, controller),
|
||||
const Divider(),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: controller.messageToPassenger,
|
||||
decoration:
|
||||
InputDecoration(hintText: 'Type a message...'.tr),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
// fcm.sendNotificationToDriverMAP(
|
||||
// 'message From Driver',
|
||||
// controller.messageToPassenger.text,
|
||||
// controller.tokenPassenger,
|
||||
// [],
|
||||
// 'ding');
|
||||
NotificationService.sendNotification(
|
||||
target: controller.tokenPassenger.toString(),
|
||||
title: 'message From Driver'.tr,
|
||||
body: 'change device'.tr,
|
||||
isTopic: false, // Important: this is a token
|
||||
tone: 'cancel',
|
||||
driverList: [], category: 'message From Driver',
|
||||
);
|
||||
controller.messageToPassenger.clear();
|
||||
Get.back();
|
||||
},
|
||||
icon: const Icon(Icons.send),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.send),
|
||||
onPressed: () {
|
||||
_sendMessage(controller, controller.messageToPassenger.text,
|
||||
'cancel');
|
||||
controller.messageToPassenger.clear();
|
||||
Get.back();
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildMessageTile(
|
||||
{required String text, required VoidCallback onTap}) {
|
||||
return InkWell(
|
||||
onTap: onTap,
|
||||
child: Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.all(12),
|
||||
margin: const EdgeInsets.symmetric(vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
color: Colors.grey[100],
|
||||
),
|
||||
child: Text(text, style: AppStyle.title),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildQuickMessageItem(String text, MapDriverController controller) {
|
||||
return ListTile(
|
||||
title: Text(text),
|
||||
onTap: () {
|
||||
_sendMessage(controller, text, 'ding');
|
||||
Get.back();
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
void _sendMessage(MapDriverController controller, String body, String tone) {
|
||||
NotificationService.sendNotification(
|
||||
target: controller.tokenPassenger.toString(),
|
||||
title: 'Driver Message'.tr,
|
||||
body: body,
|
||||
isTopic: false,
|
||||
tone: tone,
|
||||
driverList: [],
|
||||
category: 'message From Driver',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user