getOptimalHorizontalPadding static method

double getOptimalHorizontalPadding({
  1. required double minPadding,
  2. required double currentScreenWidth,
  3. double? maxWidgetWidthOverwrite,
})

Calculates the optimal horizontal padding to ensure the content width does not exceed 800px.

This method adjusts the padding based on the current screen width. If the screen width exceeds the maximum allowed width for the widget, the padding is adjusted to center the content.

  • minPadding: The minimum padding to apply if no adjustments are needed.
  • currentScreenWidth: The current width of the screen.

Returns the optimal padding value to be used with EdgeInsets.

Implementation

static double getOptimalHorizontalPadding({
  required double minPadding,
  required double currentScreenWidth,
  double? maxWidgetWidthOverwrite,
}) {
  double optimalPadding = minPadding;
  double maxWidgetWidthWithoutPadding = maxWidgetWidthOverwrite ?? kSizes_maxWidgetWidth;
  double maxAllowedWidth = maxWidgetWidthWithoutPadding + (minPadding * 2);

  // Adjust the padding to center the content if the screen exceeds the maximum allowed width.
  if (currentScreenWidth > maxAllowedWidth) {
    optimalPadding = (currentScreenWidth - maxWidgetWidthWithoutPadding) / 2;
  }

  return optimalPadding;
}