Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Image.network loadingBuilder's loading progress event is null

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 loadingBuilder to show a CircularProgressIndicator while 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?

like image 611
Vince Varga Avatar asked Jul 05 '26 20:07

Vince Varga


1 Answers

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;
  }
like image 68
Muhammed Avatar answered Jul 08 '26 15:07

Muhammed



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!