children_ method

Future<List<FileSystemEntity>> children_()

Lists all the FileSystemEntitys present in the Directory.

Implementation

Future<List<FileSystemEntity>> children_() async {
  final completer = Completer();
  final contents = <FileSystemEntity>[];
  try {
    Directory(addPrefix(path))
        .list(recursive: false, followLinks: false)
        .listen(
      (event) {
        switch (FS.typeSync_(event.path)) {
          case FileSystemEntityType.directory:
            contents.add(Directory(removePrefix(event.path)));
            break;
          case FileSystemEntityType.file:
            contents.add(File(removePrefix(event.path)));
            break;
          default:
            break;
        }
      },
      onError: (error) {
        // For debugging. In case any future error is reported by the users.
        print(error.toString());
      },
      onDone: completer.complete,
    );
    await completer.future;
    return contents;
  } catch (exception, stacktrace) {
    print(exception.toString());
    print(stacktrace.toString());
    return [];
  }
}