import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:get/get_core/src/get_main.dart';
import 'package:get/get_navigation/src/extension_navigation.dart';
import 'package:get/get_state_manager/get_state_manager.dart';
import 'package:get/get_utils/src/extensions/internacionalization.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:iketfaa_delivery/App/Common/Modules/Dashboard/binding/dashboard_binding.dart';
import 'package:iketfaa_delivery/App/Common/Modules/Dashboard/view/dashboard_view.dart';
import 'package:iketfaa_delivery/App/Common/Services/translation_service.dart';
import 'package:iketfaa_delivery/App/Common/Utilities/Constants/AppColors.dart';
import 'package:iketfaa_delivery/App/Common/Utilities/Constants/AppStyles.dart';
import 'package:iketfaa_delivery/App/Delivery/Models/Main/DriverNewOffer.dart';
import 'package:iketfaa_delivery/App/Delivery/Modules/DeliveryHub/binding/delivery_hub_binding.dart';
import 'package:iketfaa_delivery/App/Delivery/Modules/DeliveryHub/view/delivery_hub_view.dart';
import 'package:iketfaa_delivery/App/Delivery/Modules/DriverNewOrders/controller/delivery_driver_new_order_controller.dart';
import 'package:iketfaa_delivery/App/Delivery/Utilities/Widgets/TextFiledWithButton.dart';
import 'package:iketfaa_delivery/App/Delivery/Utilities/Widgets/delivery_fading_effect_map.dart';
import 'package:iketfaa_delivery/App/Delivery/Utilities/Widgets/delivery_white_button.dart';
import 'package:iketfaa_delivery/App/Delivery/Utilities/Widgets/primary_app_bar.dart';
class DeliveryDriverNewOrderSendOffer
extends GetView<DeliveryDriverNewOrderController> {
final GlobalKey<FormState> offerKey = new GlobalKey<FormState>();
@override
Widget build(BuildContext context) {
return SafeArea(
top: false,
child: Scaffold(
body: Stack(
children: [
Container(
margin: EdgeInsets.only(bottom: 100.0),
child: GoogleMap(
mapType: MapType.normal,
onMapCreated: controller.onMapCreated,
markers: Set<Marker>.of(controller.markers.values),
mapToolbarEnabled: false,
myLocationButtonEnabled: false,
myLocationEnabled: false,
zoomControlsEnabled: false,
compassEnabled: false,
rotateGesturesEnabled: true,
tiltGesturesEnabled: false,
initialCameraPosition: CameraPosition(
target: LatLng(
controller.authManager.appUser.value.locationData!
.localPosition!.latitude,
controller.authManager.appUser.value.locationData!
.localPosition!.longitude),
zoom: 10.0,
bearing: 30.0),
),
),
Align(
alignment: Alignment.bottomCenter,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Align(
alignment: Alignment.centerRight,
child: Container(
margin: EdgeInsets.all(10.0),
width: Get.width * 0.1,
height: Get.width * 0.1,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.white,
boxShadow: [AppStyles.primaryShadow],
),
child: new Material(
color: Colors.transparent,
child: new InkWell(
onTap: () {
controller.getCurrentLocation();
},
customBorder: CircleBorder(),
child: Center(
child: Icon(Icons.my_location),
)),
),
),
),
Container(
width: Get.width,
decoration: BoxDecoration(
color: AppColors.white,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(25.0),
topRight: Radius.circular(25.0),
),
boxShadow: [
BoxShadow(
blurRadius: 10,
color: AppColors.grey.withOpacity(0.2),
offset: Offset(0, 0),
spreadRadius: 3)
],
),
padding: EdgeInsets.symmetric(
horizontal: 30.0, vertical: 30.0),
child: SingleChildScrollView(
child: Column(
children: [
SizedBox(
height:
controller.driverNewOrder.value.orderType ==
0
? 25.0
: 0),
Container(
width: Get.width,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
controller.driverNewOrder.value.orderType == 0
? Row(
children: [
SvgPicture.asset(
"assets/svg/Motorbike.svg",
width: Get.width * 0.07,
),
SizedBox(
width: 10.0,
),
RichText(
text: TextSpan(
text:
"totalDistance".tr + ' ',
style: Get.theme.textTheme
.headline5!
.copyWith(
fontWeight:
FontWeight.w500),
children: <TextSpan>[
TextSpan(
text: controller
.authManager
.deliveryTools
.getDistanceString(controller
.authManager
.deliveryTools
.calculateAllDistanceForDriver(
controller
.driverNewOrder
.value
.orders!,
controller
.driverNewOrder
.value
.customerAddress!)),
style: Get.theme.textTheme
.headline5!
.copyWith(
color: AppColors
.primary,
fontWeight:
FontWeight
.bold),
),
]),
textAlign: TextAlign.start,
),
],
)
: SizedBox(),
SizedBox(
height: controller.driverNewOrder.value
.orderType ==
0
? 25.0
: 0),
controller.driverNewOrder.value.orderType == 0
? Row(
children: [
SvgPicture.asset(
"assets/svg/dolar.svg",
width: Get.width * 0.07),
SizedBox(
width: 10.0,
),
Expanded(
child: RichText(
text: TextSpan(
text:
"Delivery fee is between"
.tr +
' ',
style: Get.theme.textTheme
.headline5!
.copyWith(
fontWeight:
FontWeight
.w500),
children: <TextSpan>[
TextSpan(
text: controller
.driverNewOrder
.value
.firstEstimatePrice!
.toString(),
style: Get
.theme
.textTheme
.headline5!
.copyWith(
color: AppColors
.primary,
fontWeight:
FontWeight
.bold),
),
TextSpan(
text:
' ' + 'to'.tr + ' ',
style: Get
.theme
.textTheme
.headline5!
.copyWith(
fontWeight:
FontWeight
.w500),
),
TextSpan(
text: controller
.driverNewOrder
.value
.secondEstimatePrice!
.toString(),
style: Get
.theme
.textTheme
.headline5!
.copyWith(
color: AppColors
.primary,
fontWeight:
FontWeight
.bold),
),
TextSpan(
text: ' ' + 'SAR'.tr,
style: Get
.theme
.textTheme
.headline5!
.copyWith(
fontWeight:
FontWeight
.w500),
),
]),
textAlign: TextAlign.start,
),
),
],
)
: SizedBox(),
SizedBox(height: 25.0),
Row(
children: [
SvgPicture.asset(
"assets/svg/Icon payment.svg",
width: Get.width * 0.07,
),
SizedBox(
width: 10.0,
),
RichText(
text: TextSpan(
text: "PaymentMethod".tr + ' ',
style: Get
.theme.textTheme.headline5!
.copyWith(
fontWeight:
FontWeight.w500),
children: <TextSpan>[
TextSpan(
text: TranslationService()
.isLocaleArabic()
? controller
.deliveryHomeController
.deliveryHubController
.dashboardController
.paymentMethods
.value
.paymentMethods!
.where((element) =>
element.id ==
controller
.driverNewOrder
.value
.paymentType)
.first
.nameAR
: controller
.deliveryHomeController
.deliveryHubController
.dashboardController
.paymentMethods
.value
.paymentMethods!
.where((element) =>
element.id ==
controller
.driverNewOrder
.value
.paymentType)
.first
.nameEN,
style: Get
.theme.textTheme.headline5!
.copyWith(
color:
AppColors.primary,
fontWeight:
FontWeight.bold),
),
]),
textAlign: TextAlign.start,
),
],
),
SizedBox(height: 30.0),
Column(
children: [
Row(
children: [
SvgPicture.asset(
'assets/svg/timer.svg',
width: 20,
),
SizedBox(width: 5),
Text(
'expectedDeliveryat'.tr,
style: Get.textTheme.headline6,
),
],
),
const SizedBox(height: 10),
Obx(
() => DeliveryWhiteButton(
onTap: () {
controller.authManager.commonTools
.showCustomBottomSheet(
context,
'chooseEstimateDuration'.tr,
ListView.builder(
shrinkWrap: true,
itemCount: controller
.deliveryHomeController
.deliveryHubController
.dashboardController
.timeEstimatesDeliveryDriver
.value
.timeEstimateDeliveryDriver!
.length,
itemBuilder:
(context, index) {
return ListTile(
leading: Icon(
Icons
.timer_outlined,
color: AppColors
.primary,
),
title: Text(
TranslationService()
.isLocaleArabic()
? controller
.deliveryHomeController
.deliveryHubController
.dashboardController
.timeEstimatesDeliveryDriver
.value
.timeEstimateDeliveryDriver![
index]
.nameAR!
: controller
.deliveryHomeController
.deliveryHubController
.dashboardController
.timeEstimatesDeliveryDriver
.value
.timeEstimateDeliveryDriver![
index]
.nameEN!,
style: Get.textTheme
.headline4,
),
onTap: () {
controller
.estimateTime
.value = controller
.deliveryHomeController
.deliveryHubController
.dashboardController
.timeEstimatesDeliveryDriver
.value
.timeEstimateDeliveryDriver![
index];
controller
.durationValue
.value = TranslationService()
.isLocaleArabic()
? controller
.deliveryHomeController
.deliveryHubController
.dashboardController
.timeEstimatesDeliveryDriver
.value
.timeEstimateDeliveryDriver![
index]
.nameAR!
: controller
.deliveryHomeController
.deliveryHubController
.dashboardController
.timeEstimatesDeliveryDriver
.value
.timeEstimateDeliveryDriver![
index]
.nameEN!;
Get.back();
},
);
},
));
},
title: controller.durationValue.value,
),
),
],
),
],
),
),
SizedBox(
height: Get.width * 0.1,
),
Form(
key: offerKey,
autovalidateMode:
AutovalidateMode.onUserInteraction,
child: TextFiledWithButton(
maxLength: 6,
function: () async {
controller.authManager.commonTools
.unFocusKeyboard(context);
if (controller.estimateTime.value.id == null)
return controller.authManager.commonTools
.showFailedSnackBar(
'chooseEstimateDuration');
if (controller.offerController.text.isEmpty)
return controller.authManager.commonTools
.showFailedSnackBar(
'pleaseEnterDeliveryCost');
if ((controller.driverNewOrder.value
.firstEstimatePrice! >
double.parse(controller
.offerController.text) ||
controller.driverNewOrder.value
.secondEstimatePrice! <
double.parse(controller
.offerController.text)) &&
(controller
.driverNewOrder.value.orderType ==
0))
return controller.authManager.commonTools
.showFailedSnackBar(
'selectPriceBetweenDeliveryFee');
if (offerKey.currentState!.validate()) {
controller.authManager.commonTools
.showLoading();
DriverOffer driverOffer = DriverOffer(
orderID: controller
.driverNewOrder.value.orderID,
offerID: controller
.authManager.commonTools
.createRandom()
.toString(),
driverID: controller
.authManager.appUser.value.id,
price: double.parse(
controller.offerController.text),
totalDistance: controller
.authManager.deliveryTools
.calculateAllDistanceForDriver(
controller
.driverNewOrder.value.orders!,
controller.driverNewOrder.value
.customerAddress!),
driverName: controller
.authManager.appUser.value.name,
driverEstimateTime:
controller.estimateTime.value.id,
carClass: controller.authManager
.deliveryUser.value.driver!.carClass!,
carModel: controller.authManager
.deliveryUser.value.driver!.carModel!,
carType: controller.authManager
.deliveryUser.value.driver!.carType!,
carPlate: controller
.authManager
.deliveryUser
.value
.driver!
.vehiclePlateNumber!,
carYear: controller
.authManager
.deliveryUser
.value
.driver!
.manufacturingYear!,
rate: controller
.authManager.appUser.value.rating,
mobileNumber: controller.authManager
.appUser.value.phoneNumber,
date: DateTime.now(),
);
bool result = await controller
.deliveryHomeController
.deliveryHubController
.addToDatabase
.sendOffer(
controller.driverNewOrder.value
.customerID!,
driverOffer);
Get.back();
if (result) {
print('true');
Get.offAll(() => DashboardView(),
binding: DashboardBinding(), arguments: 'noGetData');
Get.to(() => DeliveryHubView(),
binding: DeliveryHubBinding(),
arguments: 'noGetData');
controller.authManager.commonTools
.showSuccessSnackBar(
'offerSubmittedSuccessfully');
} else {
Get.back();
controller.authManager.commonTools
.showFailedSnackBar('errorMessage');
}
}
},
controller: controller.offerController,
validator: (value) => controller
.authManager.commonTools
.offerPriceValidate(
controller.offerController),
),
),
SizedBox(
height: 10,
),
],
),
),
),
],
)),
Align(
alignment: Alignment.topCenter,
child: Container(
width: Get.width,
height: Get.height * 0.1,
child: CustomPaint(
foregroundPainter: DeliveryFadingEffectMap(),
),
)),
Column(
mainAxisSize: MainAxisSize.min,
children: [
PrimaryAppBar(
title: "Send Offer",
function: () {
Get.back();
}),
],
),
],
),
),
);
}
}