I have images and I want to load them to my appplication. my_app/lib/... - here my source files my_app/assets/images/... - here my images
I need to get list of files in assets/images/ and after that show some of them (according to other logic) I'm trying this
final dir = Directory("assets/images/");
print(dir.existsSync()); // <---- it also print: false
var files = dir.listSync().toList();
files.forEach((e) => list.add(MyImageItem(e.path)));
The problem is: I recieve exception
FileSystemException: Directory listing failed, path = 'assets/images/'
(OS Error: No such file or directory, errno = 2)
I've tried different ways: assets/images/, images/, images and so on My pubspec.yaml
flutter:
assets:
- assets/images/
- assets/
When I create Image directly all is fine
new Image(image: AssetImage("assets/images/cat.png"))
I knew that previously (month ago) each resource has to be declared in pubspec.yaml directly, but now assets/images/ is ok. I can load file by direct path. Why I can't access a directory? How to get list of files in directory to get them from my code?