getSizedImages method

List<Widget> getSizedImages(
  1. List<Image> imageInfoList,
  2. double maxWidth
)

Implementation

List<Widget> getSizedImages(List<ui.Image> imageInfoList, double maxWidth) {
  double widthSum = 0;
  double targetHeight = imageInfoList[0].height.toDouble();
  for (var info in imageInfoList) {
    widthSum += targetHeight * info.width / info.height;
  }
  double widthScale = maxWidth / widthSum;

  List<Widget> sizedImages = [];
  int imageIndex = 0;
  for (final image in images) {
    int origWidth = imageInfoList[imageIndex].width;
    int origHeight = imageInfoList[imageIndex].height;
    double scale = targetHeight / origHeight * widthScale;
    sizedImages.add(SizedBox(
        width: origWidth * scale, height: origHeight * scale, child: image));
    imageIndex++;
  }
  return sizedImages;
}