Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if asset exist in flutter

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.

like image 704
Flutter IO Dev Avatar asked Sep 04 '25 03:09

Flutter IO Dev


1 Answers

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');})
like image 146
AlexF1 Avatar answered Sep 07 '25 14:09

AlexF1