How can I get a list of filepaths from the project assets in Flutter?
135
you can list all the images in your specific directory like this:
final images = json.decode(await rootBundle.loadString('AssetManifest.json')).keys
.where((String key) => key.contains('res/assets/icons/'))
.toList();
print(images.toString());
Author by
lellek
Updated on January 04, 2023Comments
-
lellek over 1 year
I have added a bunch of Images to my App's resources folder and I want to list all of the Images from my icons folder, so the user can pick which one they want to use for their listelement.
My Folder is included in the Pubspec.yaml and I can call AssetImage("/res/assets/icons/") and it gets the image I want manually.
I want to store the path later to call AssetImage(path) on it.
But when I call
List files = Directory("/res/assets/icons/").listSync();
, I get this exception:What do I need to do to get all the file paths from the files in my directory?
-
jdar almost 2 yearsThis no longer seems to work in Flutter 3