Files
tripz/lib/views/home/map_widget.dart/main_bottom_Menu_map.dart
Hamza-Ayed a40c6851ee 9/8/1
2024-09-08 10:31:59 +03:00

659 lines
32 KiB
Dart

import 'package:SEFER/views/widgets/my_textField.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:SEFER/constant/box_name.dart';
import 'package:SEFER/constant/style.dart';
import 'package:SEFER/controller/home/map_passenger_controller.dart';
import 'package:SEFER/main.dart';
import 'package:SEFER/views/home/map_widget.dart/form_search_places_destenation.dart';
import 'package:SEFER/views/widgets/elevated_btn.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import '../../../constant/colors.dart';
import '../../../constant/table_names.dart';
import '../../../controller/functions/toast.dart';
import '../../../controller/functions/tts.dart';
import 'form_search_start.dart';
class MainBottomMenuMap extends StatelessWidget {
const MainBottomMenuMap({super.key});
@override
Widget build(BuildContext context) {
Get.put(MapPassengerController());
return GetBuilder<MapPassengerController>(
builder: (controller) => Positioned(
bottom: 3,
left: 5,
right: 5,
child: GestureDetector(
child: AnimatedContainer(
duration: const Duration(milliseconds: 500),
height: controller.mainBottomMenuMapHeight,
decoration: AppStyle.boxDecoration,
child: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
controller.isMainBottomMenuMap
? Padding(
padding: const EdgeInsets.all(15),
child: InkWell(
onTap: () =>
controller.changeMainBottomMenuMap(),
child: Container(
width: Get.width * .8,
height: Get.height * .1,
decoration: const BoxDecoration(
boxShadow: [
BoxShadow(
color: Color.fromARGB(
255, 237, 230, 230),
blurRadius: 5,
offset: Offset(2, 4)),
BoxShadow(
color: Color.fromARGB(
255, 242, 237, 237),
blurRadius: 5,
offset: Offset(-2, -2))
],
color: AppColor.blueColor,
borderRadius: BorderRadius.all(
Radius.elliptical(15, 30),
),
),
// decoration: AppStyle.boxDecoration1,
child: DefaultTextStyle(
style: AppStyle.title.copyWith(
color: AppColor.secondaryColor),
child: Center(
child: controller.isPickerShown
? clickPointPosition(
controller, context)
: whereWidgetSmall(controller),
),
)),
),
)
: IconButton(
onPressed: () {
controller.changeMainBottomMenuMap();
},
icon: controller.isMainBottomMenuMap
? const Icon(
Icons.ads_click,
color: AppColor.secondaryColor,
size: 35,
)
: const Icon(
Icons.arrow_circle_down_rounded,
size: 35,
),
),
controller.isMainBottomMenuMap
? recentPlacesWidget(controller)
: const SizedBox(),
// controller.isMainBottomMenuMap
// ? const SizedBox()
// : InkWell(
// onTap: () async {
// controller.getCurrentLocationFormString();
// },
// child: Text(
// 'From :'.tr +
// ' ${controller.currentLocationString}'.tr,
// style: AppStyle.subtitle,
// ),
// ),
controller.isMainBottomMenuMap
? const SizedBox()
: Column(
children: [
!controller.isAnotherOreder
? const SizedBox()
: formSearchPlacesStart(),
formSearchPlacesDestenation(),
const SizedBox(
height: 10,
),
// MyElevatedButton(
// title: 'Get Details of Trip'.tr,
// onPressed: () async {
// controller.changeMainBottomMenuMap();
//
// await controller.getMap(
// '${controller.newStartPointLocation.latitude},${controller.newStartPointLocation.longitude}',
// '${controller.newMyLocation.latitude},${controller.newMyLocation.longitude}',
// );
// controller.currentLocationToFormPlaces =
// false;
// controller.placesDestination = [];
// // controller.isCancelRidePageShown = true;
// controller.clearPlacesStart();
// controller.clearPlacesDestination();
//
// controller.showBottomSheet1();
// Get.back();
// controller.showBottomSheet1();
// }),
//todo If you want add stop click here
InkWell(
onTap: () {
Get.dialog(
Dialog(
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.circular(16)),
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
'WhatsApp Location Extractor'
.tr,
style: AppStyle.title,
),
const SizedBox(height: 16),
Form(
key: controller.sosFormKey,
child: Column(
children: [
MyTextForm(
controller: controller
.whatsAppLocationText,
label:
'Location Link'.tr,
hint:
'Paste location link here'
.tr,
type: TextInputType.url,
),
const SizedBox(
height: 16),
MyElevatedButton(
title:
'Go to this location'
.tr,
onPressed: () async {
controller
.goToWhatappLocation();
},
)
],
),
),
],
),
),
),
);
},
child: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
Colors.blue[300]!,
Colors.blue[600]!
],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
),
borderRadius: BorderRadius.circular(12),
boxShadow: const [
BoxShadow(
color: Colors.black26,
offset: Offset(0, 4),
blurRadius: 5.0,
),
],
),
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Text(
'Paste WhatsApp location link here'
.tr,
style: const TextStyle(
color: Colors.white,
fontSize: 16,
fontWeight: FontWeight.bold,
),
textAlign: TextAlign.center,
),
),
),
),
CupertinoButton(
child: Text(
!controller.isAnotherOreder
? 'I want to order for someone else'
.tr
: 'I want to order for myself'.tr,
),
onPressed: () {
showCupertinoModalPopup(
context: context,
builder: (BuildContext context) =>
CupertinoActionSheet(
title: Text('Select Order Type'.tr),
message: Text(
'Choose who this order is for'
.tr),
actions: <Widget>[
CupertinoActionSheetAction(
child: Row(
mainAxisAlignment:
MainAxisAlignment.center,
children: [
const Icon(
CupertinoIcons.person,
color: CupertinoColors
.activeBlue),
const SizedBox(width: 15),
Text(
'I want to order for myself'
.tr),
],
),
onPressed: () {
controller
.changeisAnotherOreder(
false);
Navigator.pop(context);
},
),
CupertinoActionSheetAction(
child: Row(
mainAxisAlignment:
MainAxisAlignment.center,
children: [
const Icon(
CupertinoIcons.person_2,
color: CupertinoColors
.activeBlue),
const SizedBox(width: 15),
Text(
'I want to order for someone else'
.tr),
],
),
onPressed: () {
controller
.changeisAnotherOreder(
true);
Navigator.pop(context);
},
),
],
cancelButton:
CupertinoActionSheetAction(
isDefaultAction: true,
onPressed: () {
Navigator.pop(context);
},
child: Text('Cancel'.tr),
),
),
);
},
)
],
)
],
),
),
),
),
));
}
SizedBox recentPlacesWidget(MapPassengerController controller) {
final textToSpeechController = Get.put(TextToSpeechController());
return SizedBox(
height: controller.recentPlaces.isEmpty ? 0 : 50,
child: ListView.builder(
itemCount: controller.recentPlaces.length,
scrollDirection: Axis.horizontal,
itemBuilder: (BuildContext context, int index) {
return TextButton(
onPressed: () {
Get.defaultDialog(
title: 'Are you want to go this site'.tr,
titleStyle: AppStyle.title,
middleText: '',
content: IconButton(
onPressed: () {
textToSpeechController
.speakText('Are you want to go this site'.tr);
},
icon: const Icon(
Icons.headphones,
size: 45,
),
),
confirm: MyElevatedButton(
title: 'Yes'.tr,
onPressed: () async {
Get.back();
controller.getLocation();
await controller.getMap(
'${controller.passengerLocation.latitude},${controller.passengerLocation.longitude}',
'${controller.recentPlaces[index]['latitude']},${controller.recentPlaces[index]['longitude']}',
);
// controller.changePickerShown();
controller.showBottomSheet1();
// controller.showBottomSheet1();
},
));
},
child: Container(
decoration: AppStyle.boxDecoration1,
child: Padding(
padding: const EdgeInsets.all(2),
child: Text(
controller.recentPlaces[index]['name'],
style: AppStyle.title,
),
),
),
);
},
),
);
}
TextButton clickPointPosition(
MapPassengerController controller, BuildContext context) {
return TextButton(
onPressed: () async {
controller.clearPolyline();
controller.data = [];
//todo add isAnothorOrder
if (controller.passengerStartLocationFromMap == true) {
controller.newMyLocation = controller.newStartPointLocation;
controller.changeMainBottomMenuMap();
await controller.getMap(
'${controller.newStartPointLocation.latitude},${controller.newStartPointLocation.longitude}',
'${controller.myDestination.latitude},${controller.myDestination.longitude}',
);
controller.currentLocationToFormPlaces = false;
controller.placesDestination = [];
// controller.isCancelRidePageShown = true;
controller.clearPlacesStart();
controller.clearPlacesDestination();
controller.passengerStartLocationFromMap = false;
controller.isPickerShown = false;
// controller.showBottomSheet1();
// Get.back();
controller.showBottomSheet1();
// controller.hintTextStartPoint =
// '${controller.newStartPointLocation.latitude.toStringAsFixed(4)} , ${controller.newStartPointLocation.longitude.toStringAsFixed(4)}';
} else if (controller.startLocationFromMap == true) {
controller.newMyLocation = controller.newStartPointLocation;
controller.hintTextStartPoint =
'${controller.newStartPointLocation.latitude.toStringAsFixed(4)} , ${controller.newStartPointLocation.longitude.toStringAsFixed(4)}';
controller.startLocationFromMap = false;
controller.isPickerShown = false;
} else if (controller.workLocationFromMap == true) {
controller.hintTextDestinationPoint = 'To Work'.tr;
box.write(BoxName.addWork,
'${controller.newMyLocation.latitude.toStringAsFixed(4)} , ${controller.newMyLocation.longitude.toStringAsFixed(4)}');
controller.newMyLocation = controller.newMyLocation;
controller.isPickerShown = false;
controller.workLocationFromMap = false;
Get.snackbar('Work Saved'.tr, '',
backgroundColor: AppColor.greenColor);
} else if (controller.homeLocationFromMap == true) {
controller.hintTextDestinationPoint = 'To Home'.tr;
box.write(BoxName.addHome,
'${controller.newMyLocation.latitude.toStringAsFixed(4)} , ${controller.newMyLocation.longitude.toStringAsFixed(4)}');
controller.newMyLocation = controller.newMyLocation;
controller.isPickerShown = false;
controller.homeLocationFromMap = false;
controller.update();
Get.snackbar('Home Saved'.tr, '',
backgroundColor: AppColor.greenColor);
} else {
controller.hintTextDestinationPoint =
'${controller.newMyLocation.latitude.toStringAsFixed(4)} , ${controller.newMyLocation.longitude.toStringAsFixed(4)}';
controller.myDestination = controller.newMyLocation;
controller.isPickerShown = false;
controller.changeMainBottomMenuMap();
controller.passengerStartLocationFromMap = true;
controller.isPickerShown = true;
if (controller.isAnotherOreder == false) {
await controller.mapController?.animateCamera(
CameraUpdate.newLatLng(LatLng(
controller.passengerLocation.latitude,
controller.passengerLocation.longitude)));
Get.defaultDialog(
title: 'Destination selected'.tr,
titleStyle: AppStyle.title,
content: Text(
'Now select start pick'.tr,
style: AppStyle.title,
),
confirm: MyElevatedButton(
title: 'OK'.tr,
onPressed: () {
Get.back();
}));
} else {}
if (controller.isWhatsAppOrder == true) {
Get.defaultDialog(
title: 'Destination selected'.tr,
titleStyle: AppStyle.title,
content: Text(
'Now select start pick'.tr,
style: AppStyle.title,
),
confirm: MyElevatedButton(
title: 'OK'.tr,
onPressed: () {
Get.back();
}));
} else {}
}
controller.placesDestination = [];
controller.placeDestinationController.clear();
controller.showBottomSheet1();
// Get.back();
// controller.showBottomSheet1();
controller.changeMainBottomMenuMap();
},
child: Row(
children: [
IconButton(
onPressed: () {
// controller.changeMainBottomMenuMap();
},
icon: controller.isMainBottomMenuMap
? const Icon(
Icons.arrow_circle_up_rounded,
size: 35,
color: AppColor.secondaryColor,
)
: const Icon(
Icons.arrow_circle_down_rounded,
size: 35,
),
),
Text(
controller.passengerStartLocationFromMap
? 'Pick or Tap to confirm'.tr
// ? 'Pick your ride location on the map - Tap to confirm'.tr
: "Click here point".tr,
style: AppStyle.title.copyWith(
color: AppColor.secondaryColor,
fontWeight: FontWeight.bold,
fontSize: 18),
),
],
),
);
}
Row whereWidgetSmall(MapPassengerController controller) {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
IconButton(
onPressed: () {
controller.changeMainBottomMenuMap();
},
icon: controller.isMainBottomMenuMap
? const Icon(
Icons.ads_click,
color: AppColor.secondaryColor,
size: 35,
)
: const Icon(
Icons.arrow_circle_down_rounded,
size: 35,
),
),
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
SizedBox(
height: 25,
child: Text('${'Where to'.tr} ${box.read(BoxName.name)}')),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
if (controller.noCarString)
Text('Nearest Car for you about '.tr)
else
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12),
color: AppColor.redColor,
),
child: null,
),
if (!controller.noCarString)
Padding(
padding: const EdgeInsets.all(4),
child: Text(
(controller.nearestCar != null
? controller.nearestDistance.toStringAsFixed(0)
: ''),
),
),
],
)
],
),
],
);
}
}
class FaviouratePlacesDialog extends StatelessWidget {
const FaviouratePlacesDialog({
super.key,
});
@override
Widget build(BuildContext context) {
Get.put(MapPassengerController());
return GetBuilder<MapPassengerController>(
builder: (controller) => DefaultTextStyle(
style: AppStyle.title,
child: Center(
child: InkWell(
onTap: () async {
List favoritePlaces =
await sql.getAllData(TableName.placesFavorite);
Get.defaultDialog(
title: 'Favorite Places'.tr,
content: SizedBox(
width: Get.width * .8,
height: 300,
child: favoritePlaces.isEmpty
? Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(
Icons.hourglass_empty_rounded,
size: 99,
color: AppColor.primaryColor,
),
Text(
'You Dont Have Any places yet !'.tr,
style: AppStyle.title,
),
],
),
)
: ListView.builder(
itemCount: favoritePlaces.length,
itemBuilder: (BuildContext context, int index) {
return Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
TextButton(
onPressed: () async {
Get.back();
controller.getLocation();
await controller.getMap(
'${controller.passengerLocation.latitude},${controller.passengerLocation.longitude}',
'${favoritePlaces[index]['latitude']},${favoritePlaces[index]['longitude']}',
);
// controller.changePickerShown();
controller.showBottomSheet1();
controller.showBottomSheet1();
},
child: Text(
favoritePlaces[index]['name'],
style: AppStyle.title,
),
),
IconButton(
onPressed: () async {
await sql.deleteData(
TableName.placesFavorite,
favoritePlaces[index]['id']);
Get.back();
// ignore: use_build_context_synchronously
Toast.show(
context,
'${'You are Delete'.tr} ${favoritePlaces[index]['name']} from your list',
AppColor.redColor);
// Get.snackbar('Deleted'.tr,
// '${'You are Delete'.tr} ${favoritePlaces[index]['name']} from your list',
// backgroundColor:
// AppColor.accentColor);
},
icon: const Icon(Icons.favorite_outlined),
),
],
);
},
),
),
cancel: MyElevatedButton(
title: 'Back'.tr, onPressed: () => Get.back()),
);
},
child: Text(
'\u{1F3D8} ' 'Favorite Places'.tr,
style: AppStyle.title,
),
)),
));
}
}