convertLength function Null safety

num convertLength(
  1. num length,
  2. [Unit originalUnit = Unit.kilometers,
  3. Unit finalUnit = Unit.kilometers]
)

Implementation

num convertLength(
  num length, [
  Unit originalUnit = Unit.kilometers,
  Unit finalUnit = Unit.kilometers,
]) {
  if (length < 0) {
    throw Exception("length must be a positive number");
  }
  return radiansToLength(lengthToRadians(length, originalUnit), finalUnit);
}