getAlternativeUOMByCurrent method

UnitOfMeasuresDto getAlternativeUOMByCurrent({
  1. required List<UnitOfMeasuresDto> altUOMs,
  2. String? currentUOM,
})

Implementation

UnitOfMeasuresDto getAlternativeUOMByCurrent({
  required List<UnitOfMeasuresDto> altUOMs,
  String? currentUOM,
}) {
  if (altUOMs.isEmpty) throw Exception('Alternative units are empty');

  return altUOMs.firstWhere(
    (uom) => uom.unit == currentUOM,
    orElse: () => altUOMs.first,
  );
}