recalculateQuantityFromUOMStringToCurrent method

double? recalculateQuantityFromUOMStringToCurrent({
  1. required double quantity,
  2. required String unitString,
  3. required UnitOfMeasuresDto? currentUOM,
  4. required List<UnitOfMeasuresDto> altUOMs,
})

Implementation

double? recalculateQuantityFromUOMStringToCurrent({
  required double quantity,
  required String unitString,
  required UnitOfMeasuresDto? currentUOM,
  required List<UnitOfMeasuresDto> altUOMs,
}) {
  final unit = uomFromString(uom: unitString, altUOMs: altUOMs);

  if (unit == null || currentUOM == null) return null;
  if (unit == currentUOM) return quantity;

  return unit.convertQuantity(
    newUnit: currentUOM,
    value: quantity,
  );
}