I'm trying to use the Image.network constructor's loadingBuilder argument.
While the image loads, I want to show a CircularProgressIndicator with its value set to the ratio of downloaded divided by the expected file size. I expected I could do this using the ImageChunkEvent parameter's cumulativeBytesLoaded, expectedTotalBytes.
I found a sample in the documentation:
The following sample uses
loadingBuilderto show aCircularProgressIndicatorwhile an image loads over the network.
Image.network(
'https://example.com/image.jpg',
loadingBuilder: (BuildContext context, Widget child, ImageChunkEvent loadingProgress) {
if (loadingProgress == null)
return child;
return Center(
child: CircularProgressIndicator(
value: loadingProgress.expectedTotalBytes != null
? loadingProgress.cumulativeBytesLoaded / loadingProgress.expectedTotalBytes
: null,
),
);
},
),
But the issue is that the loadingProgress is always null, so the whole loadingBuilder charade I'm doing is for nothing.
Why is ImageChunkEvent loadingProgress not passed to the loadingBuilder function with real values?
i found the solution after 3 years
loadingBuilder:(context, child, loadingProgress) {
if (loadingProgress != null) {
print(loadingProgress.cumulativeBytesLoaded);
return CircularProgressIndicator(
value: loadingProgress.cumulativeBytesLoaded /
loadingProgress.expectedTotalBytes!);
}
return child;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With