25-7-28-2
This commit is contained in:
193
lib/views/home/Captin/mapDriverWidgets/sos_connect.dart
Executable file
193
lib/views/home/Captin/mapDriverWidgets/sos_connect.dart
Executable file
@@ -0,0 +1,193 @@
|
||||
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}.",
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user