How can I read a folder contents (recursively) without blocking the main thread?
I have checked the Directory class and has 2 methods:
- listSync to read the folder in a synchronous fashion
- list to read the folder asynchronously but I don' really know when it finishes listing. This seems like a way to hear to folder content changes?
They both doesn't seem to be what I need.
Are isolates the only option left to read the files in a folder async?
CodePudding user response:
simply use toList()
method:
final directory = Directory('downloads');
final elements = directory.list(recursive: true).toList();
print(await elements);