fitSize function
Implementation
Size fitSize(Size containerSize, Size imgSize, [bool fill = false]) {
double containerWHScale = containerSize.width / containerSize.height;
double imgWHScale = imgSize.width / imgSize.height;
double scale;
if (imgWHScale < containerWHScale) {
if (fill) {
scale = containerSize.width / imgSize.width;
} else {
scale = containerSize.height / imgSize.height;
}
} else {
if (fill) {
scale = containerSize.height / imgSize.height;
} else {
scale = containerSize.width / imgSize.width;
}
}
final height = imgSize.height * scale;
final width = imgSize.width * scale;
return Size(width, height);
}