calculateHeight static method

double calculateHeight({
  1. required BuildContext context,
  2. required int index,
  3. required int totalSwitches,
  4. List<double>? customHeights,
  5. required double minHeight,
})

Ignores customHeights if toggle switch is horizontal

Implementation

static double calculateHeight(
    {required BuildContext context,
    required int index,
    required int totalSwitches,
    List<double>? customHeights,
    required double minHeight}) {
  /// Extra height to prevent overflow and add padding
  double extraHeight = 0.10 * totalSwitches;

  /// Max screen height
  double screenHeight = MediaQuery.of(context).size.height;

  /// Returns width per label
  ///
  /// Returns passed minHeight per label if total requested width plus extra height is less than max screen height.
  /// Returns calculated width to fit within the max screen width if total requested width plus extra height is more than max screen height.
  return customHeights != null
      ? customHeights[index]
      : ((totalSwitches + extraHeight) * minHeight < screenHeight
          ? minHeight
          : screenHeight / (totalSwitches + extraHeight));
}