associatedShipmentRate method

ShipmentRate? associatedShipmentRate(
  1. QuotedRate rate,
  2. {bool lockPrice = false}
)

Implementation

ShipmentRate? associatedShipmentRate(QuotedRate rate,
    {bool lockPrice = false}) {
  if (rates == null) {
    throw MissingPropertyException.generate(toString(), 'rates');
  }

  filterFunction(ShipmentRate shipmentRate) {
    if (shipmentRate.price == null) {
      return false;
    }

    if (lockPrice) {
      if (shipmentRate.price != rate.price) {
        return false;
      }
    }

    if (shipmentRate.carrier != null) {
      if (rate.carrier != null) {
        if (shipmentRate.carrier != rate.carrier) {
          return false;
        }
      }
    }

    if (shipmentRate.service != null) {
      if (rate.service != null) {
        if (shipmentRate.service != rate.service) {
          return false;
        }
      }
    }

    return true;
  }

  try {
    return rates!.firstWhere(filterFunction);
  } on StateError {
    return null;
  }
}