Untitled

 avatar
unknown
plain_text
a year ago
2.1 kB
9
Indexable
  getTotalAmount() async {
    // totalDistance = calculateDistance(
    //   isPickSavedAddress ? pickAddressData!.latitude.validate().toDouble() : pickLat.toDouble(),
    //   isPickSavedAddress ? pickAddressData!.longitude.validate().toDouble() : pickLong.toDouble(),
    //   isDeliverySavedAddress ? deliveryAddressData!.latitude.validate().toDouble() : deliverLat.toDouble(),
    //   isDeliverySavedAddress ? deliveryAddressData!.longitude.validate().toDouble() : deliverLong.toDouble(),
    // );

    await getGoogleMapDirectionsApi(
      isPickSavedAddress ? pickAddressData!.latitude.validate().toDouble() : pickLat.toDouble(),
      isPickSavedAddress ? pickAddressData!.longitude.validate().toDouble() : pickLong.toDouble(),
      isDeliverySavedAddress ? deliveryAddressData!.latitude.validate().toDouble() : deliverLat.toDouble(),
      isDeliverySavedAddress ? deliveryAddressData!.longitude.validate().toDouble() : deliverLong.toDouble(),
    ).then((distance) {
      totalDistance = distance;
      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
      cityData!.extraCharges!.forEach((element) {
        totalExtraCharge += countExtraCharge(totalAmount: totalAmount, charges: element.charges!, chargesType: element.chargesType!);
      });

      /// All Charges
      totalAmount = (totalAmount + totalExtraCharge).toStringAsFixed(digitAfterDecimal).toDouble();
    });
  }
Editor is loading...
Leave a Comment