convertArea function Null safety

num convertArea(
  1. num area,
  2. [dynamic originalUnit = Unit.meters,
  3. dynamic finalUnit = Unit.kilometers]
)

Implementation

num convertArea(num area,
    [originalUnit = Unit.meters, finalUnit = Unit.kilometers]) {
  if (area < 0) {
    throw Exception("area must be a positive number");
  }

  num? startFactor = areaFactors[originalUnit];
  if (startFactor == null) {
    throw Exception("invalid original units");
  }

  num? finalFactor = areaFactors[finalUnit];
  if (finalFactor == null) {
    throw Exception("invalid final units");
  }

  return (area / startFactor) * finalFactor;
}