modifyInitialFractionsToIncludeFirstHeader static method

  1. @visibleForTesting
List<double> modifyInitialFractionsToIncludeFirstHeader(
  1. List<double> initialFractions,
  2. List<PreferredSizeWidget> headers,
  3. double totalHeight
)

Implementation

@visibleForTesting
static List<double> modifyInitialFractionsToIncludeFirstHeader(
  List<double> initialFractions,
  List<PreferredSizeWidget> headers,
  double totalHeight,
) {
  var totalHeaderHeight = 0.0;
  for (final header in headers) {
    totalHeaderHeight += header.preferredSize.height;
  }
  final intendedContentHeight = totalHeight - totalHeaderHeight;
  final intendedChildHeights = List<double>.generate(
    initialFractions.length,
    (i) => intendedContentHeight * initialFractions[i],
  );
  final trueContentHeight =
      intendedContentHeight + headers[0].preferredSize.height;
  return List<double>.generate(initialFractions.length, (i) {
    if (i == 0) {
      return (intendedChildHeights[i] + headers[0].preferredSize.height) /
          trueContentHeight;
    }
    return intendedChildHeights[i] / trueContentHeight;
  });
}