associatedOrderRate method

OrderRate? associatedOrderRate(
  1. QuotedRate rate,
  2. {bool lockPrice = false}
)

Implementation

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

  filterFunction(OrderRate orderRate) {
    if (orderRate.price == null) {
      return false;
    }

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

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

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

    return true;
  }

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