SizeAspectRatio.resize constructor
SizeAspectRatio.resize(
- int width,
- int height,
- int maxWidth,
- int maxHeight,
)
Implementation
factory SizeAspectRatio.resize(
int width,
int height,
int maxWidth,
int maxHeight,
) {
double scaleFactor = (maxWidth / width > maxHeight / height)
? maxHeight / height
: maxWidth / width;
int newWidth = (width * scaleFactor).round();
int newHeight = (height * scaleFactor).round();
int finalWidth = newWidth.clamp(0, maxWidth);
int finalHeight = newHeight.clamp(0, maxHeight);
return SizeAspectRatio(
width: finalWidth,
height: finalHeight,
);
}