balance3Values method

(int, int, int) balance3Values({
  1. required int first,
  2. required int second,
  3. required int third,
})

Balances three values ensuring they sum up to 100.

This function adjusts the first value to ensure that the sum of all three values is 100. If the sum of the first and third values exceeds 100, the third value is set to 0 and the remaining percentage is distributed between the first and second values. If the sum is less than 100, the remaining percentage is assigned to the second value.

Returns a tuple containing the balanced values.

Implementation

(int, int, int) balance3Values(
    {required int first, required int second, required int third}) {
  // Validate the first value.
  final validateFirst = _validatePercent(value: first);
  if ((validateFirst + third) > 100) {
    // If the sum of the first and third values exceeds 100, adjust the values.
    return (validateFirst, 0, 100 - validateFirst);
  } else {
    // If the sum is less than 100, adjust the values accordingly.
    return (validateFirst, 100 - validateFirst - third, third);
  }
}