检查资产是否存在波动 [英] Check if asset exist in flutter
问题描述
如何检查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.
我需要检查是否存在,因为我有从1到1000的数字的音频文件和图像.构建小部件时,我使用从1到1000的循环来构建它.并且资产中可能不存在所需文件(当前编号的图像或声音).
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.
推荐答案
我假设您正在使用AssetBundle
类通过使用ByteData
的load
方法以及何时使用此方法来加载数据. ,如果找不到该资产,则会引发异常.
I assume that you are using the AssetBundle
class to load your data using the load
method which takes ByteData
, and when you use this method, it will throws an exception if the asset is not found.
这篇关于检查资产是否存在波动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!