Image loadingBuilder does not work with asset image
It seems like the loadingBuilder
is not working. Here is my code:
Image(
image: const AssetImage('assets/logo.jpg'),
loadingBuilder: (context, child, loadingProgress) {
print(loadingProgress);
if (loadingProgress == null) return child;
return const CircularProgressIndicator(color: Colors.red);
},
)
To easily see the problem you need to use a very large image for logo.jpg
(> 10 MByte).
The output shows that loadingProgress
is always null
even if the image is not completly loaded yet:
Restarted application in 2.189ms.
I/flutter (22961): null
I/flutter (22961): null
I/flutter (22961): null
What's wrong here? Why does the loading builde not work as expected?
Edit: I created an issue in the Flutter repo for this problem: https://github.com/flutter/flutter/issues/96700
While debugging, I've found a solution which works, but is quite ugly:
Image(
image: const AssetImage('assets/logo.jpg'),
loadingBuilder: (context, child, loadingProgress) {
if(((child as Semantics).child as RawImage).image != null){
return child;
}
return const CircularProgressIndicator(color: Colors.red);
},
)