What I want to do is get a List of all files in a directory. I have my Directory, and it works. At other places in my code I access files contained in those directories. However, when I try to add those files to a list, it gives me following error
E/flutter ( 4721): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: FileSystemException: Directory listing failed, path = 'assets/movies/apocalypse_now/' (OS Error: No such file or directory, errno = 2)
E/flutter ( 4721): null
I call the method with the following first line of code, the second one is to test if I can access files in the directory, which i can.
Text(getDirContents(new Directory('assets/movies/apocalypse_now')).toString()),
Image.asset("assets/movies/apocalypse_now/poster.png", width: 90, height: 90),
After running throu this, my app there shows
[] (the poster of apocalypse now)
I did this in order to see if this works, this is not how things will later look.
The method with which i try to get the files looks like this:
List<File> getDirContents(Directory dir) {
var files = <File>[];
var completer = new Completer();
var lister = dir.list(recursive: false);
lister.listen((file) => files.add(file),
// should also register onError
onDone: () => completer.complete(files));
return files;
}
I don't know why this is not working or what i need to fix, but i tried around and got nothing to work.