calculateImageSize function
Implementation
({int? width, int? height}) calculateImageSize(Size size, SlideAsset? asset) {
int? cacheWidth;
int? cacheHeight;
// check if height or asset is larger
if (asset != null) {
// cache the smallest dimension of the image
// So set the other dimension to null
if (asset.isPortrait) {
cacheHeight = min(size.height, asset.dimensions.height).toInt();
} else {
cacheWidth = min(size.width, asset.dimensions.width).toInt();
}
} else {
// If no asset is available, set both cacheWidth and cacheHeight
final ifHeightIsBigger = size.height > size.width;
// cache the smallest
if (ifHeightIsBigger) {
cacheWidth = size.width.toInt();
} else {
cacheHeight = size.height.toInt();
}
}
return (width: cacheWidth, height: cacheHeight);
}