How do I get an array/list filled with all the image paths I loaded as assets in Flutter?

℡╲_俬逩灬. 提交于 2019-12-11 18:26:55

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!