问题
I want to know if there is a way (with or without pubspec.yaml asset list) to read a directory where images will be stored, and create an array with all the paths to each image, so I can go through the array (say, with a FOR ) and create a gallery of photos. This with the purpose of being able to change, remove or add images from the directory without worrying about the paths being coded in assets.
I've read that I can use AssetBundle or RootBundle for this but I cant find any example doing so. Any help on this, even pointing me in a different approach, would be greatly appreciated.
Thanks!
EDIT: This got marked as a duplicate, but the question referenced as a duplicate is different in the sense that I need to scan a directory automatically , So I dont need to know any of the names of the files on the directory, I just want a way to read the directory (who's name I can know) and retrieve an array populated with the assets inside the directory.
回答1:
There is (or at least used to be - beware, it's an implementation detail) an asset called AssetManifest.json
. You can load that asset first, and it contains details of the actual assets.
来源:https://stackoverflow.com/questions/56369100/how-do-i-get-an-array-list-filled-with-all-the-image-paths-i-loaded-as-assets-in