I would like to list all the contents of a directory (on the file system) using Dart. How can I do this?
To list all the files or folders, you have to use flutter_file_manager, path, and path_provider_ex flutter package. Add the following lines in your pubspec. yaml file to add this package in your dependency. Add read / write permissions in your android/app/src/main/AndroidManifest.
Directory. current. path does it if you want a string, Directory. current for a Directory.
A Directory is an object holding a path on which operations can be performed. The path to the directory can be absolute or relative. It allows access to the parent directory, since it is a FileSystemEntity.
The API has changed and I have updated the async code for M4 release (0.5.16_r23799 ):
Future<List<FileSystemEntity>> dirContents(Directory dir) { var files = <FileSystemEntity>[]; var completer = Completer<List<FileSystemEntity>>(); var lister = dir.list(recursive: false); lister.listen ( (file) => files.add(file), // should also register onError onDone: () => completer.complete(files) ); return completer.future; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With