How I can check if a specific asset exists in Flutter. I'm trying to load some images and sound files and I need to handle the case when these assets do not exist.
I need to check the existence because I have audio files and images for numbers from 1 to 1000. When I build my widgets I use a loop from 1 to 1000 to build it. and there are possibilities that the required file ( the image or the sound for the current number ) does not exist in the assets.
you can try my solution, if you use a simple Image.asset Widget:
Image.asset(
'assets/image.jpg',
errorBuilder: (BuildContext context, Object exception, StackTrace stackTrace) {
return Image.network('path');})
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