parseUnit function

Unit? parseUnit(
  1. Object? unit, [
  2. Unit? def
])

Implementation

Unit? parseUnit(Object? unit, [Unit? def]) {
  if (unit == null) {
    return def;
  } else if (unit is Unit) {
    return unit;
  } else if (unit is String) {
    return getUnitByName(unit);
  } else if (unit is int) {
    return getUnitByIndex(unit);
  } else {
    return def;
  }
}