Is there a way to get the height of a CachedNetworkImage. I found this solution to get the height of a regular network image. Is there a way to implement this for a cached image?
Asked
Active
Viewed 8,122 times
1 Answers
15
Just a little modification from this existing solution https://stackoverflow.com/a/57640169/5882307 worked.
Code:
Future<Size> _calculateImageDimension() {
Completer<Size> completer = Completer();
Image image = new Image(image: CachedNetworkImageProvider("https://i.stack.imgur.com/lkd0a.png")); // I modified this line
image.image.resolve(ImageConfiguration()).addListener(
ImageStreamListener(
(ImageInfo image, bool synchronousCall) {
var myImage = image.image;
Size size = Size(myImage.width.toDouble(), myImage.height.toDouble());
completer.complete(size);
},
),
);
return completer.future;
}
Use as:
_calculateImageDimension().then((size) => print("size = ${size}")); // 487.0,696.0
All due credits to the original author: https://stackoverflow.com/a/57640169/5882307

OMi Shah
- 5,768
- 3
- 25
- 34
-
can you explain what modification you made ? looks exactly same – Fuad All Aug 20 '20 at 01:14
-
It's already commented out in the code that I added. Care to read. I have used cached network image provider instead of Image.networl() widget – OMi Shah Aug 20 '20 at 11:06
-
1thanks for clarifying. your inline code comment not visible without scrolling. – Fuad All Aug 20 '20 at 17:18