getRulerScaleValue method

num getRulerScaleValue(
  1. int index
)

Returns the ruler scale value for a given index.

This method calculates and returns the value of the ruler at a specific index. The index typically corresponds to the position of the ruler scale, and the value is a numeric representation of the unit measurement at that index.

Implementation

num getRulerScaleValue(int index) {
  num rulerScaleValue = 0;
  ScaleIntervals? currentConfig;
  for (ScaleIntervals config in widget.scaleUnit.scaleIntervals) {
    currentConfig = config;
    if (currentConfig == widget.scaleUnit.scaleIntervals.last) {
      break;
    }
    var totalCount = ((config.end - config.begin) / config.scale).truncate();
    if (index <= totalCount) {
      break;
    } else {
      index -= totalCount;
    }
  }

  rulerScaleValue = index * currentConfig!.scale + currentConfig.begin;

  return rulerScaleValue;
}