Untitled
unknown
plain_text
2 years ago
5.8 kB
11
Indexable
// replace getTotalAmount() with createOrderScreen.dart
getTotalAmount() async {
String? originLat = isPickSavedAddress ? pickAddressData!.latitude.validate() : pickLat;
String? originLong = isPickSavedAddress ? pickAddressData!.longitude.validate() : pickLong;
String? destinationLat = isDeliverySavedAddress ? deliveryAddressData!.latitude.validate() : deliverLat;
String? destinationLong = isDeliverySavedAddress ? deliveryAddressData!.longitude.validate() : deliverLong;
String origins = "${originLat},${originLong}";
String destinations = "${destinationLat},${destinationLong}";
await getDistanceBetweenLatLng(origins, destinations).then((value) {
double distanceInKms = value.rows[0].elements[0].distance.text.toString().split(' ')[0].toDouble();
if (appStore.distanceUnit == DISTANCE_UNIT_MILE) {
totalDistance = (MILES_PER_KM * distanceInKms);
} else {
totalDistance = distanceInKms;
}
totalAmount = 0;
weightCharge = 0;
distanceCharge = 0;
totalExtraCharge = 0;
/// calculate weight Charge
if (weightController.text.toDouble() > cityData!.minWeight!) {
weightCharge = ((weightController.text.toDouble() - cityData!.minWeight!) * cityData!.perWeightCharges!).toStringAsFixed(digitAfterDecimal).toDouble();
}
/// calculate distance Charge
if (totalDistance > cityData!.minDistance!) {
distanceCharge = ((totalDistance - cityData!.minDistance!) * cityData!.perDistanceCharges!).toStringAsFixed(digitAfterDecimal).toDouble();
}
/// total amount
totalAmount = cityData!.fixedCharges! + weightCharge + distanceCharge;
/// calculate extra charges
if (cityData!.extraCharges != null) {
cityData!.extraCharges!.forEach((element) {
totalExtraCharge += countExtraCharge(totalAmount: totalAmount, charges: element.charges!, chargesType: element.chargesType!);
});
}
/// All Charges
totalAmount = (totalAmount + totalExtraCharge).toStringAsFixed(digitAfterDecimal).toDouble();
});
}
//)goto lib -->user --> screens --> OrderDetailsscreen.dart
replace getDistanceApiCall() with code below
getDistanceApiCall() async {
String? originLat = orderData!.pickupPoint!.latitude.validate();
String? originLong = orderData!.pickupPoint!.longitude.validate();
String? destinationLat = orderData!.deliveryPoint!.latitude.validate();
String? destinationLong = orderData!.deliveryPoint!.longitude.validate();
String origins = "${originLat},${originLong}";
String destinations = "${destinationLat},${destinationLong}";
await getDistanceBetweenLatLng(origins, destinations).then((value) {
duration = value.rows[0].elements[0].duration.text;
double distanceInKms = value.rows[0].elements[0].distance.text.toString().split(' ')[0].toDouble();
if (appStore.distanceUnit == DISTANCE_UNIT_MILE) {
totalDistance = (MILES_PER_KM * distanceInKms);
distance = totalDistance.toString() + DISTANCE_UNIT_MILE;
} else {
totalDistance = distanceInKms;
distance = totalDistance.toString() + DISTANCE_UNIT_KM;
}
setState(() {});
});
}
//add below line of codes in orderDetial screen to dispaly distance and duration
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
children: [
Text(
language.distance,
style: secondaryTextStyle(size: 14),
overflow: TextOverflow.ellipsis,
maxLines: 1,
),
4.width,
Text(
distance ?? "0",
style: boldTextStyle(),
overflow: TextOverflow.ellipsis,
maxLines: 1,
),
],
),
Row(
children: [
Text(
language.duration,
style: secondaryTextStyle(size: 14),
overflow: TextOverflow.ellipsis,
maxLines: 1,
),
4.width,
Text(
duration ?? "0",
style: boldTextStyle(),
overflow: TextOverflow.ellipsis,
maxLines: 1,
),
],
),
],
).visible(orderData!.pickupPoint != null && orderData!.deliveryPoint != null),Editor is loading...
Leave a Comment