ResponsiveWidth function

double ResponsiveWidth(
  1. BuildContext context,
  2. double containerWidth, {
  3. double? designScreenWidth = 1536,
})

Implementation

double ResponsiveWidth(BuildContext context, double containerWidth,
    {double? designScreenWidth = 1536}) {
  final screenWidth = MediaQuery.of(context).size.width;

  // Set the reference screen width once
  _referenceScreenWidth ??= designScreenWidth;

  // Calculate the scaling factor
  final scaleFactor = screenWidth / _referenceScreenWidth!;

  // Calculate and return the responsive width
  return containerWidth * scaleFactor;
}