heightInMeasurementSystem property

({int subunit, int unit}) get heightInMeasurementSystem

Gets the height in the specified measurement system. Returns a tuple containing the unit and subunit (e.g., unit = meters, subunit = centimeters for metric).

Implementation

({int unit, int subunit}) get heightInMeasurementSystem {
  switch (heightUnit) {
    case MeasurementSystem.metric:
      // If the measurement system is metric, calculate height in meters and centimeters
      int meters = _height?.toInt() ?? 0;
      int centimeter = (((_height ?? 0) - (_height?.toInt() ?? 0)).round() *
              Conversion.centiMeterToMeter.value)
          .toInt();
      return _height != null
          ? (unit: meters, subunit: centimeter)
          : (unit: 1, subunit: 6);
    default:
      // If the measurement system is imperial, calculate height in feet and inches
      int feet = ((_height ?? 0) * Conversion.meterToInch.value) ~/
          Conversion.feetToInch.value;
      int inches = (((_height ?? 0) * Conversion.meterToInch.value) %
              Conversion.feetToInch.value)
          .toInt();
      return _height != null
          ? (unit: feet, subunit: inches)
          : (unit: 5, subunit: 6);
  }
}